0

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)

}
  • From [the document of 403 Forbidden](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/403), it says `The HTTP 403 Forbidden response status code indicates that the server understands the request but refuses to authorize it.`. In this case, I'm worried that the URL might not be able to be requested from Google side. How about this? – Tanaike Mar 30 '22 at 12:37
  • So do you think that this type of request just isn't possible? – James Trayton Mar 30 '22 at 13:14
  • Thank you for replying. When you request your URL, if the status code `403` is returned, it is considered that the URL cannot be accessed from the Google side. For example, how about asking the administrator of the API? – Tanaike Mar 30 '22 at 13:18
  • Thanks. I have spoken to the admin of the API but they could not find an issue. They have another GraphQL API which I can access no problem so not overly sure why there is an issue with the above. The admin have no issue accessing the above API through apps script and I have no issue accessing their other API using the above format which is causing much confusion! – James Trayton Mar 30 '22 at 13:44
  • Thank you for replying. Now, the information I have is from `I am trying to access the Pulsar GraphQL API using Apps Script (Have also tried Python) however, it returns a 403 error each time.`. So I'm worried such situation. This is due to my poor skill. I deeply apologize for this. – Tanaike Mar 30 '22 at 13:46

0 Answers0