GraphQL API Error 403 when using Apps Script or Python, fine using Insomnia

729 Views Asked by At

I am trying to access the Pulsar GraphQL API using Apps Script (Have also tried Python) however, it returns a 403 error each time. I have run the exact same query and variables through Insomnia, with the same API token and it returns the desired data. Any help would be greatly appreciated!

    function getDataTrac() {  
  
  var url = 'https://data-explorer.pulsarplatform.com/graphql/trac'//+endpoint;
  var body = {  
    'query' : 'query Results($date_2021_01_01: Filter!,$date_2021_01_01_option: Option){results(filter: $date_2021_01_01, options: $date_2021_01_01_option)     {       total       nextCursor      results{                    pulsarId            pulsarParentId          identifier          parentIdentifier            createdAt           publishedAt         deletedAt           updatedAt           source          info            language            countryCode                     domainName          url             content             rejected            rejectedBy          images          videos          hashtags            tags            topics          communities             emotion             reactionsByType                     impressions             viewsCount          engagement          engagementRate          commentsCount           likesCount          sharesCount             cachedReactionCount             visibility          sentiment           csr                   reputation            reviewRating        }   }}',
    'variables' :              '{   "date_2021_01_01": {        "dateFrom": "2021-01-01T00:00:00Z",     "dateTo": "2021-01-02T23:59:59Z",       "searches": [           "88dcc5a4bd60facf01829dc481c65c8e"      ]   },                          "date_2021_01_01_option": {     "limit": 1  }}'
  }
  
  //query = query.replace(/[\s\t\n]{2,}/," ");
  //vars = vars.replace(/[\s\t\n]{2,}/," ");
  //Logger.log(query);
  //url = url + '?query=' + encodeURI(query) + '&variables=' + encodeURI(vars);
  var options = {
    'headers': {'Authorization' : 'Bearer ***API Token***'},
    'muteHttpExceptions': false,
    'contentType': 'application/json',
    'method': 'POST',
    'payload' : JSON.stringify(body)
  };
  var response = UrlFetchApp.fetch(url,options);
  Logger.log(response)

}
0

There are 0 best solutions below