### Clone Example Site and Install Dependencies Source: https://developers.webflow.com/data/v2.0.0/docs/working-with-custom-code Clone the example repository and install project dependencies using npm. ```bash $ git clone https://github.com/Webflow-Examples/custom-code-examples/tree/main $ cd custom-code-examples $ npm install $ npm run install-project ``` -------------------------------- ### Verify Node.js and npm versions Source: https://developers.webflow.com/data/v2.0.0/docs/ai-tools Checks the installed versions of Node.js and npm to confirm the setup is correct. ```bash node --version npm --version ``` -------------------------------- ### Example API Request to v2 Beta Source: https://developers.webflow.com/data/v2.0.0/reference/versioning Demonstrates how to make a GET request to the v2 beta API endpoint using cURL. Ensure you have the correct authentication headers. ```cURL curl --request GET \ --url https://api.webflow.com/beta/token/authorized_by \ --header 'accept: application/json' ``` -------------------------------- ### Get Comment Thread (PHP Guzzle) Source: https://developers.webflow.com/data/v2.0.0/reference/comments/get-comment-thread This PHP example uses the Guzzle HTTP client to fetch a comment thread. Ensure you have Guzzle installed via Composer. ```php request('GET', 'https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/comments/580e63e98c9a982ac9b8b741?localeId=65427cf400e02b306eaa04a0&offset=0&limit=100', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ``` -------------------------------- ### Clone Starter App and Install Dependencies Source: https://developers.webflow.com/data/v2.0.0/reference/rest-introduction/quick-start Clone the starter webflow-app-starter-v2 project and install its Node.js dependencies. ```bash git clone https://github.com/Webflow-Examples/webflow-app-starter-v2 cd webflow-app-starter-v2 npm install ``` -------------------------------- ### Initialize Node.js Server and Dependencies Source: https://developers.webflow.com/data/v2.0.0/reference/rest-introduction/quick-start Sets up a Fastify server with security headers and initializes a LevelDB database for storing access tokens. Requires environment variables for Webflow client ID and secret. ```javascript import { WebflowClient } from "webflow-api"; import Fastify from "fastify"; import fastifyStatic from "@fastify/static"; import path from "path"; import url from "url"; import { Level } from "level"; import fs from "fs/promises"; // Load environment variables from .env file const { WEBFLOW_CLIENT_ID, WEBFLOW_SECRET, PORT NODE_ENV = "development", } = process.env; // Validate required environment variables if (!WEBFLOW_CLIENT_ID || !WEBFLOW_SECRET) { console.error( "Missing required environment variables. Please check your .env file:" ); console.error("WEBFLOW_CLIENT_ID and WEBFLOW_SECRET are required"); process.exit(1); } // Initialize our server with basic security headers const server = Fastify({ logger: true, trustProxy: true, // Required for secure cookies behind a proxy }); // Add security headers server.addHook("onSend", async (request, reply) => { reply.headers({ "X-Content-Type-Options": "nosniff", // Prevent MIME type sniffing "X-Frame-Options": "DENY", // Prevent clickjacking "Strict-Transport-Security": "max-age=31536000; includeSubDomains", // Enforce HTTPS }); }); // Initialize the database (Note: Use a proper database in production) const db = new Level("data", { valueEncoding: "json" }); await db.open(); ``` -------------------------------- ### List Registered Scripts (PHP) Source: https://developers.webflow.com/data/v2.0.0/reference/custom-code/custom-code/list A PHP example using GuzzleHttp to interact with the Webflow API. It sends a GET request to retrieve registered scripts and echoes the response body. Make sure to install GuzzleHttp via Composer. ```php request('GET', 'https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/registered_scripts', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ``` -------------------------------- ### Create Live Item with Go SDK (Partial) Source: https://developers.webflow.com/data/v2.0.0/reference/cms/collection-items/live-items/create-item-live This Go code snippet shows the initial setup for making an HTTP request to create a live item. It defines the URL with query parameters. Further implementation for request body and headers would be needed. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.webflow.com/v2/collections/580e63fc8c9a982ac9b8b745/items/live?skipInvalidFiles=true" ``` -------------------------------- ### Get Site API Response Example Source: https://developers.webflow.com/data/v2.0.0/docs/working-with-localization Example response from the Get Site endpoint, showing the structure of primary and secondary locales, including their IDs and CMS locale IDs. ```json { "locales": { "primary": { "id": "653fd9af6a07fc9cfd7a5e57", "cmsLocaleId": "653ad57de882f528b32e810e", "tag": "en-US", ... }, "secondary": [ { "id": "653fd9af6a07fc9cfd7a5e56", "cmsLocaleId": "653fd9af6a07fc9cfd7a5e5d", "tag": "fr-FR", ... }, { "id": "654112a3a525b2739d97664c", "cmsLocaleId": "654112a3a525b2739d97664f", "tag": "es-MX", ... }, ... ] } } ``` -------------------------------- ### Get Asset Details (PHP) Source: https://developers.webflow.com/data/v2.0.0/reference/assets/assets/get Use GuzzleHttp in PHP to make a GET request to retrieve asset details. Ensure you have the GuzzleHttp library installed via Composer. ```php request('GET', 'https://api.webflow.com/v2/assets/580e63fc8c9a982ac9b8b745?localeId=65427cf400e02b306eaa04a0', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ``` -------------------------------- ### Start Development Server Source: https://developers.webflow.com/data/v2.0.0/docs/working-with-custom-code Run the development server for your Webflow App. ```bash $ npm run dev ``` -------------------------------- ### List Components via HTTP Request (Go) Source: https://developers.webflow.com/data/v2.0.0/reference/pages-and-components/components/list Make a direct HTTP GET request to the Webflow API to list components. This example shows how to set up the request, headers, and handle the response. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/components?branchId=68026fa68ef6dc744c75b833&limit=100&offset=0" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Get Asset Details (C#) Source: https://developers.webflow.com/data/v2.0.0/reference/assets/assets/get This C# example utilizes RestSharp to perform a GET request for asset details. Configure the client with the API endpoint and add the Authorization header. ```csharp using RestSharp; var client = new RestClient("https://api.webflow.com/v2/assets/580e63fc8c9a982ac9b8b745?localeId=65427cf400e02b306eaa04a0"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Get Asset Details (Go) Source: https://developers.webflow.com/data/v2.0.0/reference/assets/assets/get This Go example demonstrates how to make a GET request to the Webflow API to retrieve asset details. It includes setting the Authorization header with your token. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.webflow.com/v2/assets/580e63fc8c9a982ac9b8b745?localeId=65427cf400e02b306eaa04a0" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Start Python Server Source: https://developers.webflow.com/data/v2.0.0/reference/oauth-app Execute this command in your terminal to start your Python server. This is an alternative to starting a Node.js server. ```bash python app.py ``` -------------------------------- ### Get mcp-remote path Source: https://developers.webflow.com/data/v2.0.0/docs/ai-tools Finds the system path for the globally installed mcp-remote executable. ```bash which mcp-remote ``` -------------------------------- ### Create SKU Example Source: https://developers.webflow.com/data/v2.0.0/reference/ecommerce/products/create-sku This Swift code snippet demonstrates how to create a URL session and initiate a data task to send a request, likely for creating an SKU. It includes basic error handling and response logging. ```swift let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### List Asset Folders Response Example Source: https://developers.webflow.com/data/v2.0.0/reference/assets/asset-folders/list-folders An example of a successful response when listing asset folders, showing folder details and pagination information. ```json { "assetFolders": [ { "id": "580e6 e98c9a982ac9b8b742", "displayName": "Marketing Assets", "assets": [ "580e63e98c9a982ac9b8b743", "580e63e98c9a982ac9b8b744" ], "siteId": "580e63e98c9a982ac9b8b741", "createdOn": "2023-05-10T14:22:30.000Z", "lastUpdated": "2024-04-20T09:15:00.000Z" } ], "pagination": { "limit": 1, "offset": 0, "total": 1 } } ``` -------------------------------- ### Get Custom Code via HTTP Request (C#) Source: https://developers.webflow.com/data/v2.0.0/reference/custom-code/custom-code-pages/get-custom-code Example using RestSharp in C# to make a GET request to the Webflow API for custom code. The Authorization header is added to the request. ```csharp using RestSharp; var client = new RestClient("https://api.webflow.com/v2/pages/63c720f9347c2139b248e552/custom_code"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Get Custom Code via HTTP Request (Go) Source: https://developers.webflow.com/data/v2.0.0/reference/custom-code/custom-code-pages/get-custom-code Make a direct HTTP GET request to the Webflow API to fetch custom code. This example demonstrates setting the authorization header. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.webflow.com/v2/pages/63c720f9347c2139b248e552/custom_code" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Start Node.js Server Source: https://developers.webflow.com/data/v2.0.0/reference/oauth-app Execute this command in your terminal to start your Node.js server. Ensure your server is running before initiating the authorization flow. ```bash node server.js ``` -------------------------------- ### Get Page Metadata via HTTP Request (C#) Source: https://developers.webflow.com/data/v2.0.0/reference/pages-and-components/pages/get-metadata Retrieve page metadata using a direct HTTP GET request in C#. This example uses the RestSharp library to interact with the Webflow API. ```csharp using RestSharp; var client = new RestClient("https://api.webflow.com/v2/pages/63c720f9347c2139b248e552?localeId=65427cf400e02b306eaa04a0"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Update Product SDK Examples Source: https://developers.webflow.com/data/v2.0.0/reference/ecommerce/products/update Examples of how to update a product using the Webflow SDKs in TypeScript, Python, and Go. ```typescript import { WebflowClient } from "webflow-api"; async function main() { const client = new WebflowClient({ accessToken: "YOUR_TOKEN_HERE", }); await client.products.update("580e63e98c9a982ac9b8b741", "580e63fc8c9a982ac9b8b745", { fieldData: { "name": "Updated T-Shirt Name", "description": "An updated description for the t-shirt.", "shippable": false, "sku-properties": [ { "id": "31b77fa66fa376c2c0abb458d5be39fb", "name": "Size", "enum": [ { "id": "8d21a625d655ab260e9941c27180c75b", "name": "Small", "slug": "small" } ] } ] } }); } main(); ``` ```python from webflow import Webflow client = Webflow( access_token="YOUR_TOKEN_HERE", ) client.products.update( site_id="580e63e98c9a982ac9b8b741", product_id="580e63fc8c9a982ac9b8b745", data={ "fieldData": { "name": "Updated T-Shirt Name", "description": "An updated description for the t-shirt.", "shippable": False, "sku-properties": [ { "id": "31b77fa66fa376c2c0abb458d5be39fb", "name": "Size", "enum": [ { "id": "8d21a625d655ab260e9941c27180c75b", "name": "Small", "slug": "small" } ] } ] } } ) ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/products/580e63fc8c9a982ac9b8b745" payload := strings.NewReader(`{ "fieldData": { "name": "Updated T-Shirt Name", "description": "An updated description for the t-shirt.", "shippable": false, "sku-properties": [ { "id": "31b77fa66fa376c2c0abb458d5be39fb", "name": "Size", "enum": [ { "id": "8d21a625d655ab260e9941c27180c75b", "name": "Small", "slug": "small" } ] } ] } }`) // Note: In a real Go application, you would use a proper JSON marshalling library. req, err := http.NewRequest("PUT", url, payload) if err != nil { fmt.Println("Error creating request:", err) return } req.Header.Add("accept", "application/json") req.Header.Add("content-type", "application/json") // Add your authorization token here, e.g.: // req.Header.Add("authorization", "Bearer YOUR_TOKEN_HERE") client := &http.Client{} res, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer res.Body.Close() body, err := io.ReadAll(res.Body) if err != nil { fmt.Println("Error reading response body:", err) return } fmt.Println(string(body)) } ``` -------------------------------- ### Initialize Python Server Source: https://developers.webflow.com/data/v2.0.0/reference/oauth-app Sets up a Flask server for a Webflow application, loading environment variables and initializing the Webflow client. ```python from flask import Flask, request, redirect import requests from webflow import WebflowClient from dotenv import load_dotenv import os load_dotenv() app = Flask(__name__) client_id = os.getenv('CLIENT_ID') client_secret = os.getenv('CLIENT_SECRET') redirect_uri = os.getenv('REDIRECT_URI') state = os.getenv('STATE') # We'll add the necessary endpoints here in the steps below if __name__ == '__main__': app.run(port=3000) ``` -------------------------------- ### Get Page Metadata via HTTP Request (Java) Source: https://developers.webflow.com/data/v2.0.0/reference/pages-and-components/pages/get-metadata Retrieve page metadata using a direct HTTP GET request in Java. This example utilizes the Unirest library for making the API call. ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://api.webflow.com/v2/pages/63c720f9347c2139b248e552?localeId=65427cf400e02b306eaa04a0") .header("Authorization", "Bearer ") .asString(); ``` -------------------------------- ### Get Page Metadata via HTTP Request (Ruby) Source: https://developers.webflow.com/data/v2.0.0/reference/pages-and-components/pages/get-metadata This Ruby example demonstrates making an HTTP GET request to the Webflow API for page metadata. It includes setting the necessary authorization header. ```ruby require 'uri' require 'net/http' url = URI("https://api.webflow.com/v2/pages/63c720f9347c2139b248e552?localeId=65427cf400e02b306eaa04a0") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` -------------------------------- ### List Components via HTTP Request (Ruby) Source: https://developers.webflow.com/data/v2.0.0/reference/pages-and-components/components/list This Ruby example demonstrates how to perform an HTTP GET request to the Webflow API for listing components. It includes setting up the URL, headers, and processing the response. ```ruby require 'uri' require 'net/http' url = URI("https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/components?branchId=68026fa68ef6dc744c75b833&limit=100&offset=0") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` -------------------------------- ### List Site Components (Node.js) Source: https://developers.webflow.com/data/v2.0.0/docs/working-with-localization/localize-components Use the Webflow client library in Node.js to list all components on your site. Ensure you have initialized the client with your access token. ```javascript const client = new WebflowClient({ accessToken: "YOUR_ACCESS_TOKEN" }); const components = await client.components.list("YOUR_SITE_ID"); ``` -------------------------------- ### Get Node.js path with nvs Source: https://developers.webflow.com/data/v2.0.0/docs/ai-tools Retrieves the installation path for a specific Node.js version managed by nvs. ```bash nvs which 22.3.0 ``` -------------------------------- ### List Pages with Go HTTP Request Source: https://developers.webflow.com/data/v2.0.0/reference/pages-and-components/pages/list Make a direct HTTP GET request using Go to list pages. This example shows how to construct the URL, set the Authorization header, and handle the response. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/pages?localeId=65427cf400e02b306eaa04a0&limit=100&offset=0" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Example API Response for Get Sites Source: https://developers.webflow.com/data/v2.0.0/docs/data-clients/get-a-site-token This is an example of a successful response from the Webflow API when retrieving site information. It includes details like site ID, workspace ID, display name, and custom domains. ```json 1| { ---|--- 2| "id": "42e98c9a982ac9b8b742", 3| "workspaceId": "42e63e98c9a982ac9b8b742", 4| "displayName": "The Hitchhiker's Guide to the Galaxy", 5| "shortName": "hitchhikers-guide", 6| "previewUrl": "https://screenshots.webflow.com/sites/6258612d1ee792848f805dcf/20231219211811_d5990556c743f33b7071300a03bf67e6.png", 7| "timeZone": "Magrathea/FactoryFloor", 8| "createdOn": "1979-10-12T12:00:00.000Z", 9| "lastUpdated": "2023-04-02T12:42:00.000Z", 10| "lastPublished": "2023-04-02T12:42:00.000Z", 11| "parentFolderId": "1as2d3f4g5h6j7k8l9z0x1c2v3b4n5m6", 12| "customDomains": [ 13| { 14| "id": "589a331aa51e760df7ccb89d", 15| "url": "hitchhikersguide.galaxy" 16| }, 17| { 18| "id": "589a331aa51e760df7ccb89e", 19| "url": "heartofgold.spaceship" 20| } 21| ], 22| "locales": { 23| "value": { 24| "primary": { 25| "id": "653fd9af6a07fc9cfd7a5e57", 26| "cmsLocaleId": "653ad57de882f528b32e810e", 27| "enabled": false, 28| "displayName": "English (United States)", 29| "displayImageId": null, 30| "redirect": true, 31| "subdirectory": "", 32| "tag": "en-US" 33| }, 34| "secondary": [ 35| { 36| "id": "653fd9af6a07fc9cfd7a5e56", 37| "cmsLocaleId": "653fd9af6a07fc9cfd7a5e5d", 38| "enabled": true, 39| "displayName": "French (France)", 40| "displayImageId": null, 41| "subdirectory": "fr-fr", 42| "tag": "fr-FR" 43| }, 44| { 45| "id": "654112a3a525b2739d97664c", 46| "cmsLocaleId": "654112a3a525b2739d97664f", 47| "enabled": true, 48| "displayName": "Spanish (Mexico)", 49| "displayImageId": null, 50| "subdirectory": "es-mx", 51| "tag": "es-MX" 52| } 53| ] 54| } 55| } 56| } ``` -------------------------------- ### Create a Collection (Ruby) Source: https://developers.webflow.com/data/v2.0.0/docs/working-with-the-cms/manage-collections-and-items This Ruby example shows how to make a POST request to create a collection. It sets the necessary headers for authorization and content type. ```Ruby require 'uri' require 'net/http' url = URI("https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/collections") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"displayName\": \"Blog Posts\",\n \"singularName\": \"Blog Post\",\n \"slug\": \"posts\",\n \"fields\": [\n {\n \"isRequired\": true,\n \"type\": \"PlainText\",\n \"displayName\": \"Title\",\n \"helpText\": \"The title of the blog post\",\n \"slug\": \"title\"\n },\n {\n \"isRequired\": true,\n \"type\": \"RichText\",\n \"displayName\": \"Content\",\n \"helpText\": \"The content of the blog post\",\n \"slug\": \"content\"\n },\n {\n \"isRequired\": true,\n \"type\": \"Reference\",\n \"displayName\": \"Author\",\n \"helpText\": \"The author of the blog post\",\n \"metadata\": {\n \"collectionId\": \"23cc2d952d4e4631ffd4345d2743db4e\"\n },\n \"slug\": \"author\"\n }\n ]\n}" response = http.request(request) puts response.read_body ``` -------------------------------- ### Get Page Metadata via HTTP Request (Swift) Source: https://developers.webflow.com/data/v2.0.0/reference/pages-and-components/pages/get-metadata This Swift example shows how to make an HTTP GET request to the Webflow API to obtain page metadata. It includes setting up the URL request and headers. ```swift import Foundation let headers = ["Authorization": "Bearer "] let request = NSMutableURLRequest(url: NSURL(string: "https://api.webflow.com/v2/pages/63c720f9347c2139b248e552?localeId=65427cf400e02b306eaa04a0")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Initialize Node.js Server Source: https://developers.webflow.com/data/v2.0.0/reference/oauth-app Sets up an Express.js server for a Webflow application, loading environment variables and initializing the Webflow client. ```javascript require('dotenv').config(); const express = require('express'); const { WebflowClient } = require('webflow-api'); const app = express(); const port = 3000; /* We'll add the necessary endpoints here in the steps below. */ app.listen(port, () => { console.log(`Server is running at http://localhost:${port}`); }); ``` -------------------------------- ### Get Page Metadata via HTTP Request (Go) Source: https://developers.webflow.com/data/v2.0.0/reference/pages-and-components/pages/get-metadata Make a direct HTTP GET request to the Webflow API to retrieve page metadata. This example shows how to construct the request and handle the response in Go. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://api.webflow.com/v2/pages/63c720f9347c2139b248e552?localeId=65427cf400e02b306eaa04a0" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Create SKU using HTTP POST (Go) Source: https://developers.webflow.com/data/v2.0.0/reference/ecommerce/products/create-sku This Go program sends a POST request to create a SKU. It includes setting the Authorization header and Content-Type. Replace '' with your actual bearer token. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.webflow.com/v2/sites/580e63e98c9a982ac9b8b741/products/580e63fc8c9a982ac9b8b745/skus" payload := strings.NewReader("{\n \"skus\": [\n {}\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Fetch Workspace Audit Logs using Webflow Python Package Source: https://developers.webflow.com/data/v2.0.0/reference/authentication/workspace-token This Python example shows how to retrieve audit logs using the Webflow package. First, install it using 'pip install webflow'. Replace YOUR_ACCESS_TOKEN with your workspace token. ```python from webflow.client import Webflow import datetime # Initialize the Webflow client with your access token client = Webflow(access_token="YOUR_ACCESS_TOKEN") # Fetch the list of activity across your workspace # Note: The actual variable 'audit_logs' needs to be assigned the result of the call. # For example: audit_logs = client.workspaces.audit_logs.get_workspace_audit_logs(...) client.workspaces.audit_logs.get_workspace_audit_logs( workspace_id_or_slug="hitchhikers-workspace", from_=datetime.datetime.fromisoformat( "2024-04-22 16:00:31+00:00", ), to=datetime.datetime.fromisoformat( "2024-04-22 16:00:31+00:00", ), ) # Print the audit logs # print(audit_logs) # This line would require 'audit_logs' to be assigned. ``` -------------------------------- ### Create Live Item (Swift) Source: https://developers.webflow.com/data/v2.0.0/reference/cms/collection-items/live-items/create-item-live This Swift example shows how to construct and send a POST request to create a live item in Webflow. It includes setting up headers and the JSON body. ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "isArchived": false, "isDraft": false, "fieldData": [ "name": "The Hitchhiker's Guide to the Galaxy", "slug": "hitchhikers-guide-to-the-galaxy", "plain-text": "Don't Panic.", "rich-text": "

A Guide to Interstellar Travel

A towel is about the most massively useful thing an interstellar hitchhiker can have. Don't forget yours!

", "main-image": [ "fileId": "62b720ef280c7a7a3be8cabe", "url": "/files/62b720ef280c7a7a3be8cabe_image.png" ], "image-gallery": [ [ "fileId": "62b720ef280c7a7a3be8cabd", "url": "/files/62b720ef280c7a7a3be8cabd_image.png" ], [ "fileId": "62b720ef280c7a7a3be8cabe", "url": "/files/62b720ef280c7a7a3be8cabe_image.png" ] ], "intro-video": "https://www.youtube.com/watch?v=aJ83KAggd-4", "official-site": "https://hitchhikers.fandom.com/wiki/The_Hitchhiker%27s_Guide_to_the_Galaxy", "contact-email": "zaphod.beeblebrox@heartofgold.gov", "support-phone": "424-242-4242", "answer-to-everything": 42, "release-date": "1979-10-12T00:00:00.000Z", "is-featured": true, "brand-color": "#000000", "category": "62b720ef280c7a7a3be8cabf", "author": "62b720ef280c7a7a3be8cab0", "tags": ["62b720ef280c7a7a3be8cab1", "62b720ef280c7a7a3be8cab2"], "downloadable-asset": [ "fileId": "62b720ef280c7a7a3be8cab3", "url": "/files/62b720ef280c7a7a3be8cab3_document.pdf" ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.webflow.com/v2/collections/580e63fc8c9a982ac9b8b745/items/live?skipInvalidFiles=true")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Get E-commerce Settings (TypeScript SDK) Source: https://developers.webflow.com/data/v2.0.0/reference/ecommerce/settings/get-settings Use the Webflow SDK to retrieve e-commerce settings. Ensure you have the SDK installed and your access token is configured. ```typescript import { WebflowClient } from "webflow-api"; async function main() { const client = new WebflowClient({ accessToken: "YOUR_TOKEN_HERE", }); await client.ecommerce.getSettings("580e63e98c9a982ac9b8b741"); } main(); ``` -------------------------------- ### Create SKU Response Example Source: https://developers.webflow.com/data/v2.0.0/reference/ecommerce/products/create-sku This is an example of a successful response when creating a SKU. ```json { "skus": [ { "id": "580e63fc8c9a982ac9b8b745", "cmsLocaleId": "653ad57de882f528b32e810e", "lastPublished": "2023-03-17T18:47:35.560Z", "lastUpdated": "2023-03-17T18:47:35.560Z", "createdOn": "2023-03-17T18:47:35.560Z", "fieldData": { "name": "Blue T-shirt", "slug": "t-shirt-blue", "price": { "value": 2499, "unit": "USD", "currency": "USD" }, "sku-values": { "color": "blue", "size": "small" }, "compare-at-price": { "value": 100, "unit": "USD" }, "ec-sku-billing-method": "one-time", "ec-sku-subscription-plan": { "interval": "day", "frequency": 1, "trial": 7, "plans": [ { "platform": "stripe", "id": "string", "status": "active" } ] }, "main-image": "https://www.example.com/image.jpg", "sku": "1234567890", "sku-properties": [ { "id": "Color", "name": "Color", "enum": [ { "id": "royal-blue", "name": "Royal Blue", "slug": "royal-blue" } ] } ] } } ] } ``` -------------------------------- ### Install ngrok Source: https://developers.webflow.com/data/v2.0.0/reference/oauth-app Instructions for installing ngrok using Homebrew or Chocolatey package managers. ```shell brew install ngrok/ngrok/ngrok ``` ```shell choco install ngrok ```