### Install Webflow API SDK Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/README.md Install the Webflow API SDK using npm or yarn. ```bash npm install webflow-api # or yarn add webflow-api ``` -------------------------------- ### Create Page Structure Example Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/PagesClient.md Demonstrates creating a folder and then nesting multiple pages within that folder. This example utilizes the `create` method for both folders and pages, and `list` to verify. ```typescript // Create folder for a section const servicesFolder = await webflow.pages.create(siteId, { title: "Services", slug: "services", isFolder: true }); // Create pages within folder const servicePages = [ { title: "Consulting", slug: "consulting" }, { title: "Development", slug: "development" }, { title: "Design", slug: "design" } ]; for (const servicePage of servicePages) { await webflow.pages.create(siteId, { title: servicePage.title, slug: servicePage.slug, parentId: servicesFolder.id // Nested under folder }); } // List all pages const pages = await webflow.pages.list(siteId); console.log(`Created ${pages.pages.length} pages`); // Find root-level pages const rootPages = pages.pages.filter(p => !p.parentId); console.log(`Root pages: ${rootPages.length}`); ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/webflow/js-webflow-api/blob/master/CONTRIBUTING.md Install the project dependencies using yarn. ```bash yarn install ``` -------------------------------- ### Example: Update Robots.txt Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/AdditionalClients.md Demonstrates updating the robots.txt content for a site. ```typescript await webflow.sites.robotsTxt.update(siteId, { content: "User-agent: *\nDisallow: /admin" }); ``` -------------------------------- ### Example: Create Site Redirect Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/AdditionalClients.md Demonstrates creating a new site redirect with a specified source and target URL. ```typescript await webflow.sites.redirects.create(siteId, { source: "/old-page", target: "/new-page" }); ``` -------------------------------- ### Install Webflow SDK with npm Source: https://github.com/webflow/js-webflow-api/blob/master/README.md Add the webflow-api dependency to your project using npm. ```shell npm install webflow-api ``` -------------------------------- ### Install Webflow SDK with yarn Source: https://github.com/webflow/js-webflow-api/blob/master/README.md Add the webflow-api dependency to your project using yarn. ```shell yarn add webflow-api ``` -------------------------------- ### Upload and Organize Assets Example Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/AssetsClient.md Demonstrates how to create folders, upload an asset to a specific folder, update its metadata, and list all assets in a Webflow site. ```typescript // Create organized folder structure const imagesFolder = await webflow.assets.createFolder(siteId, { name: "Product Images" }); const thumbnailsFolder = await webflow.assets.createFolder(siteId, { name: "Thumbnails", parentId: imagesFolder.id }); // Upload asset to folder const file = new File(["image data"], "product.jpg"); const uploaded = await webflow.assets.create(siteId, { filename: "product.jpg", file: file, folderId: imagesFolder.id }); console.log("Asset URL:", uploaded.url); // Update asset metadata await webflow.assets.update(siteId, uploaded.id, { customData: { productId: "SKU123", category: "Electronics" } }); // List all assets const assets = await webflow.assets.list(siteId); console.log(`Total assets: ${assets.assets.length}`); ``` -------------------------------- ### Example: Workspace Operations Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/AdditionalClients.md Demonstrates listing all workspaces, retrieving a specific workspace by its ID, and accessing audit logs for a workspace. ```typescript const workspaces = await webflow.workspaces.list(); const workspace = await webflow.workspaces.get(workspaceId); console.log(workspace.name); // List audit logs const logs = await webflow.workspaces.auditLogs.list(workspaceId); ``` -------------------------------- ### Import TokenClient Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/TokenClient.md Import the necessary types and initialize the token client. This is typically done once at the start of your application. ```typescript import type { WebflowClient } from "webflow-api"; const token = webflowClient.token; ``` -------------------------------- ### client.sites.plans.getSitePlan Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Get site plan details for the specified Site. This requires an Enterprise workspace. ```APIDOC ## GET /sites/{site_id}/plan ### Description Retrieve the site plan details for the specified Site. **Note:** This endpoint requires an Enterprise workspace. ### Method GET ### Endpoint /sites/{site_id}/plan ### Parameters #### Path Parameters - **site_id** (string) - Required - Unique identifier for a Site ### Response #### Success Response (200) - **plan_id** (string) - The ID of the site plan. - **plan_name** (string) - The name of the site plan. - **is_enterprise** (boolean) - Indicates if the plan is an Enterprise plan. ``` -------------------------------- ### Get Site Plans Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/SitesClient.md Retrieve information about the plans associated with a specific site. ```typescript const plans = await webflow.sites.plans.get(siteId); ``` -------------------------------- ### Manage Site Robots.txt Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/AdditionalClients.md Provides methods to get and update the robots.txt configuration for a site. ```typescript get(siteId: string): Promise update(siteId: string, robotsTxt: RobotsTxtUpdateRequest): Promise ``` -------------------------------- ### Import CollectionsClient Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/CollectionsClient.md Import the WebflowClient type and initialize the collections client. This is the initial setup required to use the collections API. ```typescript import type { WebflowClient } from "webflow-api"; const collections = webflowClient.collections; ``` -------------------------------- ### Full Workflow: Create Collection, Fields, and Items Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/CollectionsClient.md Demonstrates a complete workflow for creating a new collection, adding fields to it, and then creating items within that collection. This example covers collection creation, field updates, item creation, and listing items. ```typescript // Create collection const collection = await webflow.collections.create(siteId, { displayName: "Team Members", singularName: "Team Member" }); // Add fields await webflow.collections.fields.update( siteId, collection.id, fieldId, { displayName: "Name", type: "PlainText", isRequired: true } ); // Create item const item = await webflow.collections.items.create( siteId, collection.id, { fieldData: { name: "Jane Doe", email: "jane@example.com" } } ); // List items const items = await webflow.collections.items.list(siteId, collection.id); console.log(items.items); // Array of CollectionItem objects ``` -------------------------------- ### Get Form Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/FormsClient.md Retrieves a single form by its unique identifier within a specific site. Use this method to get detailed information about a particular form. ```APIDOC ## get(siteId, formId, requestOptions?) ### Description Retrieve a single form by ID. ### Method `get` ### Parameters #### Path Parameters - **siteId** (string) - Required - Unique identifier for the site. - **formId** (string) - Required - Unique identifier for the form. - **requestOptions** (RequestOptions) - Optional - Request-specific configuration. ### Returns `Promise
` — The form object. ### Throws - `BadRequestError` (400) — Invalid ID format - `UnauthorizedError` (401) — Invalid or missing authentication - `NotFoundError` (404) — Site or form not found - `TooManyRequestsError` (429) — Rate limit exceeded ### Required Scope `forms:read` ### Example ```typescript const form = await webflow.forms.get( "580e63e98c9a982ac9b8b741", "63e80c68b7f6d40011dba84a" ); console.log(form.name); // Internal form name console.log(form.displayName); // User-facing name ``` ``` -------------------------------- ### Get a Specific Collection Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/CollectionsClient.md Retrieve a single collection by its ID using the `get` method. Requires both the site ID and the collection ID. The 'cms:read' scope is necessary. ```typescript const collection = await webflow.collections.get( "580e63e98c9a982ac9b8b741", "63e80c68b7f6d40011dba84a" ); console.log(collection.displayName); // "Blog Posts" console.log(collection.fields); // Array of Field objects ``` -------------------------------- ### Manage Ecommerce Products Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/AdditionalClients.md Use the ProductsClient to list, get, create, update, and delete ecommerce products. Ensure you have the necessary 'ecommerce:read' and 'ecommerce:write' scopes. ```typescript const products = await webflow.products.list(siteId); const product = await webflow.products.create(siteId, { name: "Premium Widget", description: "High-quality widget", price: 99.99 }); const updated = await webflow.products.update(siteId, productId, { price: 89.99 }); ``` -------------------------------- ### Initialize Webflow Client and List Sites Source: https://github.com/webflow/js-webflow-api/blob/master/README.md Initialize the Webflow client with an access token and list all sites. Ensure your WEBFLOW_API_TOKEN and SITE_ID are set as environment variables. ```javascript import { WebflowClient } from "webflow-api"; // Workspace or site token const webflow = new WebflowClient({ accessToken: process.env.WEBFLOW_API_TOKEN, }); // Environment variables // in string format, such as "639656400769508adc12fe42" const site_id = process.env.SITE_ID; const custom_domain_id_1 = process.env.CUSTOM_DOMAIN_ID_1; const custom_domain_id_2 = process.env.CUSTOM_DOMAIN_ID_2; // List sites const sites = await webflow.sites.list(); // Get site const site = await webflow.sites.get(site_id); // Get custom domains const customDomains = await webflow.sites.getCustomDomain(site_id); // Publish site const publishRequest = await webflow.sites.publish(site_id, { customDomains: [custom_domain_id_1, custom_domain_id_2], publishToWebflowSubdomain: true, }); ``` -------------------------------- ### Update Static Page Content Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Updates content on a static page in secondary locales. Use get page content to identify nodes and get component properties for overrides. Always include the original data-w-id attribute for consistent behavior across locales. ```typescript await client.pages.updateStaticContent("63c720f9347c2139b248e552", { localeId: "localeId", nodes: [{ nodeId: "a245c12d-995b-55ee-5ec7-aa36a6cad623", text: "

The Hitchhiker's Guide to the Galaxy

" }, { nodeId: "a245c12d-995b-55ee-5ec7-aa36a6cad627", text: "

Don't Panic!

Always know where your towel is.

" }, { nodeId: "a245c12d-995b-55ee-5ec7-aa36a6cad635", choices: [{ value: "choice-1", text: "First choice" }, { value: "choice-2", text: "Second choice" }] }, { nodeId: "a245c12d-995b-55ee-5ec7-aa36a6cad642", placeholder: "Enter something here..." }, { nodeId: "a245c12d-995b-55ee-5ec7-aa36a6cad671", value: "Submit", waitingText: "Submitting..." }, { nodeId: "a245c12d-995b-55ee-5ec7-aa36a6cad629", propertyOverrides: [{ propertyId: "7dd14c08-2e96-8d3d-2b19-b5c03642a0f0", text: "

Time is an illusion

" }, { propertyId: "7dd14c08-2e96-8d3d-2b19-b5c03642a0f1", text: "Life, the Universe and Everything" }] }] }); ``` -------------------------------- ### Create a Product Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/COMMON-OPERATIONS.md Add a new product to the e-commerce catalog with its name, description, price, and an image URL. ```typescript const product = await webflow.products.create(siteId, { name: "Premium Widget", description: "High-quality widget with advanced features", price: 99.99, image: "https://cdn.webflow.com/image.jpg" }); console.log(`Created product: ${product.id}`); ``` -------------------------------- ### Get Site Source: https://github.com/webflow/js-webflow-api/blob/master/README.md Retrieves details for a specific site by its ID. ```APIDOC ## Get Site ### Description Retrieves details for a specific site by its ID. ### Method `GET` (implied by SDK method) ### Endpoint `/sites/{site_id}` (implied by SDK method) ### Parameters #### Path Parameters - **site_id** (string) - Required - The ID of the site to retrieve. ### Usage ```javascript const site_id = process.env.SITE_ID; const site = await webflow.sites.get(site_id); ``` ``` -------------------------------- ### WebflowClient Initialization and OAuth Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/MANIFEST.txt Documentation for the main SDK client, including its constructor, configuration options, and OAuth methods for token management. ```APIDOC ## WebflowClient ### Description Provides the main entry point for interacting with the Webflow API. Includes methods for client initialization, configuration, and OAuth flows. ### Methods #### Constructor `new WebflowClient(options)` Initializes a new Webflow client instance. **Parameters** - **options** (object) - Required - Configuration options for the client. - `clientId` (string) - Required - Your Webflow application's client ID. - `clientSecret` (string) - Required - Your Webflow application's client secret. - `redirectUri` (string) - Required - The redirect URI configured for your application. - `token` (object) - Optional - An existing token object for authentication. - `accessToken` (string) - Required - The access token. - `tokenType` (string) - Required - The type of token (e.g., 'Bearer'). - `expiresIn` (number) - Required - The token's expiration time in seconds. - `refreshToken` (string) - Required - The refresh token. - `timeout` (number) - Optional - Request timeout in milliseconds. - `apiVersion` (string) - Optional - The API version to use (default: '1.0.0'). ### OAuth Methods #### `authorizeURL(options)` Generates the authorization URL for the OAuth flow. **Parameters** - **options** (object) - Required - Options for generating the authorization URL. - `scope` (string[]) - Required - An array of scopes to request. - `state` (string) - Optional - A unique value to maintain state between the request and callback. **Returns** - `string` - The authorization URL. #### `getAccessToken(code)` Exchanges an authorization code for an access token. **Parameters** - **code** (string) - Required - The authorization code received from the redirect. **Returns** - `Promise` - A promise that resolves with the token object. - `accessToken` (string) - The access token. - `tokenType` (string) - The type of token. - `expiresIn` (number) - The token's expiration time in seconds. - `refreshToken` (string) - The refresh token. #### `refreshToken(refreshToken)` Refreshes an expired access token using a refresh token. **Parameters** - **refreshToken** (string) - Required - The refresh token. **Returns** - `Promise` - A promise that resolves with the updated token object. ``` -------------------------------- ### Get robots.txt Configuration Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/SitesClient.md Retrieve the current robots.txt configuration for a site. ```typescript await webflow.sites.robotsTxt.get(siteId); ``` -------------------------------- ### Build the Project Source: https://github.com/webflow/js-webflow-api/blob/master/CONTRIBUTING.md Build the project using yarn. ```bash yarn build ``` -------------------------------- ### client.pages.scripts.getCustomCode Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Get all scripts applied to a page. Requires `custom_code:read` scope. ```APIDOC ## GET /pages/{page_id}/scripts ### Description Get all scripts applied to a page. ### Method GET ### Endpoint /pages/{page_id}/scripts ### Parameters #### Path Parameters - **page_id** (string) - Required - Unique identifier for a Page #### Query Parameters - **requestOptions** (ScriptsClient.RequestOptions) - Optional ### Response #### Success Response (200) - **scripts** (Webflow.ScriptApplyList) - List of scripts applied to the page. ### Response Example { "scripts": [ { "id": "cms_slider", "location": "header", "version": "1.0.0", "attributes": { "my-attribute": "some-value" } } ] } ``` -------------------------------- ### get Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/PagesClient.md Retrieves a single page by its ID. Requires `pages:read` scope. ```APIDOC ## get(siteId, pageId, requestOptions?) ### Description Retrieve a single page by ID. ### Method `get` ### Parameters #### Path Parameters - **siteId** (string) - Required - Unique identifier for the site. - **pageId** (string) - Required - Unique identifier for the page. - **requestOptions** (`RequestOptions`) - Optional - Request-specific configuration. ### Returns `Promise` — The page object. ### Throws - `BadRequestError` (400) — Invalid ID format - `UnauthorizedError` (401) — Invalid or missing authentication - `NotFoundError` (404) — Site or page not found - `TooManyRequestsError` (429) — Rate limit exceeded ### Required Scope pages:read ### Example ```typescript const page = await webflow.pages.get( "580e63e98c9a982ac9b8b741", "63e80c68b7f6d40011dba84a" ); console.log(page.title); ``` ``` -------------------------------- ### client.products.create Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Creates a new ecommerce product with a default SKU. Requires 'ecommerce:write' scope. ```APIDOC ## POST /sites/{site_id}/products ### Description Creates a new ecommerce product and its default SKU. Products must have at least one SKU. The default product type is 'Advanced'. ### Method POST ### Endpoint /sites/{site_id}/products ### Parameters #### Path Parameters - **site_id** (string) - Required - Unique identifier for a Site #### Request Body - **request** (Webflow.ProductsCreateRequest) - Required - The details of the product to create, including SKU properties if creating multiple SKUs. #### Query Parameters - **requestOptions** (ProductsClient.RequestOptions) - Optional ### Response #### Success Response (200) - **[Response Fields]** (Webflow.ProductAndSkUs) - The newly created product and its default SKU. ``` -------------------------------- ### Example: Script Operations Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/AdditionalClients.md Demonstrates common script operations including listing all scripts, creating a new script with specific properties, and updating an existing script's source code. ```typescript const scripts = await webflow.scripts.list(siteId); const script = await webflow.scripts.create(siteId, { displayName: "Analytics Script", location: "head", source: "" }); const updated = await webflow.scripts.update(siteId, scriptId, { source: "" }); ``` -------------------------------- ### Get .well-known Directory Configuration Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/SitesClient.md Access the configuration for the .well-known directory of a site. ```typescript const wellKnown = await webflow.sites.wellKnown.get(siteId); ``` -------------------------------- ### Initializing Webflow Client with Access Token Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/WebflowClient.md Shows how to instantiate the WebflowClient by passing an access token. This token can be a Workspace Token for broad access or a Site Token for site-specific access. ```typescript const webflow = new WebflowClient({ accessToken: "your_workspace_or_site_token" }); ``` -------------------------------- ### Get Custom Domains Source: https://github.com/webflow/js-webflow-api/blob/master/README.md Retrieves the custom domains associated with a specific site. ```APIDOC ## Get Custom Domains ### Description Retrieves the custom domains associated with a specific site. ### Method `GET` (implied by SDK method) ### Endpoint `/sites/{site_id}/custom-domains` (implied by SDK method) ### Parameters #### Path Parameters - **site_id** (string) - Required - The ID of the site. ### Usage ```javascript const site_id = process.env.SITE_ID; const customDomains = await webflow.sites.getCustomDomain(site_id); ``` ``` -------------------------------- ### Initialize and Use WebflowClient Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/README.md Initialize the WebflowClient with an access token and perform basic operations like listing sites, getting a specific site, listing collections, and listing items within a collection. ```typescript import { WebflowClient } from "webflow-api"; // Initialize client const webflow = new WebflowClient({ accessToken: process.env.WEBFLOW_API_TOKEN }); // List sites const sites = await webflow.sites.list(); console.log(sites.sites); // Get specific site const site = await webflow.sites.get("site-id"); console.log(site.displayName); // List collections in site const collections = await webflow.collections.list("site-id"); console.log(collections.collections); // List items in collection const items = await webflow.collections.items.list( "site-id", "collection-id" ); console.log(items.items); ``` -------------------------------- ### client.sites.create() Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Creates a new site. This endpoint is available for Enterprise workspaces only and requires the `workspace:write` scope. ```APIDOC ## client.sites.create() ### Description Creates a new site. ### Warning This endpoint requires an Enterprise workspace. ### Scope `workspace:write` ### Method POST ### Endpoint /sites ### Parameters #### Path Parameters - **workspace_id** (string) - Required - Unique identifier for a Workspace. #### Request Body - **request** (Webflow.SitesCreateRequest) - Required - The site creation request object. - **requestOptions** (SitesClient.RequestOptions) - Optional - Options for the request. ### Request Example ```json { "name": "The Hitchhiker's Guide to the Galaxy" } ``` ### Response #### Success Response (200) - **site** (Webflow.Site) - The created site object. ### Response Example ```json { "site": { "id": "580e63e98c9a982ac9b8b741", "name": "The Hitchhiker's Guide to the Galaxy", "created_on": "2023-10-27T10:00:00Z" } } ``` ``` -------------------------------- ### Create Resources Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/README.md Demonstrates how to create new resources such as sites, collections, and items within Webflow. ```APIDOC ## Create Resources ### Description Allows for the creation of new sites (Enterprise only), collections, and individual items within collections. ### Methods - `webflow.sites.create(workspaceId, data)`: Creates a new site. - `webflow.collections.create(siteId, data)`: Creates a new collection within a site. - `webflow.collections.items.create(siteId, collectionId, data)`: Creates a new item within a collection. ### Parameters - `workspaceId` (string): The ID of the workspace. - `siteId` (string): The ID of the site. - `collectionId` (string): The ID of the collection. - `data` (object): An object containing the data for the resource to be created. - For sites: `{ name: string }` - For collections: `{ displayName: string, singularName: string }` - For items: `{ fieldData: object }` ### Request Example ```typescript // Create site (Enterprise only) const site = await webflow.sites.create(workspaceId, { name: "New Site" }); // Create collection const collection = await webflow.collections.create(siteId, { displayName: "Products", singularName: "Product" }); // Create item const item = await webflow.collections.items.create(siteId, collectionId, { fieldData: { name: "Product Name", price: 99.99 } }); ``` ``` -------------------------------- ### Create Webflow Resources Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/README.md Demonstrates how to create a site (Enterprise only), a collection, and an item within a collection using the Webflow API. ```typescript // Create site (Enterprise only) const site = await webflow.sites.create(workspaceId, { name: "New Site" }); // Create collection const collection = await webflow.collections.create(siteId, { displayName: "Products", singularName: "Product" }); // Create item const item = await webflow.collections.items.create(siteId, collectionId, { fieldData: { name: "Product Name", price: 99.99 } }); ``` -------------------------------- ### Get Single Collection Item Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/CollectionsClient.md Retrieves a single item from a specified collection by its ID. ```APIDOC ## Get Single Collection Item ### Description Retrieves a single item from a specified collection by its ID. ### Method GET ### Endpoint /sites/{siteId}/collections/{collectionId}/items/{itemId} ### Parameters #### Path Parameters - **siteId** (string) - Required - The ID of the site. - **collectionId** (string) - Required - The ID of the collection. - **itemId** (string) - Required - The ID of the item to retrieve. ### Response #### Success Response (200) - **item** (object) - The collection item object. ``` -------------------------------- ### client.scripts.list Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Get a list of scripts registered to a site. A site can have a maximum of 800 registered scripts. ```APIDOC ## GET /sites/{site_id}/scripts ### Description Retrieves a list of all scripts that have been registered to a specific site. Note that a site has a maximum limit of 800 registered scripts. ### Method GET ### Endpoint `/sites/{site_id}/scripts` ### Parameters #### Path Parameters - **site_id** (string) - Required - Unique identifier for a Site #### Query Parameters - **limit** (number) - Optional - The maximum number of scripts to return. - **offset** (number) - Optional - The number of scripts to skip. ### Request Example ```json { "example": "await client.scripts.list(\"580e63e98c9a982ac9b8b741\")" } ``` ### Response #### Success Response (200) - **scripts** (array) - An array of registered script objects. - **count** (number) - The total number of registered scripts. - **limit** (number) - The limit applied to the response. - **offset** (number) - The offset applied to the response. ``` -------------------------------- ### Import SitesClient Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/SitesClient.md Import the necessary types and initialize the sites client. This is the first step to using any sites-related functionality. ```typescript import type { WebflowClient } from "webflow-api"; const sites = webflowClient.sites; ``` -------------------------------- ### Delete Webflow Resources Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/README.md Provides examples for deleting assets, pages, and collection items from Webflow. ```typescript // Delete asset await webflow.assets.delete(siteId, assetId); // Delete page await webflow.pages.delete(siteId, pageId); // Delete item await webflow.collections.items.delete(siteId, collectionId, itemId); ``` -------------------------------- ### client.sites.forms.getSubmission Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Get information about a form submission within a specific site. Requires `forms:read` scope. ```APIDOC ## client.sites.forms.getSubmission ### Description Get information about a form submission within a specific site. Required scope | `forms:read` ### Method GET ### Endpoint /sites/{site_id}/forms/{form_submission_id} ### Parameters #### Path Parameters - **site_id** (string) - Required - Unique identifier for a Site - **form_submission_id** (string) - Required - Unique identifier for a Form Submission #### Request Body None ### Response #### Success Response (200) - **Webflow.FormSubmission** - Details of the form submission ### Request Example ```typescript await client.sites.forms.getSubmission("580e63e98c9a982ac9b8b741", "580e63e98c9a982ac9b8b741"); ``` ``` -------------------------------- ### Accessing Webflow Resources Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/WebflowClient.md Demonstrates how to access different resource clients like sites, collections, and pages using the Webflow client instance. Ensure the client is initialized before use. ```typescript // Access sites const sites = await webflow.sites.list(); // Access collections const collections = await webflow.collections.list(siteId); // Access specific resources const pages = await webflow.pages.list(siteId); ``` -------------------------------- ### Get Page Scripts Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Retrieves all scripts applied to a specific page. Requires 'custom_code:read' scope. ```typescript await client.pages.scripts.getCustomCode("63c720f9347c2139b248e552"); ``` -------------------------------- ### Get Ecommerce Settings Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Retrieve ecommerce settings for a specific site. Requires the 'ecommerce:read' scope. ```typescript await client.ecommerce.getSettings("580e63e98c9a982ac9b8b741"); ``` -------------------------------- ### client.components.list Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Lists all components for a given site. Supports filtering by branch and pagination. ```APIDOC ## client.components.list ### Description List of all components for a site. Required scope | `components:read` ### Parameters #### Path Parameters - **site_id** (string) - Required - Unique identifier for a Site #### Query Parameters - **request** (Webflow.ComponentsListRequest) - Optional - **requestOptions** (ComponentsClient.RequestOptions) - Optional ``` -------------------------------- ### Get Form Submission Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Retrieve information about a specific form submission. Requires `forms:read` scope. ```typescript await client.forms.getSubmission("580e63e98c9a982ac9b8b741"); ``` -------------------------------- ### Initialize Webflow Client and Use TypeScript Types Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/README.md Shows how to initialize the Webflow client and leverage TypeScript for type inference and type-safe operations on sites and collection items. ```typescript import { WebflowClient } from "webflow-api"; import type { Webflow } from "webflow-api"; const webflow = new WebflowClient({ accessToken }); // Full type inference const site: Webflow.Site = await webflow.sites.get(siteId); const items: Webflow.CollectionItem[] = (await webflow.collections.items.list(siteId, collectionId)).items; // Type-safe field operations interface BlogPost { title: string; content: string; publishDate: Date; } const post = await webflow.collections.items.create(siteId, collectionId, { fieldData: { title: "My Post", content: "Content here", publishDate: new Date() } as BlogPost }); ``` -------------------------------- ### Create Product Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/COMMON-OPERATIONS.md Creates a new product in the e-commerce store. Requires site ID and product details such as name, description, price, and image URL. ```APIDOC ## Create Product ### Description Creates a new product in the e-commerce store. Requires site ID and product details such as name, description, price, and image URL. ### Method `webflow.products.create(siteId, { name, description, price, image })` ### Parameters - **siteId** (string) - Required - The ID of the site. - **name** (string) - Required - The name of the product. - **description** (string) - Optional - The description of the product. - **price** (number) - Required - The price of the product. - **image** (string) - Optional - The URL of the product image. ``` -------------------------------- ### Get Current Inventory Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/COMMON-OPERATIONS.md Retrieves the current stock quantity for a specific product variant within a site. ```APIDOC ## Get Current Inventory ### Description Retrieves the current stock quantity for a specific product variant within a site. ### Method GET (implied by SDK method `webflow.inventory.get`) ### Endpoint `/sites/{siteId}/inventory/{variantId}` (inferred) ### Parameters #### Path Parameters - **siteId** (string) - Required - The ID of the site. - **variantId** (string) - Required - The ID of the product variant. ### Response #### Success Response (200) - **quantity** (number) - The current stock quantity. ``` -------------------------------- ### Create a New Product Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Use this snippet to create a new product with specified field data and SKU information. Ensure you have the correct site ID. ```typescript await client.products.create("580e63e98c9a982ac9b8b741", { publishStatus: "staging", product: { fieldData: { name: "Colorful T-shirt", slug: "colorful-t-shirt", description: "Our best-selling t-shirt available in multiple colors and sizes", skuProperties: [{ id: "color", name: "Color", "enum": [{ id: "red", name: "Red", slug: "red" }, { id: "yellow", name: "Yellow", slug: "yellow" }, { id: "blue", name: "Blue", slug: "blue" }] }, { id: "size", name: "Size", "enum": [{ id: "small", name: "Small", slug: "small" }, { id: "medium", name: "Medium", slug: "medium" }, { id: "large", name: "Large", slug: "large" }] }] } }, sku: { fieldData: { name: "Colorful T-shirt - Red Small", slug: "colorful-t-shirt-red-small", price: { value: 2499, unit: "USD", currency: "USD" }, mainImage: "https://rocketamp-sample-store.myshopify.com/cdn/shop/products/Gildan_2000_Antique_Cherry_Red_Front_1024x1024.jpg?v=1527232987" } } }); ``` -------------------------------- ### Get Webhook Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/WebhooksClient.md Retrieves a single webhook by its ID for a given site. Requires read access to sites. ```APIDOC ## get(siteId, webhookId, requestOptions?) ### Description Retrieves a single webhook by its ID for a given site. ### Method `get` ### Parameters #### Path Parameters - **siteId** (string) - Required - Unique identifier for the site. - **webhookId** (string) - Required - Unique identifier for the webhook. - **requestOptions** (RequestOptions) - Optional - Request-specific configuration. ### Returns `Promise` - The webhook object. ### Throws - `BadRequestError` (400) - Invalid ID format - `UnauthorizedError` (401) - Invalid or missing authentication - `NotFoundError` (404) - Site or webhook not found - `TooManyRequestsError` (429) - Rate limit exceeded ### Required Scope sites:read ### Example ```typescript const webhook = await webflow.webhooks.get( "580e63e98c9a982ac9b8b741", "63e80c68b7f6d40011dba84a" ); console.log(webhook.triggerType); console.log(webhook.url); ``` ``` -------------------------------- ### Example: Update Collection Field Source: https://github.com/webflow/js-webflow-api/blob/master/_autodocs/api-reference/AdditionalClients.md Demonstrates updating a collection field's display name and type. ```typescript await webflow.collections.fields.update(siteId, collectionId, fieldId, { displayName: "New Name", type: "PlainText" }); ``` -------------------------------- ### client.products.list Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Retrieves all products for a given site, including their SKUs. Supports pagination. Requires 'ecommerce:read' scope. ```APIDOC ## GET /sites/{site_id}/products ### Description Retrieves all products for a site, including their SKUs. Supports pagination using `limit` and `offset`. ### Method GET ### Endpoint /sites/{site_id}/products ### Parameters #### Path Parameters - **site_id** (string) - Required - Unique identifier for a Site #### Query Parameters - **request** (Webflow.ProductsListRequest) - Optional - Parameters for filtering and pagination (e.g., `limit`, `offset`). - **requestOptions** (ProductsClient.RequestOptions) - Optional ### Response #### Success Response (200) - **[Response Fields]** (Webflow.ProductAndSkUsList) - A list of products and their associated SKUs. ``` -------------------------------- ### Create a Product SKU Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Use this to create a new SKU for a product. Ensure you have the correct site and product IDs. The request body includes details for the new SKU. ```typescript await client.products.createSku("580e63e98c9a982ac9b8b741", "580e63fc8c9a982ac9b8b745", { skus: [{ id: "66072fb71b89448912e2681c", cmsLocaleId: "653ad57de882f528b32e810e", lastPublished: new Date("2023-03-17T18:47:35.000Z"), lastUpdated: new Date("2023-03-17T18:47:35.000Z"), createdOn: new Date("2023-03-17T18:47:35.000Z"), fieldData: { name: "Colorful T-shirt - Default", slug: "colorful-t-shirt-default", price: { value: 2499, unit: "USD", currency: "USD" } } }] }); ``` -------------------------------- ### client.workspaces.auditLogs.getWorkspaceAuditLogs Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Get audit logs for a workspace. Requires `workspace_activity:read` scope and an Enterprise workspace with a workspace token. ```APIDOC ## client.workspaces.auditLogs.getWorkspaceAuditLogs ### Description Get audit logs for a workspace. This endpoint requires an Enterprise workspace and a workspace token with the `workspace_activity:read` scope. Create a workspace token from your workspace dashboard integrations page to use this endpoint. Required scope | `workspace_activity:read` ### Method GET ### Endpoint /workspaces/{workspace_id_or_slug}/auditlogs ### Parameters #### Path Parameters - **workspace_id_or_slug** (string) - Required - Unique identifier or slug for a Workspace #### Query Parameters - **request** (Webflow.workspaces.AuditLogsGetWorkspaceAuditLogsRequest) - Required - Object containing query parameters for filtering audit logs. - **limit** (number) - Optional - The maximum number of audit logs to return. - **offset** (number) - Optional - The number of audit logs to skip. - **sortOrder** (string) - Optional - The order in which to sort the audit logs ('asc' or 'desc'). - **eventType** (string) - Optional - Filters logs by a specific event type. - **from** (Date) - Optional - Filters logs from a specific date and time. - **to** (Date) - Optional - Filters logs up to a specific date and time. #### Request Body None ### Response #### Success Response (200) - **Webflow.WorkspaceAuditLogResponse** - An object containing the audit logs and pagination information. ### Request Example ```typescript await client.workspaces.auditLogs.getWorkspaceAuditLogs("hitchhikers-workspace", { limit: 1, offset: 1, sortOrder: "asc", eventType: "user_access", from: new Date("2025-06-22T16:00:31.000Z"), to: new Date("2025-07-22T16:00:31.000Z") }); ``` ``` -------------------------------- ### Get a Form Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Retrieve information about a specific form using its unique ID. Requires 'forms:read' scope. ```typescript await client.forms.get("580e63e98c9a982ac9b8b741"); ``` -------------------------------- ### client.products.createSku Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Creates a SKU for a given product on a specific site. This operation requires the `ecommerce:write` scope. ```APIDOC ## POST /sites/{site_id}/products/{product_id}/skus ### Description Creates a SKU for a given product on a specific site. This operation requires the `ecommerce:write` scope. ### Method POST ### Endpoint /sites/{site_id}/products/{product_id}/skus ### Parameters #### Path Parameters - **site_id** (string) - Required - Unique identifier for a Site - **product_id** (string) - Required - Unique identifier for a Product #### Request Body - **request** (Webflow.ProductsCreateSkuRequest) - Required - **requestOptions** (ProductsClient.RequestOptions) - Optional ### Request Example ```json { "skus": [ { "id": "66072fb71b89448912e2681c", "cmsLocaleId": "653ad57de882f528b32e810e", "lastPublished": "2023-03-17T18:47:35.000Z", "lastUpdated": "2023-03-17T18:47:35.000Z", "createdOn": "2023-03-17T18:47:35.000Z", "fieldData": { "name": "Colorful T-shirt - Default", "slug": "colorful-t-shirt-default", "price": { "value": 2499, "unit": "USD", "currency": "USD" } } } ] } ``` ### Response #### Success Response (200) - **skus** (Webflow.Sku[]) - An array of created SKUs. ``` -------------------------------- ### WebflowClient Initialization Source: https://github.com/webflow/js-webflow-api/blob/master/README.md Instantiate the WebflowClient with an access token. This token can be a workspace token or a site token. ```APIDOC ## WebflowClient Initialization ### Description Instantiate the WebflowClient with an access token. This token can be a workspace token or a site token. ### Usage ```javascript import { WebflowClient } from "webflow-api"; // Workspace or site token const webflow = new WebflowClient({ accessToken: process.env.WEBFLOW_API_TOKEN, }); ``` ``` -------------------------------- ### Get a Webhook Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Retrieve a specific webhook instance using its unique ID. Requires 'sites:read' scope. ```typescript await client.webhooks.get("580e64008c9a982ac9b8b754"); ``` -------------------------------- ### Get Asset Folder Details Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Fetches the details of a specific asset folder. Requires 'assets:read' scope. ```typescript await client.assets.getFolder("6390c49774a71f0e3c1a08ee"); ``` -------------------------------- ### client.ecommerce.getSettings Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Retrieve ecommerce settings for a specific site. Requires 'ecommerce:read' scope. ```APIDOC ## client.ecommerce.getSettings(site_id) ### Description Retrieve ecommerce settings for a site. Required scope | `ecommerce:read` ### Method GET ### Endpoint /ecommerce/settings/{site_id} ### Parameters #### Path Parameters - **site_id** (string) - Required - Unique identifier for a Site #### Query Parameters - **requestOptions** (EcommerceClient.RequestOptions) - Optional - Options for the request. ### Request Example ```typescript await client.ecommerce.getSettings("580e63e98c9a982ac9b8b741"); ``` ### Response #### Success Response (200) - **Webflow.EcommerceSettings** - The ecommerce settings for the site. ``` -------------------------------- ### Run Test Suite Source: https://github.com/webflow/js-webflow-api/blob/master/CONTRIBUTING.md Run the entire test suite using yarn. ```bash yarn test ``` -------------------------------- ### client.components.getProperties Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Get the default property values of a component definition. If no localeId is included, properties from the Primary locale will be returned. ```APIDOC ## GET /sites/{site_id}/components/{component_id}/properties ### Description Retrieves the default property values for a given component definition. If a `localeId` is not specified, properties that can be localized from the Primary locale will be returned. ### Method GET ### Endpoint `/sites/{site_id}/components/{component_id}/properties` ### Parameters #### Path Parameters - **site_id** (string) - Required - Unique identifier for a Site - **component_id** (string) - Required - Unique identifier for a Component #### Query Parameters - **localeId** (string) - Optional - Identifier for the locale. - **branchId** (string) - Optional - Identifier for the branch. - **limit** (number) - Optional - The maximum number of properties to return. - **offset** (number) - Optional - The number of properties to skip. ### Request Example ```json { "example": "await client.components.getProperties(\"580e63e98c9a982ac9b8b741\", \"8505ba55-ef72-629e-f85c-33e4b703d48b\", { localeId: \"65427cf400e02b306eaa04a0\", branchId: \"68026fa68ef6dc744c75b833\", limit: 1, offset: 1 })" } ``` ### Response #### Success Response (200) - **properties** (array) - An array of property objects. - **count** (number) - The total number of properties available. - **limit** (number) - The limit applied to the response. - **offset** (number) - The offset applied to the response. ``` -------------------------------- ### Get Authorized User Information Source: https://github.com/webflow/js-webflow-api/blob/master/reference.md Retrieves information about the currently authorized user. Requires the `authorized_user:read` scope. ```typescript await client.token.authorizedBy(); ```