Follow

Contact By ContactID Methods '/contacts/{contactid}'

This article will walk you through how to use Get, Put, and Delete methods for a Contact Record and builds on our two introductory articles, A 101 Look Into Our Rest Based API | Authentication Methods.

 

The methods for Contact Record retrieval, modification, and deletion all share the URI '/contacts/{contactid}' , but where they differ is with the Method Type supplied. 

To be clear, the ContactID is the unique identifier for a Contact Record and will need to be supplied in all of the methods outlined in this article.

The purpose of each of the methods are outlined below.

 

Contact by ContactID Fetch

Method Type: GET

returns contact record by ContactID

'/contacts/{contactid}'

Optional parameter: ?recent={recent}*

* {0} does nothing

* {1} updates recently viewed

 

Contact by ContactID Fetch (Basic)

Method Type: GET

returns a simpleified contact record by ContactID

'/contacts/{contactid}/basic'

Optional parameter: ?recent={recent}*

* {0} does nothing

* {1} updates recently viewed

 

Contact by ContactID Put

Method Type: PUT

creates or updates a Contact Record by ContactID

'/contacts/{contactid}'*

* {0} creates a new record

 

Contact by ContactID Delete

Method Type: POST

marks a record as deleted by ContactID

'/contacts/{contactid}'

 

To perform the GET and DELETE methods, all that is required is to provide the ContactID in the URI and to provide the corresponding Method Type in the Request.

 

Contact by ContactID Fetch

The URI '/contacts/{contactid}', when coupled with Method Type 'GET',  returns a contact record's details.

A popular Contact used for testing in our test database is 'Mary Investor'. So we will retrieve her Contact Record by using her ContactID in the URI below.

https://api2.redtailtechnology.com/crm/v1/rest/contacts/{contactid}

https://api2.redtailtechnology.com/crm/v1/rest/contacts/384843

 

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");
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. 

 RecordGet.png

 

Contact by ContactID Fetch (Basic)

The URI '/contacts/{contactid}', when coupled with Method Type 'GET',  returns a simplified Contract Record.

https://api2.redtailtechnology.com/crm/v1/rest/contacts/{contactid}/basic

https://api2.redtailtechnology.com/crm/v1/rest/contacts/384843/basic

 

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/basic");
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.

 

Contact by ContactID PUT

With the Contact Put method  you can create or update a Contact Record by ContactID.

When Creating a record, a ContactID should not be specified. Instead, you will need to supply a '0' in lieu of the ContactID.

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? When creating or updating an 'individual' type contact, you will need to supply the TypeID, Firstname and Lastname.

If the contact has a non-individual contact type, the required fields are just TypeID and Name

 

Field Datatype

<TypeID>
<Firstname>*
<Middlename>
<Lastname>*
<Salutation>
<Designation>
<Name>*
<Nickname>
<Familyname>
<TaxID>
<DateOfBirth>
<Gender>
<MaritalStatus>
<JobTitle>
<StatusID>
<CategoryID>
<SourceID>
<UserID>
<Family>
<FamilyHeadID>
<ServicingAdvisorID>
<WritingAdvisorID>
 
integer    
string  
string
string
string
string
string
string
string
integer
datetime
string
string
string
integer
integer
integer
integer
string
integer
integer
integer

 

If you choose to supply a value for the salutation, StatusID,SourceID, or CategoryID field, you will need to pull a list of IDs from the APIs listed below.. The IDs may be different for each DB. So please take a look at the following documentation.

Salutation List Fetch - returns a list of Salutations with the corresponding Salutation Code.

Contact Status List Fetch returns a list of contact statuses with the corresponding Contact Status Code.

          Contact Category List Fetch returns a list of Contact Categories with the corresponding Contact Category Code.

         Servicing Advisor List Fetch returns a list of Servicing Advisors with the corresponding Servicing Advisor Code.

         Writing Advisor List Fetch returns a list of Writing Advisors with the corresponding Writing Advisor Code.

      

 

Since we use Mary Investor heavily, lets not modify the ContactID '384843'. Instead, we will try a new record. To create a new record, we will specify the ContactID 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}

 

Request Header example (C#)

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://api2.redtailtechnology.com/crm/v1/rest/contacts/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 = "{\"DateOfBirth\":\"\\/Date(1227011828560-0800)\\/\",\"Firstname\":\"a1Test\",\"Gender\":\"F\",\"Lastname\":\"a1Test\",\"MaritalStatus\":\"M\",\"Middlename\":\"J\",\"SourceID\":2643,\"StatusID\":8169,\"TypeID\":\"I\"}";
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());

 

Contact by ContactID Delete

The URI '/contacts/{contactid}', when supplied with the Method Type 'POST',  marks a record as deleted.

Since we use Mary Investor heavily, lets let her stay in our database. That is, lets leave the contact id 384843 alone!

Just as with the other methods, the URI is https://api2.redtailtechnology.com/crm/v1/rest/contacts/{contactid}

 

Request Header example (C#)

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://api2.redtailtechnology.com/crm/v1/rest/contacts/313730");
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());

 

 

 

 

 

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk