turkeryildirim / figma-api
PHP library for Figma API
Requires
- php: >=8.1
- ext-curl: >=7.60.0
- guzzlehttp/guzzle: ^8.6
- monolog/monolog: ^3.13
- psr/simple-cache: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpstan/phpstan-phpunit: ^2.1
- phpstan/phpstan-strict-rules: ^2.1
- phpunit/phpunit: ^13.4
- squizlabs/php_codesniffer: ^4.0
- turkeryildirim/phpunit-json-coverage-report: ^1.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A PHP library for Figma's REST API covering files, teams, folders, components, styles, users, version history, comments, reactions, webhooks, variables, dev resources, library analytics, activity logs, developer logs, AI usage, payments, and oEmbed endpoints.
Description
This library provides typed PHP endpoints, response models, and DTOs (>= 8.1) for the Figma REST API.
Due to inconsistencies in property naming across various Figma API endpoints (e.g., style_type and styleType), property names used across response objects and DTOs in this library are standardized to camelCase.
Supported API endpoints
- Files (including node rendering, image fills, metadata, and file duplication)
- Teams (create, fetch, and invite members)
- Folders v1/v2 (replaces deprecated Projects endpoints)
- Version History
- Comments & Reactions
- Users (
me) - Components & Component Sets
- Styles
- Webhooks v2
- Activity Logs
- Developer Logs
- AI Usage
- Payments
- Variables (local, published, and bulk mutations)
- Dev Resources
- Library Analytics
- oEmbed
- Projects (deprecated — kept for
ProjectsEndpointcompatibility; useFoldersEndpointinstead)
Installation
You can install this library using Composer (requires PHP >=8.1 and ext-curl >=7.60.0):
composer require turkeryildirim/figma-api
Then include Composer's autoloader in your application:
require 'vendor/autoload.php';
Documentation
You can read full details about Figma API endpoints and properties in the official Figma REST API documentation.
All fields are populated with response data received from the API endpoint and normalized to consistent types:
- Boolean strings (such as
"false") are converted to native booleans. - Empty response strings (
"") and empty collections are normalized tonull. - Missing fields defined on a response or DTO are marked as
null.
By default, GET responses are cached in memory (ArrayCache) for 5 minutes (300 seconds) and invalidated on POST, PUT, and DELETE calls to the same endpoint. You can pass any PSR-16 CacheInterface driver (see samples/CustomCacheSample.php).
Actions and errors are logged using Monolog (ErrorLogHandler) by default. You can pass any PSR-3 LoggerInterface driver (see samples/CustomLoggerSample.php).
Breaking Changes (Upgrading from 1.x to 2.x)
If you are upgrading an existing integration from 1.x, review the following behavioral and type changes:
FileKeyTrait::$filekeyrenamed to$fileKey: AffectsCommentType,ComponentType,ComponentSetType, andStyleType(snake_casefile_keyand legacyfilekeykeys in input payloads are still accepted).TypeStyleType::$hyperlinktype changed: Changed from?stringto?HyperlinkType(Turker\FigmaAPI\Types\File\HyperlinkTypewithtype,url, andnodeID) to match the Figma REST API object schema.CanvasNodeType::$flowStartingPointstype changed: Changed from?FlowStartingPointsTypetoFlowStartingPointsType[]|null(?array) to match the Figma REST API array schema.PaintType::$filterstype changed: Changed fromImageFiltersType[]|null(?array) to?ImageFiltersTypeto match the Figma REST API object schema.- Map keys preserved (
preserveKeys: true):FileNodesResponse::$nodes,StylesTrait::$styles,ComponentNodeType::$componentPropertyDefinitions, andInstanceNodeType::$componentPropertiesnow preserve the Figma node ID, style ID, or property name keys instead of re-indexing to0, 1, 2.... CommentsEndpoint::fetchComments()query parameter fixed: Now sendsas_mdinstead ofad_md.- Boolean query parameter serialization:
BaseEndpoint::filterParams()now serializes boolean query parameters (e.g.,branch_data,use_absolute_bounds,as_md) as'true'/'false'strings instead of'1'/'0'. ProjectsEndpointdeprecated:ProjectsEndpoint(teams/{teamId}/projects,projects/{projectId}/files) is marked@deprecatedin favor ofFoldersEndpoint(/v2/teams/{teamId}/folders,/v2/folders/{folderId}/files).HttpClientTLS verification enabled by default: Guzzle'verify'defaults totrue(use$httpClient->setVerifySsl(false)only if local development requires disabling TLS checks).HttpClientexception codes preserved:FigmaAPIException::getCode()now retains the HTTP status code (such as400,403,404,429,500) instead of0.- Unknown Figma node/action types:
ChildrenTraitandInteractionTypenow ignore unrecognizedtypevalues instead of throwingUnhandledMatchError.
How to use
License
PHP library for Figma REST API is licensed under MIT.