I'm trying to send a PUT request using CURL, but I get an HTTP 400 Bad Request , I use it CURLOPT_VERBOSEfor debugging and with this I get: "Error: invalid request: waiting for the found object: \" email \ ""} Does anyone know what this is mean / how can i fix it?
the code:
$http_headers = array(
"Accept: application/json",
"Connection: close",
"Expect:",
"Content-Type: application/json"
);
$ym_api_url = 'https://services.yesmail.com/enterprise/subscribers/718880';
$newsubscriber = array(
'email' => 'karina@email.com',
'firstName' => 'Karina',
'lastName' => 'McG',
'postCode' => 'BT93 EP3',
'prefersMobile' => '',
'emailFormat' => 'HTML'
);
$curl_hdl = curl_init();
$curl_options = array(
CURLOPT_VERBOSE => TRUE,
CURLOPT_STDERR => $verbose = fopen('php://temp', 'rw+'),
CURLOPT_HEADER => TRUE,
CURLOPT_HTTPHEADER => $http_headers,
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
CURLOPT_USERPWD => 'xxxxxxx:xxxxxxxx',
CURLOPT_PROTOCOLS => CURLPROTO_HTTPS,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_URL => $ym_api_url,
);
curl_setopt_array($curl_hdl, $curl_options);
curl_setopt($curl_hdl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl_hdl, CURLOPT_POSTFIELDS, http_build_query($newsubscriber));
curl_setopt($curl_hdl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl_hdl, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($curl_hdl);
$http_response_code = curl_getinfo($curl_hdl, CURLINFO_HTTP_CODE);
echo "Verbose information:\n<pre>", !rewind($verbose), htmlspecialchars(stream_get_contents($verbose)), "</pre>\n";
curl_close($curl_hdl);
echo PHP_EOL . "INFO: HTTP Response Code was: " . $http_response_code . PHP_EOL;
if ( $response === false )
{
echo PHP_EOL . "ERROR: curl_exec() has failed." . PHP_EOL;
}
else
{
echo PHP_EOL . "INFO: Response Follows..." . PHP_EOL;
echo PHP_EOL . $response;
}
source
share