Skip to main content
All CollectionsREST API
Common API Functions
Common API Functions
Luiza Gircoveanu avatar
Written by Luiza Gircoveanu
Updated over 8 months ago

Overview

When using our API, it's pretty common to make calls using Javascript. Below are some functions pre-written to make creating integrations with our API a little easier, especially for those less technical.

You can copy and paste these functions into any script file and then simply call apiRequestGET(), apiRequestPOST(), and apiRequestPUT() with the appropriate parameters.

Note: these examples are for v2 endpoints. You can modify them to support v3 requests by simply swapping out v2 for v3 in the url variable.

GET Request

function apiRequestGET(endpoint,apiKey) {
var url = 'https://api.observepoint.com/v2' + endpoint;
var options = {
'method': 'GET',
'headers': {
Authorization: 'api_key ' + apiKey
},
'contentType': 'application/json',
'muteHttpExceptions': true
}
var ret = UrlFetchApp.fetch(url, options);
return JSON.parse(ret);

}

POST Request

function apiRequestPOST(endpoint,apiKey, payload) {
var url = 'https://api.observepoint.com/v2' + endpoint;
var options = {
'method': 'POST',
'headers': {
Authorization: 'api_key ' + apiKey
},
'payload': JSON.stringify(payload),
'contentType': 'application/json',
'muteHttpExceptions': true
}
var ret = UrlFetchApp.fetch(url, options);
return JSON.parse(ret);
}

PUT Request

function apiRequestPUT(endpoint,apiKey, payload) {
var url = 'https://api.observepoint.com/v2' + endpoint;
var options = {
'method': 'PUT',
'headers': {
Authorization: 'api_key ' + apiKey
},
'payload': JSON.stringify(payload),
'contentType': 'application/json',
'muteHttpExceptions': true
}
var ret = UrlFetchApp.fetch(url, options);
return JSON.parse(ret);
}
Did this answer your question?