Generate a new expense in your ConstructionOnline company account
https://api.constructiononline.com/api/Expenses?Info={expenseInfo}
This endpoint allows users to create either a new lump sum expense or an itemized expense for a project in their ConstructionOnline company account. If successful, the endpoint will return a record of the newly created expense with a unique numerical ID called 'ID', which will be used for any future references. The required fields for creating an expense using this endpoint include PRJ_ID and TITLE; if the expense is itemized, it must also include the ITEMS field. All other properties are optional and can be specified during the creation of the expense for additional detail.
Please note: expenses can only be created for existing projects in ConstructionOnline. If a specific project ID is not included in the request, the expense creation will fail.
Requests
Info: JSON
- Properties to be added to the expense.
- Required properties for the expense: PRJ_ID, TITLE
- Required properties for the expense ITEMS: NAME, RATE
- Allowed properties for the expense: DATE_CREATED, CREATED_BY, SUBTOTAL, TAX_PERCENT, TAX_TYPE, VENDOR_ID, LMOD, LMOD_BY, NOTES, TRADE, RECEIPT_STATUS, TRAFFIC_COLOR, TAGS, ITEMS
- Allowed properties for the expense ITEMS: QTY, UNIT, TAX_TYPE_ID, TAX_PERCENT
Individual properties for creation should be entered as JSON key-value pairs.
Lump sum expense JSON key-value pairs shown below:
{
"PRJ_ID": "1340167",
"TITLE" : "Site Supervisor Labor",
"VENDOR_ID" : "885048",
"SUBTOTAL" : "15000.00",
"TRADE" : "59910",
"RECEIPT_STATUS" : "105769"
}
Itemized expense JSON key-value pairs shown below:
{
"PRJ_ID": "1340167",
"TITLE" : "Site Supervisor Labor - Itemized",
"VENDOR_ID" : "885048",
"TRADE" : "59910",
"RECEIPT_STATUS" : "105769",
"ITEMS" : [
{
"NAME" : "Hourly Wage",
"QTY" : "160.0",
"RATE" : "45.00"
}
{
"NAME" : "Overtime Pay",
"QTY" : "20.0",
"RATE" : "67.50"
}
]
}
Example requests in cURL, C#, Python, and JavaScript can be found below:
# replace {email} with the email address for your ConstructionOnline account
# {password} with your ConstructionOnline password
# {apikey} with your provided API key
# {expenseInfo} with the information for expense creation
curl -X POST https://api.constructiononline.com/api/Expenses?Info={expenseInfo} -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
{expenseInfo} with the information for expense creation */
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/Expenses?Info={expenseInfo}");
Python
#replace {username} with the email address for your ConstructionOnline account
#{password} with your ConstructionOnline password
#{apikey} with your provided API key
#{expenseInfo} with the information for expense creation
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/Expenses?Info={expenseInfo}"))
JavaScript
/* replace {username} with the email address for your ConstructionOnline account
{password} with your ConstructionOnline password
{apikey} with your provided API key
{expenseInfo} with the information for expense creation */
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/Expenses?Info={expenseInfo}");
Responses
200: Success
A successful request will return a 200 response with a record of the newly created expense 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: Nov 11, 2024