Skip to main content
Question

Rest API call inside figma plugin

  • February 21, 2023
  • 0 replies
  • 1287 views

GopalGupta

Hi Folks,

I am trying to use the figma comment API inside the plugin but not able to call that directly, I tried to use Axios also but getting errors.

Can we call figma apis directly inside plugin, is it possible? below code I am trying to execute.

fetch('https://api.figma.com/v1/files/R6ykujiQzXipdL2KxEUX1a/comments', {
        method: 'GET',
        mode: 'cors',
        cache: 'no-cache',
        headers: {
          'Content-Type': 'application/json',
          'X-FIGMA-TOKEN': 'figd_mfT5pS4cf62EMIfsxlIWZjF4XNsmo8Se19V', 
        },
    }).then(resp => resp.json() // this returns a promise
    ).then(repos => {
        let csvContent = "data:text/csv;charset=utf-8,";
        for (const repo of repos.comments) {
            let row = '';
            for (const property in repo) {
                if (typeof repo[property] == 'string')
                    row += repo[property]+ ",";
            }
            csvContent += row + "\r\n";
        }
        var encodedUri = encodeURI(csvContent);
        window.open(encodedUri);
    }).catch(ex => {
        
    });

Here I want to download the comments on current figma page by running the plugin.

This topic has been closed for replies.

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings