$ curl --url "https://api.constantcontact.com/v2/account/info?api_key=vdamjgek7zcyvj8pb5wnkevk" -H "Authorization: Bearer REDACTED" -H "X-Originating-Ip: 74.29.14.27" {"website":"http://www.leisuretimetours.com","organization_name":"Leisure Time Tours","time_zone":"US/Eastern","first_name":"David","last_name":"Berk","email":"email1@example.com","phone":"7185280700","company_logo":"","country_code":"US","state_code":"NA","organization_addresses":[{"city":"Queens","line1":"145-98 Brewer Blvd","postal_code":"11434","country_code":"US","state_code":"NY","state":"New york"}]} $ curl --url "https://api.constantcontact.com/v2/account/verifiedemailaddresses?status=ALL&api_key=vamjgek7zcyvj8pb5wnkevk" -H "Authorization: Bearer REDACTED" -H "X-Originating-Ip: 74.29.14.27" [{"email_address":"emai1l@example.com","status":"UNCONFIRMED"},{"email_address":"daberk@gmail.com","status":"CONFIRMED"},{"email_address":"email2@example.com","status":"CONFIRMED"}] $ curl --url "https://api.constantcontact.com/v2/contacts?email=email%40example.com&status=ALL&limit=50&api_key=damjgek7zcyvj8pb5wnkevk" -H "Authorization: Bearer REDACTED" -H "X-Originating-Ip: 74.29.14.27" {"meta":{"pagination":{}},"results":[{"id":"1663540141","status":"ACTIVE","fax":"","addresses":[],"notes":[],"confirmed":false,"lists":[{"id":"1806940688","status":"ACTIVE"},{"id":"1871720660","status":"ACTIVE"},{"id":"2058450850","status":"ACTIVE"}],"source":"Site Owner","email_addresses":[{"id":"66b9cc70-a6ed-11e4-87fc-d4ae5292c426","status":"ACTIVE","confirm_status":"NO_CONFIRMATION_REQUIRED","opt_in_source":"ACTION_BY_OWNER","opt_in_date":"2015-01-28T12:58:49.000Z","email_address":"email@example.com"}],"prefix_name":"","first_name":"Robert","middle_name":"","last_name":"Frucher","job_title":"","company_name":"","home_phone":"","work_phone":"","cell_phone":"","custom_fields":[],"created_date":"2015-01-28T12:58:53.000Z","modified_date":"2015-02-05T00:18:14.000Z","source_details":""}]}
Hello,
You're definitely on the right track with what you've accomplished so far. While it is a bit tricky to demonstrate the exact process for updating a contact with cURL, I can provide some example HTTP calls with cURL to demonstrate the individual steps.
Here's a quick overview of the process for add/update:
The tricky part here will be that you will need to be able to process and modify the JSON data that is returned from cURL, as well as being able to then pass the modified JSON back to the next cURL call.
Here are some example of what needs to be done for each of the three steps:
1. GET to Contacts Collection
URL Requires: Email Address you wish to add/update, API Key, Access Token
$ curl -G "https://api.constantcontact.com/v2/contacts?email=<EMAIL_ADDRESS>&api_key=<API_KEY>" -H "Authorization: Bearer <ACCESS_TOKEN>"
2. PUT to individual contact endpoint
URL Requires: Contact ID, API Key, Access Token
$ curl -X PUT -H "Authorization: Bearer <ACCESS_TOKEN>" -H "Content-Type: application/json" -d "{\"addresses\": [ { \"ad\", \"city\": \"Cambridge\", \"country_code\": \"US\", \"line1\": \"541 Brighton Ave.\", \"line2\": \"Unit 785\", \"line3\": \"\", \"postal_code\": \"01555\", \"state_code\": \"MA\", \"sub_postal_code\": \"\" }, { \"address_type\": \"BUSINESS\", \"city\": \"Belleville\", \"country_code\": \"CA\", \"line1\": \"47 Shawmut Ave.\", \"line2\": \"Suite 404\", \"line3\": \"\", \"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\", \"middle_name\": \"Angelo\", \"prefix_name\": \"Mr.\", \"work_phone\": \"555-555-5555\"}" https://api.constantcontact.com/v2/contacts/<CONTACT_ID>?api_key=<API_KEY>
3. POST to Contacts Collection
URL Requires: API Key, Access Token
$ curl -X POST -H "Authorization: Bearer <ACCESS_TOKEN>" -H "Content-Type: application/json" -d "{\"addresses\": [ { \"ad\", \"city\": \"Cambridge\", \"country_code\": \"US\", \"line1\": \"541 Brighton Ave.\", \"line2\": \"Unit 785\", \"line3\": \"\", \"postal_code\": \"01555\", \"state_code\": \"MA\", \"sub_postal_code\": \"\" }, { \"address_type\": \"BUSINESS\", \"city\": \"Belleville\", \"country_code\": \"CA\", \"line1\": \"47 Shawmut Ave.\", \"line2\": \"Suite 404\", \"line3\": \"\", \"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\", \"middle_name\": \"Angelo\", \"prefix_name\": \"Mr.\", \"work_phone\": \"555-555-5555\"}" https://api.constantcontact.com/v2/contacts?api_key=<API_KEY>
While the examples above will allow you to send and receive contact data using the API, you will still need some method for processing and creating JSON data for the contacts. In order to make this work, you would need to be able to parse the response from Step 1, and depending on whether or not a contact is present in the response, choose to either update contact data for Step 2, or skip to Step 3 and create new contact data.
The best resource for information about the contact data structure is the API Documentation. Here's a couple relevant links:
Create Contact: http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html?method=POST
Update Contact: http://developer.constantcontact.com/docs/contacts-api/contacts-resource.html?method=PUT
If you do have any questions about any of this or run into any difficulties, feel free to reach out for assistance!
Sincerely