Here is an example based on your request:
Ethereum: the URLFETCAPP request fails in the menu functions but not in personalized functions
As a developer who works with the Google Apps script, you are probably not foreign to the challenges of connection to external bees. Recently, I encountered a problem in which my requests for “Urlfatchapp” have not tried to recover market prices from an external resting fir, but not when using personalized functions.
The problem: Request EXTERNAL API
When I used the following code in a menu function:
`Javascript
Getmarketprices function () {
var options = {
Method: “Get”,
newspapers: {
‘Content-Type’: ‘Application/Json’
}
};
VAR ANSWER = URLFECTHAPP.FECTH (‘ Options);
var data = json.pars (reply.getContentext ());
return data;
}
`
The request failed with an error message that indicates that the URL was malformed. After further investigations, I realized that the problem was not related to a problem with the endpoint bees itself, but rather with the way it is configured "URLFECTHAPP".
Personalized function solution
When using personalized functions, the problem can be more complex and requires careful consideration on how to manage HTTP requests.
After some research and experiments, I discovered that if you are carrying out HTTP requests within a personalized function, it is essential to use the objectscream instead ofIn particular, when you create a new "ull 'object for an external API request:
Javascript
Getmarketprices function () {
var options = {
Method: “Get”,
newspapers: {
‘Content-Type’: ‘Application/Json’
}
};
var url = new url (‘
URL.SEarchParams.set (‘symbol’, ‘btcusdt’); // Replace with the desired symbol
VAR Answer = URLFETTHAPP.FECTH (URL.HREF, Options);
var data = json.pars (reply.getContentext ());
return data;
}
`
The key difference between the use ofURLFECTHAPPP ‘is the creation of a new object’ URL ‘is that the first uses theHref
resulting URL, which allows you to easily add the query parameters (such as the symbol) . This approach works in both menus functions and personalized functions.
Conclusion
In conclusion, if there are problems with external API requests when usingURLFETTHAPP ‘, but not when using personalized functions, it is likely due to how HTTP requests are configured inside your script. Moving from UrlfatchApp
to the creation of a new object ‘URL’ or to the query parameters by adding directly to the resulting URL, you should be able to solve the problem and correctly recover market prices from an external resting fir.
I hope this article was useful to solve the problem for you!