1

I am trying to use GitHub API to create an issue, by

curl -u $username  -d '{"title" : "Big Files List" , "body" : "'$(find -type f -size +1M)'", "label" : "big files" } $URL -k'

however, I got the response like

curl: (3) [globbing] unmatched close brace/bracket at pos 56
{
"message": "Invalid request.\n\nFor 'links/0/schema', \"body\" is not an 
object.",
"documentation_url": 
"https://developer.github.com/enterprise/2.15/v3/issues/#create-an-issue"
}

So the issue is within $(find -type f -size +1M) , when I replace is with string, there is not issue.

4

1 回答 1

1

curl正在返回多个文件名,并且第一个文件名之后的空格结束了-d参数,因此您发送的 JSON 不完整。你需要引用它,这样它就不会分裂。

但这还不够,因为 JSON 中也不允许使用文字换行符。您需要将换行符翻译为\n.

您还把结束引号放在了错误的位置,它应该在 JSON 的末尾,而不是行尾。

bigfiles=$(find -type f -size +1M)
bigfiles=${bigfiles// /\\n}
curl -u $username  -d '{"title" : "Big Files List" , "body" : "'"$bigfiles"'", "label" : "big files" }' $URL -k
于 2018-12-24T21:45:33.177 回答