koalati/webflow-api-client
Composer 安装命令:
composer require koalati/webflow-api-client
包简介
An API client for Webflow's REST API. Manage sites, collections, ecommerce, members, and more.
README 文档
README
This package provides an API client for Webflow's REST API.
Work in progress
This package is still in the works.
The following issues must be completed before the API client can be considered complete and ready:
-
#1 feat: add models and module for CMS collections - #2 feat: add models and module for ecommerce
-
#3 feat: add models and module for sites -
#4 feat: add models and module for membership
If you would like to help, check out the Contributing section below, pick an issue and submit a pull request for it!
Requirements
This package requires PHP 8.1 or above.
Installation
To install, use composer:
composer require koalati/webflow-api-client
Getting started
1. Authenticate with Webflow
To quote Webflow's authentication documentation:
To access the API, you will need to provide an
access_tokento authenticate with Webflow. You can acquire that token in one of two ways.
- Utilize OAuth to allow your application’s users to authorize your app to access their Webflow account and data. [...]
- Issue a Site API Token that grants your application full access to your personal account. Check out our guide on Site API Tokens.
We recommend you opt for OAuth authentication. To set up the OAuth flow, we suggest you use our koalati/oauth2-webflow package.
If you prefer to use Webflow's Site API Token instead, follow the steps on their documentation page that is linked above to get your access token. Please note that you will likely get a more limited access to the API if you chose to go with the Site API Token.
Either way, make sure keep all access tokens secure (e.g. store them in an encrypted format).
2. Instanciate the API client with your access token
<?php 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);
3. Start interacting with the API!
// 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"; }
If you interact with a single website...
If you interact with a single Webflow site, you can use the SiteClient
instead of the basic Client to make your code a bit cleaner.
Both clients offer the exact same feature (Client is actually used internally
by the SiteClient), but it saves you from having to pass the site ID with
every call.
Here is an example:
<?php 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...
Usage
Pagination
Endpoints that are paginated will return a PaginatedList instance. This will
prevent you from making more API calls than you really need to.
The first page of results is always fetched to begin with. As you loop over the list, additional API calls will be made to load more data only when you actually get to that point.
$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. }
If you prefer to fetch all of the data at the beginning, you can use the
PaginatedList::fetchAll() method, which loads all of the data and returns it
as an array.
Ex.:
$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) { ... } } // }
Updating data
Models that can be updated via the API, such as Collection Items and Users, track their own changes: all you have to do to update them via their model instance and call their update endpoint with the model once you're ready.
Ex.:
$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.
Contributing
Please see CONTRIBUTING for details.
Credits
The core of this package was developed by Koalati, a QA platform for web developers and agencies.
Check out other contributors who helped maintain and make this package better: All Contributors.
License
The MIT License (MIT). Please see License File for more information.
koalati/webflow-api-client 适用场景与选型建议
koalati/webflow-api-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 128 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 02 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 koalati/webflow-api-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 koalati/webflow-api-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 128
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-21