bashcurlsparkpost

curl: argument list too long


I want to send an email with attached pdf file through the Sparkpost API with curl post.

To insert the pdf I use (my test.pdf is ~ 200KB)

"data":"'$(cat test.pdf} | base64 --wrap=0)'"

But somehow this doesn't work out showing the following error:

/usr/bin/curl: Die Argumentliste ist zu lang (original)
/usr/bin/curl: Argument list is too long

EDIT: curl command

curl -X POST https://api.eu.sparkpost.com/api/v1/transmissions -H 'Authorization: <APIKEY>' -H 'Content-Type: application/json' -d '{
   "options":{
      "open_tracking":false,
      "click_tracking":false,
      "inline_css":false
   },
   "recipients":[
      {
         "address":{
            "email":"user@domain.tld",
            "name":"user"
         }
      }
   ],
   "content":{
      "from":{
         "name":"sender",
         "email":"sender@domain.tld"
      },
      "reply_to":"replyto@domain.tld",
      "subject":"subject",
      "text":"textbody",
      "attachments":[
         {
            "name":"attachmentname.pdf",
            "type":"application/pdf",
            "data":"'$(cat test.pdf | base64 --wrap=0)'"
         }
      ]
   }
}'

Solution

  • This is coming up because you are trying to pass the entirety of the base64'd content on the command line. curl has the ability to load in data to POST from a file, which I'd recommend doing. More information can be found in the man page, but the basic format is this:

    curl -X POST -d @filename.txt https://website.com/path