I’m trying to add custom audience on Facebook using Ruby restclient gem but there is something with the payload param that’s not working.
I’m setting “multipart” param to the payload for RestClient but this doesn’t work neither. I get always a RestClient::BadRequest: 400 Bad Request
Here is an example of what I’m doing , any guest?
payload = {:payload =>
{:schema=>["FN", "LN", "EMAIL"],
:data=>[
["31c88cbf2ceeb43fce68f027c10dd71b053672ce771fa5e4fc22422e633c6f11",
"3565d65adb5cc2043e09097ee55ad430333a2a9a08a3a2b82c158b160ff12454",
"d66746d2a1a6d488601e5603b8e9540c03e7e8063ae8aa921a3860007f478761"],
["3f03df52a32aafde65e6ee94b351970e0fa1481337b6b02f5f607d3357c1c368",
"2ef9487065c3616d7c108c4b1c81e1b3afeee48f0373f7d5f5220bbc38db8ef5",
"e4e91c99e2ae79c614e35de6cb429c32510dc2ecbf11c2a6e45a5872693542e6"],
["2de75eeda225156c96688715f0c2f86276dc0f10453dad716b9419729c46c5b8",
"68c91edc2305b00a20a7febc616d2925e58bdbdf27fdcef8f84a1d1d8f37b3af",
"a63ef4bd9dd5985f46674b4fb7f98b63c7144aae9b243281d01a66ad7659247e"]]
},
:access_token => "<ACCESS_TOKEN>",
:multipart => true }
url = "https://graph.facebook.com/v2.7/<AUDIENCE_ID>/users"
request = RestClient::Request.new(
:method => :post,
:url => url,
:payload=>payload)
response = request.execute
Building the request like this:
@payload="--474291rnContent-Disposition: form-data; name="payload[schema][]"rnrnFNrn--474291rnContent-Disposition: form-data; name="payload[schema][]"rnrnLNrn--474291rnContent-Disposition: form-data; name="payload[schema][]"rnrnEMAILrn--474291rnContent-Disposition: form-data; name="payload[data][]"rnrn31c88cbf2ceeb43fce68f027c10dd71b053672ce771fa5e4fc22422e633c6f11rn--474291rnContent-Disposition: form-data; name="payload[data][]"rnrn3565d65adb5cc2043e09097ee55ad430333a2a9a08a3a2b82c158b160ff12454rn--474291rnContent-Disposition: form-data; name="payload[data][]"rnrnd66746d2a1a6d488601e5603b8e9540c03e7e8063ae8aa921a3860007f478761rn--474291rnContent-Disposition: form-data; name="payload[data][]"rnrn3f03df52a32aafde65e6ee94b351970e0fa1481337b6b02f5f607d3357c1c368rn--474291rnContent-Disposition: form-data; name="payload[data][]"rnrn2ef9487065c3616d7c108c4b1c81e1b3afeee48f0373f7d5f5220bbc38db8ef5rn--474291rnContent-Disposition: form-data; name="payload[data][]"rnrne4e91c99e2ae79c614e35de6cb429c32510dc2ecbf11c2a6e45a5872693542e6rn--474291rnContent-Disposition: form-data; name="payload[data][]"rnrn2de75eeda225156c96688715f0c2f86276dc0f10453dad716b9419729c46c5b8rn--474291rnContent-Disposition: form-data; name="payload[data][]"rnrn68c91edc2305b00a20a7febc616d2925e58bdbdf27fdcef8f84a1d1d8f37b3afrn--474291rnContent-Disposition: form-data; name="payload[data][]"rnrna63ef4bd9dd5985f46674b4fb7f98b63c7144aae9b243281d01a66ad7659247ern--474291rnContent-Disposition: form-data; name="access_token"rnrnXXXXXXXXXXXXXXXXXXXXrn--474291--rn"
CURL Example that works:
curl
-F 'payload={
"schema": [
"FN",
"LN",
"EMAIL"
],
"data": [["31c88cbf2ceeb43fce68f027c10dd71b053672ce771fa5e4fc22422e633c6f11",
"3565d65adb5cc2043e09097ee55ad430333a2a9a08a3a2b82c158b160ff12454",
"d66746d2a1a6d488601e5603b8e9540c03e7e8063ae8aa921a3860007f478761"],
["3f03df52a32aafde65e6ee94b351970e0fa1481337b6b02f5f607d3357c1c368",
"2ef9487065c3616d7c108c4b1c81e1b3afeee48f0373f7d5f5220bbc38db8ef5",
"e4e91c99e2ae79c614e35de6cb429c32510dc2ecbf11c2a6e45a5872693542e6"],
["2de75eeda225156c96688715f0c2f86276dc0f10453dad716b9419729c46c5b8",
"68c91edc2305b00a20a7febc616d2925e58bdbdf27fdcef8f84a1d1d8f37b3af",
"a63ef4bd9dd5985f46674b4fb7f98b63c7144aae9b243281d01a66ad7659247e"]]
}'
-F 'access_token=XXXXX'
https://graph.facebook.com/v2.7/XXXX/users --trace-ascii /dev/stdout
2
Answers
So , the solution was to stringify FB's payload param .
The JSON class will do that: