I use the following json to create a contact:
[{"status":"ACTIVE","first_name":"Albert",
"last_name":"Einstein",
"lists":[{"id":"1","status":"ACTIVE"}],
"email_addresses":[{
"id":"1",
"status":"ACTIVE",
"email_address":"albert@einstein.com"}]}]
I get the following response:
[{
"error_key": "json.field.missing",
"error_message": "#/email_addresses: Property is required but not found."
}]
Can anyone please tell me which field is missing in the request? I can't figure it out from the error message.
Solved! Go to Solution.
Hi Peter,
It looks like you're just missing the Content-Type header from this request. Try changing:
curl_setopt( $Request, CURLOPT_HTTPHEADER, array( 'Content-Length: ' . strlen( $RequestJson) ) );
to:
curl_setopt( $Request, CURLOPT_HTTPHEADER, array( 'Content-Length: ' . strlen( $RequestJson), 'Content-Type: application/json' ) );
This should resolve that error message you are seeing about the invalid Content-Type header.
David J
The problem is your request JSON. We're expecting a Contact object, you're providing an array of Contact objects. Simply remove the opening/closing [] that you're doing around the entire payload (or if you're serializing, don't put your Contact object into a list/array/collection) and you should be all set.
Thank you so much for your answer, Dave. Removing the square brackets does get it executed by your API test page, but I'm still having trouble getting it to run from PHP. And this may be something I am doing wrong, so if you still have time, it would be an enourmous help if you could glance over my code:
$Request = curl_init( $Url );
curl_setopt( $Request, CURLOPT_RETURNTRANSFER, TRUE );
curl_setopt( $Request, CURLOPT_SSL_VERIFYHOST, FALSE );
curl_setopt( $Request, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt( $Request, CURLOPT_TIMEOUT, 10 );
$RequestJson = json_encode( $RequestData ); // $RequestData is array
curl_setopt( $Request, CURLOPT_HTTPHEADER, array( 'Content-Length: ' . strlen( $RequestJson) ) );
curl_setopt( $Request, CURLOPT_POSTFIELDS, $RequestJson );
$Response = curl_exec( $Request );
// end of code
the $RequestJson looks like this:
{"first_name":"One","last_name":"Two","lists":[{"id":"1"}],"email_addresses":[{"email_address":"one@two.com"}]}
bud I get:
"[{"error_key":"http.header.content_type.invalid","error_message":"Invalid content type. API only supports application/json."}]
Hi Peter,
It looks like you're just missing the Content-Type header from this request. Try changing:
curl_setopt( $Request, CURLOPT_HTTPHEADER, array( 'Content-Length: ' . strlen( $RequestJson) ) );
to:
curl_setopt( $Request, CURLOPT_HTTPHEADER, array( 'Content-Length: ' . strlen( $RequestJson), 'Content-Type: application/json' ) );
This should resolve that error message you are seeing about the invalid Content-Type header.
David J
Thank you very much, David.