Common API Functions

Overview

When using our API, it's pretty common to make calls using vanilla 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() and apiRequestPOST() with the  appropriate parameters

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);
}
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.