Dominic
Dominic

Reputation: 15

sending a image attachment to facebook chat with curl does't work

i'm trying to send a image attachment to a facebook chat with curl. I got the instructions form (https://developers.facebook.com/docs/messenger-platform/send-api-reference/image-attachment)

curl  \
-F 'recipient={"id":"YYYY"}' \
-F 'message={"attachment":{"type":"image", "payload":{}}' \
-F 'filedata=@/home/dominic/site/drophere/hitcat.jpg;type=image/jpeg' \
"https://graph.facebook.com/v2.6/me/messages?access_token=XXXX"

after I ececuted it, this error message appear:

{"error":{"message":"(#100) Message cannot be empty, must provide valid attachment or text","type":"OAuthException","code":100,"error_subcode":2018034,"fbtrace_id":"DwlBQTqXCw\/"}}

cant find my mistake.

Upvotes: 0

Views: 1323

Answers (2)

tmn4jq
tmn4jq

Reputation: 361

Also their documentation has a bad JSON example here https://developers.facebook.com/docs/messenger-platform/send-messages

curl  \
  -F 'recipient={"id":"<PSID>"}' \
  -F 'message={"attachment":{"type":"<ASSET_TYPE>", "payload":{"is_reusable"=true}}}' \
  -F 'filedata=@/tmp/shirt.png;type=image/png' \
  "https://graph.facebook.com/v2.6/me/messages?access_token=<PAGE_ACCESS_TOKEN>"

Note the EQUALS sign here:

{"is_reusable"=true}

Here should be : instead of =

Upvotes: 3

jammygb
jammygb

Reputation: 133

You seem to be missing a } after "payload":{}}. Your code should read:

curl  \
-F 'recipient={"id":"YYYY"}' \
-F 'message={"attachment":{"type":"image", "payload":{}}}' \
-F 'filedata=@/home/dominic/site/drophere/hitcat.jpg;type=image/jpeg' \
"https://graph.facebook.com/v2.6/me/messages?access_token=XXXX"

Upvotes: 0

Related Questions