Call external Api with Bearer Token

1,169 views
Skip to first unread message

Hassan Shabbir

unread,
Aug 9, 2022, 2:47:11 AM8/9/22
to Google Apps Script Community
Hi,

 I am calling External web api (.net Core) with Bearer Authorization Token from google AppScript but getting Bearer Token null. I tried from Postmann it is working properly but from appscript i am getting Authorization Null.

Here is my google App Script Code:,

var headers = { Authorization: 'Bearer Token' }; 

  var requestOptions = { 'method': 'GET', 'header':headers, 'redirect': 'follow', 'muteHttpExceptions':true }; 

  var res=UrlFetchApp.fetch('myapp/api/getxml', requestOptions); //Add RESTAPI Endpoint where var json=res.getContentText(); Logger.log(res);

appscript1.png

here in header i am getting null in authorization.

I hope you can help me in this.

Regards:

Hassan Shabbir

Ben Ronkin

unread,
Aug 26, 2022, 11:10:01 PM8/26/22
to Google Apps Script Community
On this line: var headers = { Authorization: 'Bearer Token' }; 

It looks like you're passing the string "Token" instead of the actual token.

Ben

Bruce Mcpherson

unread,
Aug 27, 2022, 5:43:26 AM8/27/22
to google-apps-sc...@googlegroups.com
The property name should be 'headers' not 'header' in your urlfetch options.
Also the correct option property for redirect is followRedirects: true




--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/e49d3182-de63-413f-8f84-3c574139142bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages