javascriptapifigma

Why can i not access the Figma API token with a http request?


i am trying to acess the figma API using my personal token, but once i make the request it sends a response with the 403 status (forbidden), can someone help me ?

I generated a token: My token

I am making the request to the following url: 'https://api.figma.com/v1/files/${mytoken}';

The status code is the following: 403

What is wrong with my code? is the url wrong ?

    fetch('https://api.figma.com/v1/mytoken').then((response) => {
        console.log(response)

})

Status code: 403 Forbidden


Solution

  • According to figma authentication documentation you should add the token to the header of the request.

    X-Figma-Token: *YOUR TOKEN*
    
    fetch('https://api.figma.com/v1/files/...', {
            method: 'GET',
            headers: {
                'X-Figma-Token': 'your-figma-token',
            },
        })
        .then(response => response.json())
        .then(response => console.log(response))
        .catch(err => console.error(err));