spiderweb191919
spiderweb191919

Reputation: 31

Creating figma plugin in with rest api

I am trying to create a plugin that fetches data from an API, but it doesn't seem to work. I want to log data from this public API endpoint: https://dummy.restapiexample.com/api/v1/employees.

if (msg.type === "create-rectangles") {
console.log("Click was observed");
(async () => {
    const response = await fetch("https://dummy.restapiexample.com/api/v1/employees", {
        method: "GET",
        headers: {
            "Content-Type": "application/json",
            "Access-Control-Allow-Origin": "*",
        },
    });

    const json = await response.json();
    console.log("Data received:", json);
})();

}

In my manifest.json, I added the following to allow network access:

"networkAccess": {
"allowedDomains": [
    "https://dummy.restapiexample.com/"
]

}

However, the data isn't being logged to the console as expected. What might be the issue, and how can I fix this?

Upvotes: 0

Views: 94

Answers (0)

Related Questions