首页 > 解决方案 > cURL 命令在终端提示符下不起作用

问题描述

按照 /campaigns 下的文档我使用我的 api-key 尝试该示例。

我在 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 命令的正确方法是什么?

标签: bashshell

解决方案


用空格替换制表符,并删除最后一个反斜杠,那么它应该可以正常工作。

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"}}

推荐阅读