Generate a new contact in your ConstructionOnline company account
https://api.constructiononline.com/api/Contacts?contactInfo={contactInfo}
This endpoint allows users to create a new contact. If successful, the endpoint will return a record of the newly created contact. The new contact will be automatically assigned a unique numerical ID called 'ID', which will be used for future reference. Required properties for creation are the contact's first name, last name, display name, and email address. All other properties are optional; these can be entered during contact creation or at a later time.
Requests
contactInfo: JSON object
- Properties used to create the contact. Must include the required properties(s). Allowed properties are optional but recommended.
- Required properties: EMAIL, FIRSTNAME, LASTNAME, DISPLAY_NAME
- Allowed properties: COMPANY, ADDRESS, CITY, STATE, ZIP, PHONE, MOBILE_PHONE, MOBILE_PROVIDER, FAX, MIDDLENAME, WEBSITE, SUMMARY, EXPERIENCE, COUNTRY_SETTING, EMAIL, CONTACT_QUALITY, CONTACT_REGION, CONTACT_DIVISION, CONTACT_OFFICE, CONTACT_CATEGORY, CONTACT_TRADE, FIELD_ID
- Example: {"EMAIL" : "alice@conwayconstruction.com", "FIRSTNAME" : "Alice", "LASTNAME" : "Conway", "DISPLAY_NAME" : "Alice Conway"}
❗ Contacts cannot have duplicate emails. If you try to create a new contact with an email address that has already been assigned to an existing contact, a a new contact will not be created. Instead, the endpoint will return an updated version of the existing contact with the entered fields. However, this endpoint should not be used to update contacts. The endpoint for updating contacts can be found here.
Example requests in cURL, C#, Python, and JavaScript can be found below:
cURL
# replace {email} with the email address for your ConstructionOnline account
# {password} with your ConstructionOnline password
# {apikey} with your provided API key
# {data} with the payload for contact creation
curl -X POST https://api.constructiononline.com/api/Contacts -d '{data}' -u {email}:{password} -H 'APIKey:{apikey}'
C#
/* replace {username} with the email address for your ConstructionOnline account
{password} with your ConstructionOnline password
{apikey} with your provided API key
{contactInfo} with the fields for the contact */
public string MakeRequest(string endpoint, string payload) {
string username = {username};
string password = {password};
string apiKey = {apikey};
string response = "";
var handler = new HttpClientHandler() { AutomaticDecompression = System.Net.DecompressionMethods.GZip };
using (HttpClient client = new HttpClient(handler)) {
client.BaseAddress = new Uri("http://api.constructiononline.com");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password)));
client.DefaultRequestHeaders.Add("APIKey", apiKey);
client.DefaultRequestHeaders.Add("Accept-Encoding", "gzip");
HttpContent content = new StringContent(payload, System.Text.Encoding.UTF32, "application/json");
response = client.PostAsync(endpoint, content).Result.ToString();
}
return response;
}
MakeRequest("api/contacts?contactInfo={contactInfo}");
Python
#replace {username} with the email address for your ConstructionOnline account
#{password} with your ConstructionOnline password
#{apikey} with your provided API key
#{contactInfo} with the fields for the contact
import base64, requests, json
#Global Variables
apikey = {apikey}
username = {username}
password = {password}
#Functions
def makeRequest(endpoint, payload):
url = "https://api.constructiononline.com/" + endpoint
userPass = username + ":" + password
headers = {
"APIKey": apikey,
"Accept-Encoding": "gzip, deflate, br",
"Authorization": "Basic " + base64.b64encode(userPass.encode()).decode(),
}
response = requests.request("POST", url, headers=headers, data=payload)
return json.dumps(json.loads(response.text), indent=2)
#Main Program
print(makeRequest("api/contacts?contactInfo={contactInfo}"))
JavaScript
/* replace {username} with the email address for your ConstructionOnline account
{password} with your ConstructionOnline password
{apikey} with your provided API key
{contactInfo} with the fields for the contact */
username = '{username}';
password = '{password}';
apikey = '{apikey}';
function makeRequest(endpoint, payload) {
auth = btoa('${username}:${password}');
var myHeaders = new Headers();
myHeaders.append("APIKey", apikey);
myHeaders.append("Accept-Encoding", "gzip, deflate, br");
myHeaders.append("Authorization", "Basic ${auth}");
var requestOptions = {
method: 'POST',
body: '',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://api.constructiononline.com/" + endpoint, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
return response;
};
makeRequest("api/contacts?contactInfo={contactInfo}");
Responses
200: Success
A successful request will return a 200 response with a record of the newly created contact in the body.
A sample response and property definitions can be found here.
404: Error
The server was not able to locate the resource specified in the request.
429: Error
The user has surpassed the request rate limit for the hour, day, week, or month.
500: Error
There was an internal server error and the server was unable to complete the request.
Last updated: Dec 21, 2023