cancel
Showing results for 
Search instead for 
Did you mean: 

#/email_addresses: Value is of a disallowed type. Allowed types are: Array

Occasional Advisor

#/email_addresses: Value is of a disallowed type. Allowed types are: Array

Hi I am running into a problem testing the add contact api endpoint here:

 

https://constantcontact.mashery.com/io-docs

 

 

My jsonbody is this:

 

{"status":"ACTIVE","lists":["2"],"email_addresses":{"email_address":"hudson.atwell@gmail.com"},"first_name":"Test","last_name":"User","home_phone":null,"company_name":null}

 

And the response body is this:

 

[{
   
"error_key":"json.type.invalid",
   
"error_message":"#/email_addresses: Value is of a disallowed type. Allowed types are: Array."
}]

 

You can see I have a json encoded array as my email_addresses param but I am still getting this error.

 

Any ideas?

Tags (1)
9 REPLIES 9
Occasional Advisor

Re: #/email_addresses: Value is of a disallowed type. Allowed types are: Array

Ok I found out why, I needed to encode my child array in another array for the lot to be considered an array value type. 

 

eg: 

 

$contact = array (
'status' =>'ACTIVE',
'lists' => array( array( "id"=>$target_list ) ),
'email_addresses' => array( array( 'status' => 'ACTIVE' , 'email_address' => $lead_data['email'] ) ),
'first_name' => $lead_data['first_name'],
'last_name' => $lead_data['last_name'],
);


$contact_encoded = json_encode($contact);

 

echo $contact_encoded;

Occasional Advisor

Re: #/email_addresses: Value is of a disallowed type. Allowed types are: Array

Just to keep an update on my progress; I have run into a new error: Unable to parse JSON payload. , although my json object is working on https://constantcontact.mashery.com/io-docs

 

JSON

{"status":"ACTIVE","lists":[{"id":"1"}],"email_addresses":[{"status":"ACTIVE","email_address":"hudson.atwell@gmail.com"}],"first_name":"Test","last_name":"User"}


 

Response

array(5) { ["headers"]=> array(11) { ["cache-control"]=> string(78) "private, no-cache, no-store, max-age=0, must-revalidate, no-cache="Set-Cookie"" ["content-encoding"]=> string(4) "gzip" ["content-type"]=> string(30) "application/json;charset=UTF-8" ["date"]=> string(29) "Wed, 18 Dec 2013 20:56:54 GMT" ["pragma"]=> string(8) "no-cache" ["server"]=> string(6) "Apache" ["vary"]=> string(26) "Accept-Encoding,User-Agent" ["x-mashery-responder"]=> string(39) "prod-j-worker-us-east-1b-36.mashery.com" ["x-powered-by"]=> string(0) "" ["content-length"]=> string(2) "94" ["connection"]=> string(5) "Close" } ["body"]=> string(86) "[{"error_key":"json.payload.invalid","error_message":"Unable to parse JSON payload."}]" ["response"]=> array(2) { ["code"]=> int(400) ["message"]=> string(11) "Bad Request" } ["cookies"]=> array(0) { } ["filename"]=> NULL } 

 

Code

 

$contact = array (
'status' =>'ACTIVE',
'lists' => array( array( "id"=>$target_list ) ),
'email_addresses' => array( array( 'status' => 'ACTIVE' , 'email_address' => $lead_data['email'] ) ),
'first_name' => $lead_data['first_name'],
'last_name' => $lead_data['last_name'],
);


$contact = apply_filters('inboundnow_constantcontact_lead_data',$contact);

$contact_encoded = json_encode($contact);
echo $contact_encoded;
echo "<Hr>";


/* add contact to list */

$args = array(
'redirection' => 0,
'sslverify' => false,
'headers' => array( 'Authorization' => "Bearer $constantcontact_access_key" , 'content-type'=>'application/json;charset=UTF-8'),
'body' => array( 'jsonRequestBody' => $contact_encoded)
);

$response = wp_remote_post( 'https://api.constantcontact.com/v2/contacts?action_by=ACTION_BY_OWNER&api_key='.$constantcontact_api... , $args );

 

CTCT Employee

Re: #/email_addresses: Value is of a disallowed type. Allowed types are: Array

Let me try this out in WordPress and see what's going on :)

Thanks!

-------------------------------------------
Check out our developer portal: http://developer.constantcontact.com
Occasional Advisor

Re: #/email_addresses: Value is of a disallowed type. Allowed types are: Array

Woo thanks Mike!

Occasional Advisor

Re: #/email_addresses: Value is of a disallowed type. Allowed types are: Array

Hey Mike,

Did you ever have a chance to look into this? 

CTCT Employee

Re: #/email_addresses: Value is of a disallowed type. Allowed types are: Array

Hi Hudson,

 

Sorry for the delay on this.  I tried your json payload in IO Docs and in my own RESTClient, and it works, generating a 201 Created message when the email address is newly entered, and a 409 Conflict once the email address is already in my account.

 

Therefore, it seems that Wordpress is modifying the json payload somehow before sending it over to us.  I apologize, but without knowing what Wordpress is doing to it, it's hard to troubleshoot from our side.  Perhaps they have a setting they could configure or provide some insight on their side as to how they're changing the json.

 

Best Regards,

Shannon W.

Partner API Support Engineer

Occasional Advisor

Re: #/email_addresses: Value is of a disallowed type. Allowed types are: Array

Hi Shannon

 

I have succes! I managed to do it by removing the part of the code that sets the json string into a an array and just set the json string directly into body.

 

See workng:

 

$args = array(
'redirection' => 0,
'sslverify' => false,
'headers' => array( 'content-type'=>'application/json' ,'Authorization' => "Bearer $constantcontact_access_key" ),
'body' => $contact_encoded
);

$response = wp_remote_post( 'https://api.constantcontact.com/v2/contacts?action_by=ACTION_BY_OWNER&api_key='.$constantcontact_api... , $args );

 

But now I have a problem that when I want to sort a contact already in the system in a new list I get this error:
string(122) "[{"error_key":"http.status.email_address.conflict","error_message":"Email address adistantbox@gmail.com already exists."}]" 

 

If I had a way to look up a contact by email and then update it into the list I should do that, but I couldn't find a api part to do email based lookups. 

 

What do you think?

 

Highlighted
CTCT Employee

Re: #/email_addresses: Value is of a disallowed type. Allowed types are: Array

You can check to see if a contact already exists by using the contacts endpoint and adding an email address, like so:
GET https://api.constantcontact.com/v2/contacts?email={EMAIL_ADDRESS}&limit={YOUR_LIMIT}&api_key={API_KE...

 

 

You can then send the contact information back as a PUT request with the list added to the lists array to:
PUT: https://api.constantcontact.com/v2/contacts/{CONTACT_ID}&api_key={API_KEY}

 

You can see a sample PUT request here: http://developer.constantcontact.com/docs/contacts-api/contacts-resource.html?method=PUT

 

 

Hope that helps!

 

- Mike

-------------------------------------------
Check out our developer portal: http://developer.constantcontact.com
Occasional Advisor

Re: #/email_addresses: Value is of a disallowed type. Allowed types are: Array

Hey Mike,

 

Almost home free. 

 

I managed to do a successful lookup on an email but when trying to PUT the contact to an new list I get a 405 error:

 

Here's the json body and the response:

{"status":"ACTIVE","lists":[{"id":"1"}],"email_addresses":[{"status":"ACTIVE","email_address":"mikymon7@gmail.com"}],"first_name":"Hudson","last_name":"Atwell"}


array(5) { ["headers"]=> array(11) { ["cache-control"]=> string(78) "private, no-cache, no-store, max-age=0, must-revalidate, no-cache="Set-Cookie"" ["content-encoding"]=> string(4) "gzip" ["content-type"]=> string(16) "application/json" ["date"]=> string(29) "Mon, 10 Feb 2014 20:04:05 GMT" ["pragma"]=> string(8) "no-cache" ["server"]=> string(6) "Apache" ["vary"]=> string(26) "Accept-Encoding,User-Agent" ["x-mashery-responder"]=> string(39) "prod-j-worker-us-east-1d-32.mashery.com" ["x-powered-by"]=> string(0) "" ["content-length"]=> string(2) "20" ["connection"]=> string(5) "Close" } ["body"]=> string(0) "" ["response"]=> array(2) { ["code"]=> int(405) ["message"]=> string(18) "Method Not Allowed" } ["cookies"]=> array(0) { } ["filename"]=> NULL }

 

and the code which is amost identical to the create a new contact PUT except the url has changed a bit:

 

$args = array(
'redirection' => 0,
'sslverify' => false,
'headers' => array( 'content-type'=>'application/json' ,'Authorization' => "Bearer $constantcontact_access_key" ),
'body' => $contact_encoded
);



$response = wp_remote_post( 'https://api.constantcontact.com/v2/contacts/'.$cc_contact_data['results'][0]['id'].'?action_by=ACTIO... , $args );
var_dump($response);

 

 

 

---------

 

and that's it! Any insight?