Skip to main content
Question

API integration 403 forbidden issue

  • May 7, 2024
  • 1 reply
  • 402 views

I’m trying to integrate with Figma using below file APIs
#1. GET /v1/files/:file_key: Retrieve information about a specific file by its key.
#2. GET /v1/files/:file_key/nodes: Retrieve the node structure of a specific file.
#3. GET /v1/files/:file_key/components: Retrieve information about components within a specific file.
#4. GET /v1/images/:file_key: Export images from a specific file.

API #1 is working fine while other three APIs are giving 403 forbidden exceptions.

Please help in resolving the forbidden issue.

Reference Code:
public async Task GetFileContent(string fileKey)
{
string url = $https://api.figma.com/v1/files/{fileKey};
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add(“X-Figma-Token”, accessToken);

               HttpResponseMessage response = await httpClient.SendAsync(request);
               response.EnsureSuccessStatusCode();

               string responseBody = await response.Content.ReadAsStringAsync();
               return responseBody;

}

            public async Task<string> GetFileNodes(string fileKey)
            {
                            string baseUrl = https://api.figma.com/v1/;
                            httpClient.DefaultRequestHeaders.Add("X-Figma-Token", accessToken);

                            var response = await httpClient.GetAsync($"{baseUrl}files/{fileKey}/nodes");
                            response.EnsureSuccessStatusCode();
                            return await response.Content.ReadAsStringAsync();
            }

            public async Task<string> GetFileComponents(string fileKey)
            {
                            string baseUrl = https://api.figma.com/v1/;
                            httpClient.DefaultRequestHeaders.Add("X-Figma-Token", accessToken);

                            var response = await httpClient.GetAsync($"{baseUrl}files/{fileKey}/components");
                            response.EnsureSuccessStatusCode();
                            return await response.Content.ReadAsStringAsync();
            }

            public async Task<byte[]> ExportFileImages(string fileKey)
            {
                            string baseUrl = https://api.figma.com/v1/;
                            httpClient.DefaultRequestHeaders.Add("X-Figma-Token", accessToken);

                            var response = await httpClient.GetAsync($"{baseUrl}images/{fileKey}");
                            response.EnsureSuccessStatusCode();

                            // Read the image content as a byte array
                            return await response.Content.ReadAsByteArrayAsync();
            }
This topic has been closed for replies.

1 reply

Celine_
Figmate
  • Community Support
  • 3736 replies
  • May 9, 2024

Hi @WinWire_Technologies_Inc ,
Thanks for reaching out to the community. The technical specialist replied to your ticket and is waiting for your response to investigate it further. Please check your inbox and continue the conversation there.

For visibility here, “we were able to call the API on our end as expected, therefore suspecting that there are errors in the reference code that you are using.
Additionally, for the second and fourth call, you would also need the “ids” query”. Thanks!


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