PHP code example of koalati / webflow-api-client

1. Go to this page and download the library: Download koalati/webflow-api-client 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/ */

    

koalati / webflow-api-client example snippets




use Koalati\Webflow\Api\Client;

// Fetch your access token 
// @TODO: change this to get the token from where you stored it.
$accessToken = getenv("WEBFLOW_API_ACCESS_TOKEN");

// Instanciate the API client
$client = new Client($accessToken);

// Fetch the list of sites
$sites = $client->listSites();

// Fetch a specific site
$siteId = "6114382d5af6775b0abebe2c";
$specificSite = $client->getSite($siteId);

// Publish a site
$client->publishSite($siteId);

// List all collections for a site
$collections = $client->listCollections($siteId);

// Fetch and iterate over collection items
$items = $client->listCollectionItems($collections[0]);
foreach ($items as $item) {
	echo $item->name . "\n";
}



use Koalati\Webflow\Api\SiteClient;

// Fetch your access token 
// @TODO: change this to get the token from where you stored it.
$accessToken = getenv("WEBFLOW_API_ACCESS_TOKEN");

// Instanciate the API client
$client = new SiteClient($accessToken, "your-site-id");

$domains = $client->listDomains();
$collections = $client->listCollections();
// etc...

$items = $client->listCollectionItems('somecollectionid');

foreach ($items as $item) {
	// The first 100 items are already loaded.
	// Once you reach the 101st item, an API call will be made automatically to load the next batch.
	// Same thing one you reach the 201st item, and so on and so forth.
}

$itemList = $client->listCollectionItems('somecollectionid');
$itemsArray = $itemList->fetchAll();

var_dump($itemsArray);
// array(561) { 
//	[0]=> object(Koalati\Webflow\Model\CollectionItem)#1 (13) { ... } }
//	[1]=> object(Koalati\Webflow\Model\CollectionItem)#2 (13) { ... } }
//  ...
//	[559]=> object(Koalati\Webflow\Model\CollectionItem)#560 (13) { ... } }
//	[560]=> object(Koalati\Webflow\Model\CollectionItem)#561 (13) { ... } }
// }

$item = $client->getCollectionItem('somecollectionid', 'someitemid');

// Update the data on the model
$item->setFieldValue('name', 'My Updated Item Name');
$item->setFieldValue('some-custom-field', 'Another update value');

// Make the API call - changes you made will be automatically detected and sent
$updatedItem = $client->updateCollectionItem('somecollectionid', $item);

// $updatedItem now holds the updated version of the item, as returned by Webflow's API.