PHP code example of nicdev / webflow-sdk

1. Go to this page and download the library: Download nicdev/webflow-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nicdev / webflow-sdk example snippets


use Nicdev\WebflowSdk\Webflow;

$token = 'your-webflow-api-token';
$webflow = new Webflow($token);

$user = $webflow->user();

$authInfo = $webflow->authInfo();

$sites = $webflow->listSites();

$site = $webflow->getSite($siteId);

$webflow->publishSite($siteId);

$domains = $webflow->listDomains($siteId);

$webhooks = $webflow->listWebhooks($siteId);

$webhook = $webflow->getWebhook($siteId, $webhookId);

use Nicdev\WebflowSdk\Enums\WebhookTypes;

$triggerType = WebhookTypes::SITE_PUBLISH;
$url = 'https://your-webhook-url.com';
$filter = []; // Optional filter array

$webflow->createWebhook($siteId, $triggerType, $url, $filter);

$webflow->deleteWebhook($siteId, $webhookId);

$collections = $webflow->listCollections($siteId);

$collection = $webflow->fetchCollection($collectionId);

$page = 1; // Optional page number

$items = $webflow->listItems($collectionId, $page);

$fields = [
    'field-name' => 'field-value',
    // ...
];
$live = false; // Optional live mode

$item = $webflow->createItem($collectionId, $fields, $live);

$item = $webflow->getItem($collectionId, $itemId)

$itemIds = ['your-item-id', 'your-other-item-id'];
    
$webflow->publishItems($collection, $itemIds);

$fields = $fields = [
    'field-name' => 'field-value',
    // ...
];
$live = false; // Optional publish 

$webflow->updateItem($collectionId, $itemId, $fields, $live)

$fields = $fields = [
    'field-name' => 'field-value',
    // ...
];
$live = false; // Optional publish 

$webflow->updateItem($collectionId, $itemId, $fields, $live)

$live = true; // Optional. When set to true the item will be un-published but kept in the collection

$webflow->deleteItem($collectionId, $itemId, $live)

$page = 1; // Optional page number
$webflow->listProducts($siteId, $page);

$product = [
    'slug' = 'foo-bar',
    'name' => 'Foo Bar',
];
$sku = [
    'slug' => 'foo-bar-small',
    'name' => 'Foo Bar (S)',
    'price' => [
        'value' => 990,
        'unit' => 'USD'
    ]
]; // Optional
$webflow->createProductAndSku($siteId, $product, $sku)

$webflow->getProduct($site, $product);

$fields = [
    'name' => 'New Foo Bar',
    '_archived' => true
];

$webflow->updateProduct($siteId, $productId, $fields);

$sku = [
    'slug' => 'foo-bar-Medium',
    'name' => 'Foo Bar (M)',
    'price' => [
        'value' => 1190,
        'unit' => 'USD'
    ]
];
$webflow->createSku($siteId, $product, $sku);

$sku = [
    'slug' => 'foo-bar-Medium',
    'name' => 'Foo Bar (M) Discounted!!',
    'price' => [
        'value' => 1290,
        'unit' => 'USD'
    ]
];

$webflow->updateSku($siteId, $productId, $skuId, $sku);

$collectionId = 'your-collection-id'; //likely to be the SKUs collection.
$webflow->getInventory($collectionId, $skuId)

$fields = [
    'inventory_type' => 'infinite'
];

$webflow->updateInventory($collectionId, $skuId, $fields);

$page = 1; // Optional page number

$items = $webflow->listOrders($collectionId, $page);

$webflow->getOrdr($siteId, $orderId)

$fields = [
    'comment' => 'Adding a comment to this order'
];

$webflow->updateOrder$siteId, $orderId, $fields);

$notifyCustomer = true; // Optional, defaults to false

$webflow->fullfillOrder($siteId, $orderId, $notifyCustomer);

$webflow->unfulfillOrder($siteId, $orderId);

$webflow->refundOrder($siteId, $orderId);

$webflow->getEcommerceSettings($siteId);

use Nicdev\WebflowSdk\Webflow;

$token = 'your-webflow-api-token';
$webflow = new Webflow($token);

$sites = $webflow->sites; // [Site $site1, Site $site2...]
// or
$sites = $webflow->sites()->list(); // [Site $site1, Site $site2...]

$site = $webflow->sites($siteId) // Site $site;
// or
$site = $webflow->sites()->get($siteId) // Site $site;

$site->publish();

$webflow->sites($siteId)->domains();
// or
$webflow->sites($siteId)->domains;

$site->collections; // [Collection $collection1, Collection $collection2, ...]
// or
$site->collections(); // [Collection $collection1, Collection $collection2, ...]

$site->collections($collectionId) // Collection $collection;

$site->collections($collectionId)->items(); // [Item $item1, Item $item2, ...]
// or
$site->collections($collectionId)->items; // [Item $item1, Item $item2, ...]

$site->webhooks(); // [Webhook $webhook1, Webhook $webhook2, ...]
// or
$site->webhooks; // [Webhook $webhook1, Webhook $webhook2, ...]

$site->products(); // [Product $product1, Product $product2, ...]
// or
$site->products; // [Product $product1, Product $product2, ...]

$site->webhooks(); // [Order $order1, Order $order2, ...]
// or
$site->webhooks; // [Order $order1, Order $order2, ...]