У меня есть запрос на публикацию curl, который отправляет Json в конечную точку API, но я не могу заставить его работать в php. Вот рабочий завиток:
curl -v -H "Accept: application/json" -H "Content-type: application/json" -H "Access-Token: **not_telling_you**" -X POST --data '{"import":{"members":[{"organization_customer_identifier":"a number", "program_customer_identifier":"a number", "first_name":"Chris", "member_customer_identifier":"5", "member_status":"OPEN"} ]}}' https://an_api_endpoint.com/api/v1/imports
Вот php, который не работает:
$org_id = "a number";
$pc_id = "a number";
$user_id = "5";
$api_key = "**not telling you**";
$url = "https://an_api_endpoint.com/api/v1/imports";
$data = json_encode(array('import' => array( 'members' => array( array('organization_customer_identifier' => $org_id, 'program_customer_identifier' => $pc_id, 'member_customer_identifier' => $user_id, 'member_status' => 'OPEN')))));
echo $data;
echo "\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Access-Token: '.$api_key));
curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
$result = json_decode($output, true);
var_dump($result);
Я продолжаю получать ошибки, такие как {"message":"Invalid JSON in request body, please validate your JSON and try again."}
int (1) или после переключения все может быть немного: ["message"]=>string(29)
"Invalid API key () specified."
Я подумал, что мне будет проще перевести curl в php curl, но я не могу заставить его работать. Я даже попытался скопировать и вставить данные json напрямую, чтобы они были точно такими же и не работали до сих пор. Я не уверен, что что-то упустил или мой заказ плохой? Заранее благодарю за любую помощь, которую я получаю, решая эту проблему.