Figma REST API Specification

repository·main·Indexed 42 days ago

https://github.com/figma/rest-api-spec

Official OpenAPI v3.1.0 specification and TypeScript types for the Figma REST API, providing type-safe integrations via the @figma/rest-api-spec package.

Tokens
447
Snippets
2
Records
4
Agent score
4%

What's inside Figma REST API

  1. Understand the TypeScript type naming conventions

    main

    The TypeScript types are generated from the OpenAPI specification using a custom generator optimized for the Figma REST API. They follow specific naming patterns:

    • Named Types: All OpenAPI schemas, responses, and request parameters are exported as named types (e.g., Paint, VariableAlias).
    • Endpoint-Associated Types: Types related to specific API endpoints are prefixed with the OpenAPI operation ID. For example, the getFile operation generates:
      • GetFilePathParams
      • GetFileQueryParams
      • GetFileResponse
    • Request Bodies: For endpoints that expect a request body, the types are suffixed with RequestBody (e.g., postComments -> PostCommentsRequestBody).
  2. Use Figma REST API TypeScript types

    main

    Import the generated types from @figma/rest-api-spec to annotate your API responses or request bodies. This provides type safety when using HTTP clients like axios.

    import { type GetFileResponse } from '@figma/rest-api-spec'
    
    // Many popular HTTP clients let you annotate response types
    const result = await axios.get<GetFileResponse>(url);
    result.data // This has type GetFileResponse
  3. Access the OpenAPI specification

    main
    The Figma REST API uses OpenAPI v3.1.0. The raw specification files are located in the openapi/ directory of this repository and can be used with various tools to generate documentation or custom SDKs.