This article will walk you through how to use Get, Put, and Delete methods for Address Records and builds on our two introductory articles, A 101 Look Into Our Rest Based API | Authentication Methods.
If you are using the Address by AddressID Put method, you will need to designate the TypeID as follows.
Address Types | |
TypeID |
Type
|
H
|
Home
|
I
|
Home 2
|
M
|
Mailing
|
O
|
Other
|
P
|
PO Box
|
W
|
Work
|
X
|
Work 2
|
The purpose of each of the methods are outlined below.
Method Type: GET
returns a list of Address records for a ContactID
'/contacts/{contactid}/addresses'
Method Type: PUT
creates or updates an Address record by AddressID and Contact
'/contacts/{contactid}/addresses/{addressid}' *
*{addressid} = {0} creates a new address record for a specific ContactID.
Method Type: POST
marks a record as deleted by AddressID
'contacts/{contactid}/addresses/{addressid}'
To perform the GET and POST methods, all that is required is to provide the ContactID and AddressID in the URI and to provide the corresponding Method Type in the Request.
Addresses by ContactID Fetch
The URI '/contacts/{contactid}/addresses', when coupled with Method Type 'GET', returns a List of Addresses for a specific Contact Record.
A popular Contact used for testing in our test database is 'Mary Investor'. So we will retrieve a list of her Addresses using the URI below.
'contacts/{contactid}/addresses'
https://api2.redtailtechnology.com/crm/v1/rest/contacts/384843/addresses
Below is a sample request in C# using our URI, sample credentials, and the method type. The content type "text/json" work equally well.
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://api2.redtailtechnology.com/crm/v1/rest/contacts/384843/addresses"); req.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes("6C135EDF-C37C-4039-AEF3-5DFC079F9E6A:Statementone:sonedemo")); req.Method = "GET"; req.ContentType = "text/xml";
//and here's the response stream.
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
The corresponding response(xml) will be similar to the following.
Address by AddressID PUT
With the Address Put method you can create or update an Address by an AddressID.
When Creating a new record, an AddressID should not be specified. Instead, you will need to supply a '0' in its place.
As you know, put methods requires a Request Body accompanying the Request Header. (You know this because you've read our 101 article!)
What fields need to be supplied? The Required Fields are provided below in Bold.
Field | Datatype |
<RecID>
<ClientID>
<TypeID>
<Address1>
<Address2>
<City>
<State>
<Zip>
|
integer
integer
string
string
string
string
string
integer
|
To create a new record, we will specify the AddressID in our URI as equal to '0' and supply the required fields in the request body.
https://api2.redtailtechnology.com/crm/v1/rest/contacts/{contactid}/addresses/{addressid}
Request Header example (C#)
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://api2.redtailtechnology.com/crm/v1/rest/contacts/384843/addresses/0");
req.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes("6C135EDF-C37C-4039-AEF3-5DFC079F9E6A:statementone:sonedemo"));
req.Method = "PUT";
req.ContentType = "text/json";
Request Body example (C#)
string reqJSON = "{\"RecID\":0,\"ClientID\":384843,\"TypeID\":\"HM\",\"Address1\":\"51234 Main St.\",\"Address2\":\"\",\"City\":\"Sacramento\",\"State\":\"CA\",\"Zip\":95670}"
byte[] reqBody = System.Text.Encoding.ASCII.GetBytes(reqJSON);
//Request Stream
req.GetRequestStream().Write(reqBody, 0, reqBody.Length);
//and here's the response stream.
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
Address by AddressID Delete
The URI '/contacts/{contactid}/addresses/{addressid}', when supplied with the Method Type 'POST', marks an address record as deleted.
To delete an address, provide in the URI the specific AddressID and ContactID.
Request Header example (C#)
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://api2.redtailtechnology.com/crm/v1/rest/contacts/313730/addresses/133370");
req.Headers[System.Net.HttpRequestHeader.Authorization] = "Basic " + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes("6C135EDF-C37C-4039-AEF3-5DFC079F9E6A:statementone:sonedemo"));
req.Method = "POST";
req.ContentType = "text/json";
//and here's the response stream.
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
Request Body example (C#)
//and here's the response stream.
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
....
Comments