Skip to main content
Participant
January 23, 2024
Question

Network request failed error in api calling

  • January 23, 2024
  • 1 reply
  • 879 views

I am using below code for calling some external api in our plugin and getting error: Network request failed

Anyone kindly help to sort out this isue.

 

*********mainfeest.json***********

{
"id": "xyz",
"name": "xyz",
"version": "1.0.1",
"main": "index.html",
"manifestVersion": 5,
"icons": [
{
"width": 48,
"height": 48,
"path": "icons/plugin.png",
"scale": [1, 2],
"theme": ["darkest", "dark", "medium", "lightest", "light", "all"],
"species": ["pluginList"]
}
],

"requiredPermissions": {
"network": {
"domains": ["http://xyz.com"]
},
"clipboard": "readAndWrite",
"webview": {
"allow": "yes",
"domains": ["http://xyz.com"]
},
"launchProcess": {
"schemes": ["https", "slack"],
"extensions": [".xd", ".psd"]
}
}
}
 
**********common function*************:
async function fetchData(API) {
console.log("calling")
try {
const response = await fetch(API);
const data = await response.json();
console.log(data);
} catch (error) {
console.log('Error fetching data:', error);
}
}
************Calling function*************
fetchData("https://xyz.com/abc")
 
API working when I put hostenty else getting error Network request failed

1 reply

Community Expert
March 10, 2024

Not really sure how to help on this one

Maybe check the URL is ok - sometimes small typos can cause issues - I was writing a script the other day for illustrator to target a note called 'Folder' and I accendiatlly typed the note in Illustrator as Folder with a paragraph return - I had to write a catch alert in the script to identify why it wasn't working - and it returned the error.


I'm guessing the protocol matches the domain in manifest.json.
Can you check for CORS errors and server permissions?
Maybe security policies?