This is an undocumented API. It may break at any time. Contributions welcome; please share in the comments and I will update the gist accordingly.
Each request must be passed a valid authentication cookie. The cookie takes the following form and can be pulled from any authenticated request made in the browser:
__Host-figma.authn=<#token#>
Example Python usage:
from typing import Any, Dict
from ratelimiter import RateLimiter
import requests
class FigmaAPIRequestError(Exception):
"""An error indicating the Figma API request failed."""
pass
@RateLimiter(max_calls=1, period=1)
def GetFigmaUrl(path: str) -> Dict[str, Any]:
url = f'https://www.figma.com/api/{path}'
headers = {
'cookie': '__Host-figma.authn=' + self._figma_authn,
'cache-control': 'no-cache',
'pragma': 'no-cache',
'user-agent': 'YourUserAgent/1.0'
}
requests.get(url, headers=headers)
response = raw_response.json()
if response['error'] or response['status'] != 200:
raise FigmaAPIRequestError(raw_response)
return response
Certain requests allow for analytics to be fetched for a specific time period. These requests appear to be bucketed by day; i.e. the start and end timestamp together define a date range.
For example, if you want to get analytics for a specific date you can do the following:
import datetime
date = datetime.datetime(2022, 9, 30)
start_timestamp = int(date.replace(tzinfo=datetime.timezone.utc).timestamp())
end_timestamp = start_timestamp + 24 * 60 * 60 - 1
Note the - 1
in the end_timestamp calculation is needed to avoid including the next day in the results.
Endpoint:
https://www.figma.com/api/dsa/num_teams?org_id=<#org_id#>
Example response:
{
"error": false,
"status": 200,
"meta": {
"num_teams": 10
},
"i18n": null
}
Endpoint:
https://www.figma.com/api/dsa/library/<#library_file_key#>
Example response:
{
"error": false,
"status": 200,
"meta": {
"library_file_key": "abcd",
"library_file_name": "My Library",
"team_name": "My Team",
"team_id": "1234",
"license_group_id": null,
"folder_name": "Libraries",
"folder_id": "5678",
"file": null,
"thumbnail_url": "/component/abcd1234/thumbnail?ver=123:456",
"num_components": 123,
"num_styles": 123,
"num_weekly_insertions": 123,
"num_teams": 123
},
"i18n": null
}
Returns team-specific usage data for a library for a given window of time.
Required parameters:
start_ts
: The start timestamp for the time window to fetch. Expressed in unix epoch timestamp format (seconds).end_ts
: The end timestamp for the time window to fetch. Expressed in unix epoch timestamp format (seconds).
Endpoint:
https://www.figma.com/api/dsa/library/<#library_file_key#>/team_usage?start_ts=<#start_ts#>&end_ts=<#end_ts#>
Example response:
{
"error": false,
"status": 200,
"meta": [
{
"team_id": "1234",
"team_name": "Some team",
"num_insertions": "123"
},
{
"team_id": "5678",
"team_name": "Some other team",
"num_insertions": "456"
}
],
"i18n": null
}
Thanks a lot @jverkoey for this GitHub gist.
I understood well the whole of what you wrote and managed to reproduce it.
The cookie has an expiration date, and wishing to automate these calls via a daily cron, could you please tell me how a server could retrieve a new token once the old one has expired?
Thank you!