根据/activities下面的文档,我用我的api键尝试这个例子。
我使用的是Mac上的终端窗口(bash-shell(。
curl -X POST https://api.mailerlite.com/api/v2/campaigns
-d '{
"subject": "Regular campaign subject",
"segments": 1291259,
"type": "regular"
}'
-H "Content-Type: application/json"
-H "X-MailerLite-ApiKey: <api-key>"
我把这整件事粘贴到提示中,尽管这似乎不是正确的方法。
命令的一部分被理解了,然后进行到一半时,shell询问这个Display all 114 possibilities question
:
~/: curl -X POST https://api.mailerlite.com/api/v2/campaigns
> -d '{
>
Display all 114 possibilities? (y or n)
后面是目录列表,后面是:
> campaign subject",
> "segments": 1291259,
> "type": "regular"
> }'
> -H "Content-Type: application/json"
> -H "X-MailerLite-ApiKey: <api-key>"
>
{"error":{"code":400,"message":"Campaign type is missing"}}~/:
从bash shell发出多行cURL命令的正确方法是什么?
用空格替换制表符,并去掉最后一个反斜杠,这样就可以正常工作了。
curl -X POST https://api.mailerlite.com/api/v2/campaigns
-d '{
"subject": "Regular campaign subject",
"segments": 1291259,
"type": "regular"
}'
-H "Content-Type: application/json"
-H "X-MailerLite-ApiKey: <api-key>"
它向我提供以下输出:
$ curl -X POST https://api.mailerlite.com/api/v2/campaigns
> -d '{
> "subject": "Regular campaign subject",
> "segments": 1291259,
> "type": "regular"
> }'
> -H "Content-Type: application/json"
> -H "X-MailerLite-ApiKey: <api-key>"
{"campaign_type":"regular","date":"2020-10-06 19:21:47","account_id":<id>,"id":<id>,"mail_id":<id>,"options":{"current_step":"step3","send_type":"regular","campaign_type":"regular","date":"2020-10-06 19:21:47"}}