Error DNS with urlFetch

2,521 views
Skip to first unread message

Emeric HOCHART

unread,
Jan 24, 2020, 2:37:51 AM1/24/20
to Google Apps Script Community
Hi everyone,
I have a problem with an API call.
I have a dns error that I can't resolve.

I make the call from a script in a google sheet (apps script) and the url of my request is on https:// ...

I think this is a CORS problem but I don't know how to fix it. I post my code :


function doRequest() {
   
// GET Request with params
   
var authHeader = 'Basic ZWhvY2hhMTJfQ29jaGlzZV8......=';
       
   
var options = {
       
'method' : 'get',
       
'contentType' : 'application/json',
       
'accept' : 'application/json',
       
'muteHttpExceptions': true,
       
'headers' : {
         
Authorization : authHeader
       
}
     
};
         
   
// Call the API
   
var response = UrlFetchApp.fetch('https://xxx.xxx/rest/query/8a5f90c66e1a2e4b016e1c14a7141800/resultat?limite=1000&valeurNumeriqueFormatee=false', options);

   

   
var result = JSON.parse(response);
   
Logger.log(result);  
}



Riël Notermans

unread,
Jan 24, 2020, 3:02:45 AM1/24/20
to Google Apps Script Community
What is the error?

A DNS error is usually the case that your URL is incorrectly spelled.

CORS is not an issue if you do server-to-server.


Met vriendelijke groet,

pic
Riël Notermans
Technisch Directeur
logo
phone
email
email
040 711 41 94
ri...@zzapps.nl
www.zzapps.nl


--
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/1d19f3d7-eb4e-4a0e-aa65-524c591b9e6f%40googlegroups.com.

Emeric HOCHART

unread,
Jan 24, 2020, 3:05:01 AM1/24/20
to google-apps-sc...@googlegroups.com

Alan Wells

unread,
Jan 24, 2020, 9:49:55 AM1/24/20
to Google Apps Script Community
There is no "accept" parameter for fetch options.  You have:

'accept' : 'application/json',

remove that.
Your URL has search string parameters:

?limite=1000&valeurNumeriqueFormatee=false

The HTTPS method GET does not accept a payload, so you can't use a payload.  So, you are okay with that.

Usually the Authorization header has the word "Bearer" in it:

Authorization: 'Bearer ' + authHeader

On Friday, January 24, 2020 Emeric HOCHART wrote:
I tested my request beforehand in Postman.

my url is  :

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.

--
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-community+unsub...@googlegroups.com.

Riël Notermans

unread,
Jan 24, 2020, 9:56:26 AM1/24/20
to Google Apps Script Community

@Alan, the Basic Authorization header is also possible, it usually is a B64 or username:password. The bearer is used for oAuth calls.
The URL is just not right, a DIG does not show any records for this domainname: factory.europe.subsidia.org



Met vriendelijke groet,

pic
Riël Notermans
Technisch Directeur
logo
phone
email
email
040 711 41 94
ri...@zzapps.nl
www.zzapps.nl

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.

--
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.

--
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/3da8bacf-8110-495d-9a92-e818a7a046fd%40googlegroups.com.

Emeric HOCHART

unread,
Jan 27, 2020, 1:44:22 AM1/27/20
to google-apps-sc...@googlegroups.com
Thanks for your response.

The url corresponds to a web service. The API is private and not open to everyone.
 
When I make the API call via urlfetchapp, I think that since the call comes from a public google server, I get a dns error because it is two different domains and for security reasons, access forbidden. 

Am I right ?


Bruce Mcpherson

unread,
Jan 27, 2020, 1:17:44 PM1/27/20
to google-apps-sc...@googlegroups.com
Is it possible that the domain is internal to your organization? The url you are using is not visible publicly and that's why you are getting a dns error.
That means if you are pinging it from a machine in your internal network (presumably that's where you ran postman from), it will work, but if you try to access it from externally (apps script runs on a google server, not your local machine) then it will not see it. 

For this to work you'll need a publicly exposed endpoint for the API you want to use.






Reply all
Reply to author
Forward
0 new messages