Ethereum: UrlFetchApp request fails in Menu Functions but not in Custom Functions (connecting to external REST API)

Here is an example article based on your request:

Ethereum: Urlfetchapp request has not been said in menu functions, but not in non -standard functions

As a programmer working with a Google Apps script, you are probably not alien to the challenges related to combining with external API interfaces. I recently encountered a problem where my Urlfetchapp demands were not a failure, trying to withdraw market prices from the external API holiday interface, but not when I use non -standard features.

Problem: API external request

When I used the following code as a menu function:

`Javascript

Getmarketprises function () {

Var options = {

Method: "Take",

Headers: {

"Content type": "App/JSON"

}

};

Var Reply = Urlfetchapp.fetch (' options);

Var data = json.parse (response.getContenttext ());

Feedback;

}

The request failed to make an error message indicating that the URL has been removed. After further consideration, I realized that the problem was not related to the problem of the endpoint of the API itself, but more recently with the configured “Urlfetchapp”.

Solving non -standard functions

When using non -standard functions, the problem can be more complex and requires careful consideration on how to maintain HTTP requirements.

After some studies and experiments, I found that if you send HTTP requirements from a non -standard function, it is necessary to use the “URL” site instead of “URLFETCHAPP”. In particular, when you create a new “URL” object for an external request of the API interface:

`Javascript

Getmarketprises function () {

Var options = {

Method: "Take",

Headers: {

"Content type": "App/JSON"

}

};

Var url = new URL ('

url.searchparty.set ("symbol", "btcusdt"); // Replace the desired character

VAR reply = urlfetchapp.fetch (url.href, options);

Var data = json.parse (response.getContenttext ());

Feedback;

}

The main difference between the use of “Urlfetchapp” and the creation of the new “URL” object is that the first uses the “HREF” properties of the created URL, which allows you to easily attach the inquiry parameters (such as the symbol). This approach works in both menu functions and non -standard functions.

App

In summary, if you have problems with the external requirements of the API interface, when you use “Urlfetchapp”, but not when using non -standard functions, it is probably the result of how HTTP requests are configured into the script. By moving from “Urlfetchapp” to creating a new “URL” object or by attaching the request parameters directly to the resulting URL level, you need to be able to solve the problem and successfully withdraw market prices from the API Rest external interface.

I hope this article was helpful in solving the problem!

Tags: