2

I have a problem with reproducing the second example https://developers.facebook.com/docs/messenger-platform/reference/attachment-upload-api#example_request

It is:

curl  \
  -F 'message={"attachment":{"type":"image", "payload":{"is_reusable":true}}}' \
  -F 'filedata=@/tmp/shirt.png;type=image/png' \
  "https://graph.facebook.com/v6.0/me/message_attachments?access_token=<PAGE_ACCESS_TOKEN>"

When I check the request with httpbin, I get:

{
"args": {}, 
  "data": "", 
  "files": {
    "filedata": ""
  }, 
  "form": {
    "message": "{\"attachment\":{\"type\":\"image\", \"payload\":{\"is_reusable\"=true}}}", 
    "recipient": "{\"id\":\"2673203139464950\"}"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "474", 
    "Content-Type": "multipart/form-data; boundary=------------------------855a2be7cb07aa99", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.58.0", 
    "X-Amzn-Trace-Id": "Root=1-5e71f6ce-edeb373f3e446e443e23f2e3"
  }, 
  "json": null, 
  "origin": "my.ip.ad.dr", 
  "url": "https://httpbin.org/post"
}

When I run it locally, I get

{
   "error":{
      "message":"(#100) Field message must be a valid json object with string keys",
      "type":"OAuthException",
      "code":100,
      "fbtrace_id":"ABYTTCTcFg7DoXr8i8ySdJB"
   }
}

My attempts to solve it by myself are unsuccessful, despite several days of effort. I guess, the problem is really simple, but I need help.

By the way, in general I need python-requests way of uploading files to Facebook, thus, if I had one, I would not need curl solution.

Any help will be appreciated.

I was told to replace the equals sign with a colon and add backslashes, however, it does not seem to work:

$ curl  \
>   -F 'message:{\"attachment\":{\"type\":\"image\", \"payload\":{\"is_reusable\": true}}}' \
>   -F 'filedata=@/tmp/shirt.png;type=image/png' \
>   "https://graph.facebook.com/v6.0/me/message_attachments?access_token=<MY-TOKEN>"
Warning: Illegally formatted input field!
curl: option -F: is badly used here
  • Your JSON object for the message field is invalid. Try replacing the equals sign `=` with a colon `:`. `"{\"attachment\":{\"type\":\"image\", \"payload\":{\"is_reusable\": true}}}"` – Vyacheslav Pukhanov Mar 18 '20 at 11:12
  • Thanks for your help! I do not understand your suggestion properly. Do you mean `"message:{"attachment":{"type":"image", "payload":{"is_reusable":true}}}"`? If so, curl failed to parse it. If this is not the case, please, explain with more details. – Andrew Ishutin Mar 18 '20 at 12:10
  • Do not forget about the backslashes. Use the exact JSON from your post, juts replace the equals sign with a colon – Vyacheslav Pukhanov Mar 18 '20 at 12:37
  • So, I've replaced the equal sign with a colon like this: `curl \ -F 'message:{\"attachment\":{\"type\":\"image\", \"payload\":{\"is_reusable\": true}}}' \ -F 'filedata=@/tmp/shirt.png;type=image/png' \ "https://graph.facebook.com/v6.0/me/message_attachments?access_token="` Curl output: `Warning: Illegally formatted input field! curl: option -F: is badly used here` I doubt that this is what you mean. By the way, thanks for your patience. – Andrew Ishutin Mar 18 '20 at 13:16
  • Please edit your question and include it there, in comments this is hardly readable to begin with, plus right now we can’t really tell where exactly this contains line breaks right now. – CBroe Mar 18 '20 at 13:25
  • @Cbroe, I've edited the question. – Andrew Ishutin Mar 18 '20 at 14:10
  • @vyacheslav-pukhanov, can you please review? – Andrew Ishutin Mar 20 '20 at 10:16

1 Answers1

0

You only want to replace the second equal sign with a colon, the one after is_reusable, otherwise the JSON you provide is not valid. The equal sign after message should stay, because it is required by curl. Check out the documentation for more details.

In your case you want to use the following:

-F 'message={"attachment":{"type":"image","payload":{"is_reusable":true}}}'
Vyacheslav Pukhanov
  • 1,788
  • 1
  • 18
  • 29