Add new contacts via shell (or curl)

SOLVED
Highlighted
Occasional Participant

Add new contacts via shell (or curl)

Hey there,

I'm a newbie with the API and have started to look at the API and am getting a bit overwhelmed ;-)

 

I'm looking to add customers every time we get an order from our 3rd party provider.  Then I'd like to run a shell script to add the contact's email address (and a few other fields, such as name and country, etc.).  I can generate the JSON file no problem.  

 

Two questions:

1. Do you have a curl example I can follow? (or whatever is appropriate to call from a shell script).  

2. In our 3rd party order form, we will be asking if customers want to be added to our mailing list.  I have that info when I run my shell script.  I see in another thread that  I can use ACTION_BY_VISITOR to get express consent set in your db,  and ACTION_BY_OWNER to set implied (soft) consent. https://knowledgebase.constantcontact.com/articles/KnowledgeBase/18265-Create-a-Sign-Up-Form-with-th...

 

However, I do not see that an ACTION field in the list of fields of the JSON data (https://developer.constantcontact.com/docs/bulk_activities_api/bulk-activities-import-contacts.html#...)

 

Any help on getting new contact info into the constant contact db via a shell script, complete with express or implied consent, would be very helpful!

 

Pete

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: Add new contacts via shell (or curl)

Hello Pete,

Thank you for reaching out to the API Support team here at Constant Contact.

First the ACTION_BY parameter does not go in the JSON data; it is used as a URL parameter exactly the same way that your API Key is used. Second, you can only set the ACTION_BY parameter when working with base Contacts collection (http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST). All contacts added via the bulk activity method you linked are added as action_by_owner. Below is an example using cURL to post a new contact.

curl -X POST \
  'https://api.constantcontact.com/v2/contacts/1?api_key={API_KEY}&action_by=action_by_visitor' \
  -H 'Authorization: Bearer {ACCESS_TOKEN}' \
  -H 'Content-Type: application/json' \
  -d '{
    "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": "1"
        }
    ],
      "cell_phone": "555-555-5555",
      "company_name": "System Optimzations",
      "confirmed": false,
      "email_addresses": [
        {
        "email_address": "username1@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"
}'


Please let me know if you have any other questions!

 

Regards,
David B.
Tier II API Support Engineer

View solution in original post

Tags (2)
4 REPLIES 4
Highlighted
Occasional Participant

Re: Add new contacts via shell (or curl)

Also, to be clear, I'm not a developer for a 3rd party app for email services. 

 

I'm just a geek trying to manager our own in-house list(s) for customers.

 

Pete

Highlighted
Moderator

Re: Add new contacts via shell (or curl)

Hello Pete,

Thank you for reaching out to the API Support team here at Constant Contact.

First the ACTION_BY parameter does not go in the JSON data; it is used as a URL parameter exactly the same way that your API Key is used. Second, you can only set the ACTION_BY parameter when working with base Contacts collection (http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST). All contacts added via the bulk activity method you linked are added as action_by_owner. Below is an example using cURL to post a new contact.

curl -X POST \
  'https://api.constantcontact.com/v2/contacts/1?api_key={API_KEY}&action_by=action_by_visitor' \
  -H 'Authorization: Bearer {ACCESS_TOKEN}' \
  -H 'Content-Type: application/json' \
  -d '{
    "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": "1"
        }
    ],
      "cell_phone": "555-555-5555",
      "company_name": "System Optimzations",
      "confirmed": false,
      "email_addresses": [
        {
        "email_address": "username1@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"
}'


Please let me know if you have any other questions!

 

Regards,
David B.
Tier II API Support Engineer

View solution in original post

Tags (2)
Highlighted
Occasional Participant

Re: Add new contacts via shell (or curl)

Thanks so much.  You've provided exactly the answer I needed.  I have a few more questions that I'll take offline and send to you via email.  The questions are just concerning a few details.

Pete

 

Highlighted
Occasional Contributor

Re: Add new contacts via shell (or curl)

Hello.

I copying and pasted the curl -X POST that is in this message. It seems to run without any sort of error. I changed the api-key for a test and managed to get an error. Then I put it back. So, next action on my part is to see if I have a new contact in Constant Contact. Nope.

 

Is this not supposed to add a contact? Any help would be appreciated.

Developer Portal

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

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured