I am using sendhub API.
https://www.sendhub.com/developer/
and getting this error.
The format indicated ‘application/x-www-form-urlencoded’ had no available deserialization method. Please check your formats and content_types on your Serializer.
The code I am using is:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HEADER, "Content-Type: application/json");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
if(LOCAL_MODE){
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt($ch, CURLOPT_PROXY, FALSE);
}
curl_setopt($ch, CURLOPT_POST, 1);
$data = '{
"contacts": [
1111
],
"text": "Testing"
}';
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
echo $result=curl_exec ($ch);
echo curl_error($ch);
Can anybody help me how to solve this issue.
Thank You.
It seems that Content-Type is not being sent correctly.
The message “The format indicated ‘application/x-www-form-urlencoded’ had no available deserialization method.” indicates the server is reading the content type as ‘application/x-www-form-urlencoded’ rather than ‘application/json’.
You should be setting the content type like this:
(note the CURLOPT_HEADER is now CURLOPT_HTTPHEADER)
Assuming that your url (including the username and apikey) are correct and the contact ids supplied exist this should now work.