webservices

How To Use RESTClient

by Administrator on ‎03-23-2011 04:27 PM

Initial Setup

 

First, download and install the RESTClient from the following URL:

 

http://rest-client.googlecode.com/

 

Next, we need to set up the authentication information.  On "Auth" tab, check "BASIC" and uncheck "Preemptive".

For "Username", enter {API KEY}%{Constant Contact username}.  For "Password", enter your Constant Contact password.

 

AuthTab.jpg

 

Using RESTClient

 

You will mostly work with "Method", "Headers" and "Body" tabs.  Choose the appropriate method on "Method" tab.

If you are using a GET method, then you don't need to use "Headers" or "Body" tab.  If you are using a PUT or a POST, then put your XML in "Body" tab and add application/atom+xml as "Content-Type" header on "Headers" tab.  If you are trying to run a GET method followed by PUT or POST, you do not need to delete the contents of "Headers" and "Body" tabs.  They will be promptly ignored.

In URL, enter your API call like the following:

https://api.constantcontact.com/ws/customers/{username}/lists

Don't forget to use "https" instead of "http".

 

Examples

 

All examples assume your {username} is testuser.

 

1. Getting a list of contacts

  • On "Method" tab, choose "GET"
  • In URL, enter https://api.constantcontact.com/ws/customers/testuser/contacts
  • Hit the Go! button with ">>" icon
    • The REST Client will display a response status (which should be 200 OK) in the lower pane
    • If the call was successful, see the BODY tab of the lower pane to inspect the response body.  (The Response Body from your GET is generally very useful in putting together a Request Body for a create (POST) or update (PUT) command)

GetExample.jpg

 

2. Creating a new contact list

  • On "Method" tab, choose "POST"

 

    PostExample1.jpg

     

  • On "Headers" tab, enter Content-Type as "Key" and application/atom+xml as "Value" and hit the plus button to add it.

 

    PostExample2.jpg

     

    PostExample3.jpg

     

    On "Body" tab, enter your XML entry for the new contact list

  • <entry xmlns="http://www.w3.org/2005/Atom">
    <id>data:,</id>
    <title/>
    <author/>
    <updated>2008-04-16</updated>
    <content type="application/vnd.ctct+xml">
    <ContactList xmlns="http://ws.constantcontact.com/ns/1.0/">
    <OptInDefault>false</OptInDefault>
    <Name>A New List</Name>
    <SortOrder>99</SortOrder>
    </ContactList>
    </content>
    </entry>

    PostExample4.jpg