Hi I'm having a problem with posting a JSON
array with cURL
to my API,
I have this code below for the cURL
post:
$data_string = stripslashes($JSONData);
$ch = curl_init('http://api.webadress.com');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
It doesn't store/post anything to the API end and the $results is not returning correct, What is wrong with the code?
A bit from the JSON
:
{
"name": "test",
"type_id": "1",
"css": "#fb-iframe{}#fb-beforelike{}#fb-beforelike-blur{}",
"json": [
{
"Canvas": [
{
"Settings": {
"Page": {
"campaignName": "test"
}
},
"QuizModule": {
"Motivation": [],
"Questions": [],
"Submit_Fields": [
{
"label": "Name",
"name": "txtName",
"value": true
}
]
}
}
]
}
],
"user_id": "123"
}