Sending a POST request to a add a new contact using Meter JS http package

SOLVED
Highlighted
Occasional Contributor

Sending a POST request to a add a new contact using Meter JS http package

Hi,
I am not sure if anyone here is familiar with Meteor, but that is what I am using to build my application, there is a http package, and you can see it's api here. I was able to successfully add a Contact in the API tester page, but when I use my code I get a 400 response saying. I am thinking it has something to do with the data option, but I am not quite sure what to try instead.

{ [Error: failed [400] [{"error_key":"query.param.invalid","error_message":"The query parameter status is not supported."},{"error_key":"query.param.invalid","error_message":"The query parameter limit is not supported."}]]



Here is my code

var data = {
      "addresses": [
        {
          "address_type": "BUSINESS",
          "city": "Belleville",
          "country_code": "CA",
          "line1": "47 Shawmut Ave.",
          "line2": "Suite 404",
          "postal_code": "K8b 5W6",
          "state_code": "ON"
        }
      ],
      "lists": [
        {
          "id": "1395617465"
        }
      ],
      "cell_phone": "555-555-5555",
      "company_name": "System Optimzations",
      "confirmed": false,
      "email_addresses": [
        {
          "email_address": "username2@example.com"
        }
      ],
      "fax": "555-555-5555",
      "first_name": "Ronald",
      "home_phone": "555-555-5555",
      "job_title": "Systems Analyst 3",
      "last_name": "Martone",
      "prefix_name": "Mr.",
      "work_phone": "555-555-5555"
    };

   HTTP.post('https://api.constantcontact.com/v2/contacts?status=ALL&limit=50&api_key=<random-key>', {
      headers: {
        'Authorization': 'Bearer <random-token>',
        'Content-Type': 'application/json'
      },
      data: JSON.stringify(data)
    }, function (error, response) {
      if ( error ) {
        console.log( error );
      } else {
        console.log(response);

      }
    });

 

Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Sending a POST request to a add a new contact using Meter JS http package

Hello @AndersK81,

 

Thank you for reaching out to Constant Contact's API Support.

 

When making a post you do not need some of the parameters that you are including in your POST URL and I believe that is the issue that is causing your error.

 

You are posting to this URL.

https://api.constantcontact.com/v2/contacts?status=ALL&limit=50&api_key=<random-key>

Why don't you try to POST to this one.

https://api.constantcontact.com/v2/contacts?api_key=<random-key>

The only other parameter you might consider using in a POST URL would be the action_by parameter. You can read about that here. https://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST


Regards,
Jimmy D.
Tier II API Support Engineer

View solution in original post

1 REPLY 1
Highlighted
Moderator

Re: Sending a POST request to a add a new contact using Meter JS http package

Hello @AndersK81,

 

Thank you for reaching out to Constant Contact's API Support.

 

When making a post you do not need some of the parameters that you are including in your POST URL and I believe that is the issue that is causing your error.

 

You are posting to this URL.

https://api.constantcontact.com/v2/contacts?status=ALL&limit=50&api_key=<random-key>

Why don't you try to POST to this one.

https://api.constantcontact.com/v2/contacts?api_key=<random-key>

The only other parameter you might consider using in a POST URL would be the action_by parameter. You can read about that here. https://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST


Regards,
Jimmy D.
Tier II API Support Engineer

View solution in original post

Developer Portal

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

Visit Page

Register for our "Making Sense of Online Marketing for Retail" Webinar

Join us on Thursday, August 13th at 2pm ET for a free webinar where we'll discuss how to incorporate online marketing into your retail store.

Read More
Featured