Answered

API and GOOGLE SHEETS

Hi,


How do i get the API credentials into google sheets when i run the availability get function?


function myFunction() {

var response = UrlFetchApp.fetch("https://inventory.dearsystems.com/ExternalApi/v2/ref/productavailability?Page=1&Limit=1000")

Logger.log(response.getContentText()

)}


api-auth-accountid & api-auth-applicationkey


Request failed for https://inventory.dearsystems.com/ExternalApi/v2/ref/productavailability?Page=1&Limit=1000 returned code 403. Truncated server response: Incorrect credentials! (use muteHttpExceptions option to examine full response) (line 3, file "C

  • Here is the code I use to make API requests from Google Apps Script: 

      var DEARapiauthaccountid = "YOUR-API-ID-HERE";
      var DEARapiauthapplicationkey = "YOUR-API-KEY-HERE";
      var DEARoptions = {'headers' : {"api-auth-accountid" : DEARapiauthaccountid,
                      "api-auth-applicationkey" : DEARapiauthapplicationkey,
                      "Accept" : "application/json"
                               }};
      
    
    
      var url = "https://inventory.dearsystems.com/ExternalApi/v2/saleList?Page=1&Limit=100&Search=" + SOorINVnumber;
      var dataAll = JSON.parse(UrlFetchApp.fetch(url, DEARoptions).getContentText());
      Logger.log(dataAll);
    

     

  • Thank you Tristan, you are a great help.

    i have modified to get product availability, 


    my next challenge is to get it into google sheets, can you assist?


     

    function myFunction() {
        var DEARapiauthaccountid = "xxxxx";
      var DEARapiauthapplicationkey = "xxxxx";
      var DEARoptions = {'headers' : {"api-auth-accountid" : DEARapiauthaccountid,
                      "api-auth-applicationkey" : DEARapiauthapplicationkey,
                      "Accept" : "application/json"
                               }};
      
    
    
      var url = "https://inventory.dearsystems.com/ExternalApi/v2/ref/productavailability?Page=1&Limit=1000%22";
      var dataAll = JSON.parse(UrlFetchApp.fetch(url, DEARoptions).getContentText());
      Logger.log(dataAll);
    }
    

     

  • The Google Apps Script website is really good and has some good tutorials as well:

    https://developers.google.com/apps-script/reference/spreadsheet/


Login or Signup to post a comment