Join the Ready, Set, Send Challenge Week 3. Share your QR code or landing page and win a badge!

Invalid Json Response

user298769
Rookie
0 Votes

I am trying to integrate V3 API into my web application. Using this I want to subscribe a user from the application. I am using CURL to execute the API but each time I get the same error Invalid JSON format. Please help.

Exact Response: [{"error_key":"http.status.bad_request","error_message":"Request body contains invalid JSON."}]

2 REPLIES 2
user298769
Rookie
0 Votes

I got a solution myself. The issue was with the JSON string that I was supplying in API. I am sharing the correct way to insert contact in a particular list.

 

$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.cc.email/v3/contacts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => '{"email_address": {"address": "YOUR_EMAIL","permission_to_send": "implicit"},"first_name":"NAME_OF_THE_USER","create_source": "Account","list_memberships": ["LIST_ID"]}',
CURLOPT_HTTPHEADER => array(
'authorization: Bearer ADD_TOKEN_HERE',
"content-type: application/json",
"cache-control: no-cache",
"accept: application/json"
),
));

$response = curl_exec($curl);
curl_close($curl);

Courtney_E
Moderator
0 Votes

Hello user298769,

 

Thank you for reaching out to Constant Contact API Developer Support. 

 

I’m glad to hear that you were able to resolve your issue! Also, we appreciate you sharing your resolution for other users that may run into the same type of problem.

 

Included below is some additional related information for visibility on the forum: 

 

Our API documentation contains example requests in cURL for most of our endpoint requests that you can reference:

Example POST Create a Contact Request (click the tab in the example that says cURL)

https://v3.developer.constantcontact.com/api_guide/contacts_create.html#example-post-create-a-contac...

 

Additionally, you can utilize our API Reference Page to find request body schemas & values, as well as test the functionality of our available endpoints to see how they will work once programmed within your application:

https://v3.developer.constantcontact.com/api_reference/index.html

 

Please let us know if you have any other questions!


Regards,

Courtney E.
Tier II API Support Engineer

Did I answer your question?
If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
Resources
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up