im new and trying to learn cURL in php but when trying to POST my new made user to my testing enviroment i get an error.
I've tried debugging and looking for various things but couldn't find anything in specific that was wrong. I tried googling as well but all the answers i found made no sense enter
string(830) "{"status":400,"error":"There was a problem in the JSON you submitted [92677fc5f9526c8878a88c61e3ca5a27]: unexpected characters after the JSON document () at line 1, column 1 [parse.c:618]
in '--------------------------7c5256387e2a9ed5\r\nContent-Disposition:
attachment; name=\"name\"\r\n\r\njohn jeff\r\n-------------------------
-7c5256387e2a9ed5\r\nContent-Disposition: attachment;
name=\"email\"\r\n\r\nhelloyes@hotmail.com\r\n-------------------------
-7c5256387e2a9ed5\r\nContent-Disposition: attachment; name=\"phone\"\r\n\r\n09009090\r\n-------------------------
-7c5256387e2a9ed5\r\nContent-Disposition: attachment; name=\"companies\"\r\n\r\nLandstede\r\n-------------------------
-7c5256387e2a9ed5\r\nContent-Disposition: attachment; name=\"user_id\"\r\n\r\n420\r\n--------------------------
7c5256387e2a9ed5--\r\n"}"
if (isset($_POST['submit'])) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.intercom.io/users");
curl_setopt($ch, CURLOPT_POST, 1);
if (isset($_POST['unsubscribed_from_emails'])) {
$post = ['name' => $_POST['name'],
'email' => $_POST['email'],
'phone' => $_POST['phone'],
'companies' => $_POST['companies'],
'user_id' => $_POST['user_id'],
'unsubscribed_from_emails' => $_POST['unsubscribed_from_emails']
];
} else {
$post = ['name' => $_POST['name'],
'email' => $_POST['email'],
'phone' => $_POST['phone'],
'companies' => $_POST['companies'],
'user_id' => $_POST['user_id']
];
}
//var_dump($post);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); //Post Fields
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'Authorization:Bearer <MYKEYYOUCANTSEE>',
'Accept: application/json',
'Content-type: application/json',
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$server_output = curl_exec($ch);
curl_close($ch);
// var_dump($server_output);
}
I just want the user to be added to the enviroment but nothing happens. Only when i var_dump'd to find the problem i got that errormessage.
You need to json_encode()
the $post data.
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post)); //Post Fields
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.