I’m trying to update a contact from a website that uses the current InfusedWOO plugin v4.4.5, and specifically trying to update a contact’s phone number. Problem: somewhere along the way, the update data is getting formatted wrong, so the API is rejecting it.
I start with an update variable created like so:
$update_data = ['given_name' => $given_name,'family_name' => $family_name];
The API developer’s guide says that phone numbers should be a nested array, so if there is a phone number, I add it to $update_data:
$update_data['phone_numbers'] = ['number' => $formatted_phonenum,'field' => 'PHONE1'];
Then I use $update_data in a call to the plugin’s function iw_keap_restV1Request():
$update_result = iw_keap_restV1Request("contacts/{$matching_contact_id}", 'PATCH', json_encode($update_data));
But it doesn’t work. If I dump the contents of $update_data using json_encode, I get this:
{“given_name”:“John”,“family_name”:“Doe”,“phone_numbers”:{“number”:“5551011110”,“field”:“PHONE1”}}
However, by experimenting with Postman, I found that what the API wants to see is this:
{“given_name”:“John”,“family_name”:“Doe”,“phone_numbers”:[ {“number”:“5551011110”,“field”:“PHONE1”} ] }
with the phone_numbers sub-array contained inside both square brackets and curly braces.
Why is this happening, and is there a way to get $update_data into the format that the API wants without building the JSON string myself?