I’ve created a $contact_details array:
$json = file_get_contents('current.json');
$contacts = json_decode($json, true);
$contacts_data = [];
for ($i = 0; $i < count($contacts); $i++) {
$contacts_data[$i]['email'] = $contacts[$i]['Email'];
$contacts_data[$i]['fields'] = [
"id" => 1,
"value" => $contacts[$i]['Appointments Booked']
];
}
That outputs this:
Array
(
[0] => Array
(
[email] => [email protected]
[fields] => Array
(
[id] => 1
[value] => 104
)
)
[1] => Array
(
[email] => [email protected]
[fields] => Array
(
[id] => 1
[value] => 4
)
)
)
That I then pass into a request:
curl_setopt_array($curl, [
CURLOPT_URL => "https://test.api-us1.com/api/3/import/bulk_import",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'callback' => [
'requestType' => 'POST',
'detailed_results' => 'true',
'url' => 'test.com'
],
'contacts' => $contacts_data
]),
CURLOPT_HTTPHEADER => [
"Api-Token: 1234567890",
"Content-Type: application/json",
"accept: application/json"
],
]);
However, the API responds with:
"failureReasons":
[{"contact":1,"failureReason":"Field 'fields.id' must be an integer"},
{"contact":2,"failureReason":"Field 'fields.id' must be an integer"}]}
I’m totally stumped. Based on the output of my $contact_details array, it appears that the “id” key has an integer value of 1 for both contacts.