Issue
Following the documentation here under /campaigns I try the example with my api-key.
I am using the terminal window on a 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>" \
I paste this whole thing into the prompt even though that doesn't seem the correct way to do this.
Part of the command is understood and then part way through, the shell asks this Display all 114 possibilities question
:
~/: curl -X POST https://api.mailerlite.com/api/v2/campaigns \
> -d '{
>
Display all 114 possibilities? (y or n)
Followed by a directory listing, Followed by:
> 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"}}~/:
What is the proper way to issue a multi-line cURL command from a bash shell?
Solution
Replace tabs with spaces, and drop the last backslash, then it should work just fine.
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>"
It gives the following output to me:
$ 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"}}
Answered By - Anis Ladram