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();
}