Skip to content

Repository files navigation

Webflow Data API SDK

Installation

Using npm:

$ npm install webflow-api

Using yarn

$ yarn add webflow-api

Usage

The constructor takes in a few optional parameters to initialize the API client

  • token - the access token to use
  • headers - additional headers to add to the request
  • version - the version of the API you wish to use
constWebflow=require("webflow-api");// initialize the client with the access tokenconstwebflow=newWebflow({token: "[ACCESS TOKEN]"});// fully loadedconstwebflow=newWebflow({token: "[ACCESS TOKEN]",version: "1.0.0",headers: {"User-Agent": "My Webflow App / 1.0",},});

Transitioning to API v2

We're actively working on a new version of the SDK that will fully support API v2. In the meantime, to make use of API v2 with our SDK, there are some important changes you need to be aware of:

Setting Up For API v2

When initializing your client, it's crucial to set the beta flag to true in the client options. This ensures you're targeting the API v2 endpoints.

constwebflow=newWebflow({beta: true, ...otherOptions});

Please note, when the beta flag is set, several built-in methods will not be available. These methods include, but are not limited to, info, authenticatedUser, sites, site, etc. Attempting to use these will throw an error.

Calling API v2 Endpoints

To interact with API v2, you'll need to move away from using built-in methods, and instead use the provided HTTP methods directly.

For instance, where you previously used sites():

// get the first siteconst[site]=awaitwebflow.sites();

For API v2, you will need to use direct HTTP methods:

// get the first siteconstsites=awaitwebflow.get("/sites");constsite=sites[0];

We understand that this is a shift in how you interact with the SDK, but rest assured, our upcoming SDK version will streamline this process and offer a more integrated experience with API v2.

Basic Usage

Chaining Calls

You can retrieve child resources by chaining calls on the parent object.

// get the first siteconst[site]=awaitwebflow.sites();// get the first collection in the siteconst[collection]=awaitsite.collections();// get the first item in the collectionconst[item]=awaitcollection.items();// get one item from the collectionconstitem=awaitcollection.items({itemId: "[ITEM ID]"});

Pagination

To paginate results, pass in the limit and offset options.

// Get the first page of resultsconstpage1=awaitcollection.items({limit: 20});// Get the second page of resultsconstpage2=awaitcollection.items({limit: 20,offset: 20});

Rate Limit

Check rate limit status on each call by checking the _meta property.

// make an api callconstsite=awaitwebflow.site({siteId: "[SITE ID]"});// check rate limitconst{ rateLimit }=site._meta;// { limit: 60, remaining: 56 }

Update Token

If you need to update the access token, you can set the token property at any time.

// token is unsetconstwebflow=newWebflow();// set tokenwebflow.token="[ACCESS TOKEN]";// remove the tokenwebflow.clearToken();

Calling APIs Directly

All Webflow API endpoints can be called directly using the get, post, put, and delete methods.

// call the sites endpoint directlyconstsites=awaitwebflow.get("/sites");// post to an endpoint directlyconstresult=awaitwebflow.post("/sites/[SITE ID]/publish",{domains: ["hello-webflow.com"],});

OAuth

To implement OAuth, you'll need a Webflow App registered and a webserver running, that is publicly facing.

Authorize

The first step in OAuth is to generate an authorization url to redirect the user to.

// Get the authorization url to redirect users toconsturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",state: "1234567890",// optionalredirect_uri: "https://my.server.com/oauth/callback",// optional});// redirect user from your server routeres.redirect(url);

Using the scopes Parameter with v2 API

The v2 API introduces the concept of 'scopes', providing more control over app permissions. Instead of using the scope parameter as a single string, you can define multiple permissions using the scopes array:

consturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",redirect_uri: "https://my.server.com/oauth/callback",scopes: ["read:sites","write:items","read:users"],});

For more information and a detailed list of available scopes, refer to our Scopes Guide.

Access Token

Once a user has authorized their Webflow resource(s), Webflow will redirect back to your server with a code. Use this to get an access token.

constauth=awaitwebflow.accessToken({
client_id,
client_secret,
code,
redirect_uri,// optional - required if used in the authorize step});// you now have the user's access token to make API requests withconstuserWF=newWebflow({token: auth.access_token});// pull information for the userconstauthenticatedUser=awaituserWF.authenticatedUser();

Revoke Token

If the user decides to disconnect from your server, you should call revoke token to remove the authorization.

constresult=awaitwebflow.revokeToken({
client_id,
client_secret,
access_token,});// ensure it went throughresult.didRevoke===true;

Examples

Sites

Get all sites available or lookup by site id.

// List all sitesconstsites=awaitwebflow.sites();// Get a single siteconstsite=awaitwebflow.site({siteId: "[SITE ID]"});

Collections

Get all collections available for a site or lookup by collection id.

// Get a site's collection from the siteconstcollections=awaitsite.collections();// Get a site's collection by passing in a site idconstcollections=awaitwebflow.collections({siteId: "[SITE ID]"});// Get a single collectionconstcollection=awaitwebflow.collection({collectionId: "[COLLECTION ID]"});

Collection Items

Get all collection items available for a collection or lookup by item id.

// Get the items from a collectionconstitems=awaitcollection.items();// Get a subset of itemsconstitems=awaitcollection.items({limit: 10,offset: 2});// Get a single itemconstitem=awaitwebflow.item({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]"});

Update an Item

// Set the fields to updateconstfields={name: "New Name",_archived: false,_draft: false,slug: "new-name",};// call updateconstupdatedItem=awaitwebflow.updateItem({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]",
fields,});

Memberships

// Get a site's users from the siteconstusers=awaitsite.users();// Get a site's users with a site idconstusers=awaitwebflow.users({siteId: "[SITE ID]",});// Get a single userconstuser=awaitsite.user({siteId: "[SITE ID]",userId: "[USER ID]",});// Get a site's access groupsconstaccessGroups=awaitsite.accessGroups();// Get a site's access groups with a site idconstaccessGroups=awaitwebflow.accessGroups({siteId: "[SITE ID]",});

Webhooks

// get webhooks for a siteconstwebhooks=awaitsite.webhooks();// create a webhookconstwebhook=awaitsite.createWebhook({triggerType: "form_submission",url: "https://webhook.site",});

Authenticated User

// pull information for the authenticated userconstauthenticatedUser=awaitwebflow.authenticatedUser();

Contributing

Contributions are welcome - feel free to open an issue or pull request.

License

The MIT license - see LICENSE.

About

Node.js SDK for the Webflow Data API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
GitHub - cernak/js-webflow-api: Node.js SDK for the Webflow Data API · GitHub
Skip to content

Repository files navigation

Webflow Data API SDK

Installation

Using npm:

$ npm install webflow-api

Using yarn

$ yarn add webflow-api

Usage

The constructor takes in a few optional parameters to initialize the API client

  • token - the access token to use
  • headers - additional headers to add to the request
  • version - the version of the API you wish to use
constWebflow=require("webflow-api");// initialize the client with the access tokenconstwebflow=newWebflow({token: "[ACCESS TOKEN]"});// fully loadedconstwebflow=newWebflow({token: "[ACCESS TOKEN]",version: "1.0.0",headers: {"User-Agent": "My Webflow App / 1.0",},});

Transitioning to API v2

We're actively working on a new version of the SDK that will fully support API v2. In the meantime, to make use of API v2 with our SDK, there are some important changes you need to be aware of:

Setting Up For API v2

When initializing your client, it's crucial to set the beta flag to true in the client options. This ensures you're targeting the API v2 endpoints.

constwebflow=newWebflow({beta: true, ...otherOptions});

Please note, when the beta flag is set, several built-in methods will not be available. These methods include, but are not limited to, info, authenticatedUser, sites, site, etc. Attempting to use these will throw an error.

Calling API v2 Endpoints

To interact with API v2, you'll need to move away from using built-in methods, and instead use the provided HTTP methods directly.

For instance, where you previously used sites():

// get the first siteconst[site]=awaitwebflow.sites();

For API v2, you will need to use direct HTTP methods:

// get the first siteconstsites=awaitwebflow.get("/sites");constsite=sites[0];

We understand that this is a shift in how you interact with the SDK, but rest assured, our upcoming SDK version will streamline this process and offer a more integrated experience with API v2.

Basic Usage

Chaining Calls

You can retrieve child resources by chaining calls on the parent object.

// get the first siteconst[site]=awaitwebflow.sites();// get the first collection in the siteconst[collection]=awaitsite.collections();// get the first item in the collectionconst[item]=awaitcollection.items();// get one item from the collectionconstitem=awaitcollection.items({itemId: "[ITEM ID]"});

Pagination

To paginate results, pass in the limit and offset options.

// Get the first page of resultsconstpage1=awaitcollection.items({limit: 20});// Get the second page of resultsconstpage2=awaitcollection.items({limit: 20,offset: 20});

Rate Limit

Check rate limit status on each call by checking the _meta property.

// make an api callconstsite=awaitwebflow.site({siteId: "[SITE ID]"});// check rate limitconst{ rateLimit }=site._meta;// { limit: 60, remaining: 56 }

Update Token

If you need to update the access token, you can set the token property at any time.

// token is unsetconstwebflow=newWebflow();// set tokenwebflow.token="[ACCESS TOKEN]";// remove the tokenwebflow.clearToken();

Calling APIs Directly

All Webflow API endpoints can be called directly using the get, post, put, and delete methods.

// call the sites endpoint directlyconstsites=awaitwebflow.get("/sites");// post to an endpoint directlyconstresult=awaitwebflow.post("/sites/[SITE ID]/publish",{domains: ["hello-webflow.com"],});

OAuth

To implement OAuth, you'll need a Webflow App registered and a webserver running, that is publicly facing.

Authorize

The first step in OAuth is to generate an authorization url to redirect the user to.

// Get the authorization url to redirect users toconsturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",state: "1234567890",// optionalredirect_uri: "https://my.server.com/oauth/callback",// optional});// redirect user from your server routeres.redirect(url);

Using the scopes Parameter with v2 API

The v2 API introduces the concept of 'scopes', providing more control over app permissions. Instead of using the scope parameter as a single string, you can define multiple permissions using the scopes array:

consturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",redirect_uri: "https://my.server.com/oauth/callback",scopes: ["read:sites","write:items","read:users"],});

For more information and a detailed list of available scopes, refer to our Scopes Guide.

Access Token

Once a user has authorized their Webflow resource(s), Webflow will redirect back to your server with a code. Use this to get an access token.

constauth=awaitwebflow.accessToken({
client_id,
client_secret,
code,
redirect_uri,// optional - required if used in the authorize step});// you now have the user's access token to make API requests withconstuserWF=newWebflow({token: auth.access_token});// pull information for the userconstauthenticatedUser=awaituserWF.authenticatedUser();

Revoke Token

If the user decides to disconnect from your server, you should call revoke token to remove the authorization.

constresult=awaitwebflow.revokeToken({
client_id,
client_secret,
access_token,});// ensure it went throughresult.didRevoke===true;

Examples

Sites

Get all sites available or lookup by site id.

// List all sitesconstsites=awaitwebflow.sites();// Get a single siteconstsite=awaitwebflow.site({siteId: "[SITE ID]"});

Collections

Get all collections available for a site or lookup by collection id.

// Get a site's collection from the siteconstcollections=awaitsite.collections();// Get a site's collection by passing in a site idconstcollections=awaitwebflow.collections({siteId: "[SITE ID]"});// Get a single collectionconstcollection=awaitwebflow.collection({collectionId: "[COLLECTION ID]"});

Collection Items

Get all collection items available for a collection or lookup by item id.

// Get the items from a collectionconstitems=awaitcollection.items();// Get a subset of itemsconstitems=awaitcollection.items({limit: 10,offset: 2});// Get a single itemconstitem=awaitwebflow.item({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]"});

Update an Item

// Set the fields to updateconstfields={name: "New Name",_archived: false,_draft: false,slug: "new-name",};// call updateconstupdatedItem=awaitwebflow.updateItem({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]",
fields,});

Memberships

// Get a site's users from the siteconstusers=awaitsite.users();// Get a site's users with a site idconstusers=awaitwebflow.users({siteId: "[SITE ID]",});// Get a single userconstuser=awaitsite.user({siteId: "[SITE ID]",userId: "[USER ID]",});// Get a site's access groupsconstaccessGroups=awaitsite.accessGroups();// Get a site's access groups with a site idconstaccessGroups=awaitwebflow.accessGroups({siteId: "[SITE ID]",});

Webhooks

// get webhooks for a siteconstwebhooks=awaitsite.webhooks();// create a webhookconstwebhook=awaitsite.createWebhook({triggerType: "form_submission",url: "https://webhook.site",});

Authenticated User

// pull information for the authenticated userconstauthenticatedUser=awaitwebflow.authenticatedUser();

Contributing

Contributions are welcome - feel free to open an issue or pull request.

License

The MIT license - see LICENSE.

About

Node.js SDK for the Webflow Data API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - cernak/js-webflow-api: Node.js SDK for the Webflow Data API · GitHub
Skip to content

Repository files navigation

Webflow Data API SDK

Installation

Using npm:

$ npm install webflow-api

Using yarn

$ yarn add webflow-api

Usage

The constructor takes in a few optional parameters to initialize the API client

  • token - the access token to use
  • headers - additional headers to add to the request
  • version - the version of the API you wish to use
constWebflow=require("webflow-api");// initialize the client with the access tokenconstwebflow=newWebflow({token: "[ACCESS TOKEN]"});// fully loadedconstwebflow=newWebflow({token: "[ACCESS TOKEN]",version: "1.0.0",headers: {"User-Agent": "My Webflow App / 1.0",},});

Transitioning to API v2

We're actively working on a new version of the SDK that will fully support API v2. In the meantime, to make use of API v2 with our SDK, there are some important changes you need to be aware of:

Setting Up For API v2

When initializing your client, it's crucial to set the beta flag to true in the client options. This ensures you're targeting the API v2 endpoints.

constwebflow=newWebflow({beta: true, ...otherOptions});

Please note, when the beta flag is set, several built-in methods will not be available. These methods include, but are not limited to, info, authenticatedUser, sites, site, etc. Attempting to use these will throw an error.

Calling API v2 Endpoints

To interact with API v2, you'll need to move away from using built-in methods, and instead use the provided HTTP methods directly.

For instance, where you previously used sites():

// get the first siteconst[site]=awaitwebflow.sites();

For API v2, you will need to use direct HTTP methods:

// get the first siteconstsites=awaitwebflow.get("/sites");constsite=sites[0];

We understand that this is a shift in how you interact with the SDK, but rest assured, our upcoming SDK version will streamline this process and offer a more integrated experience with API v2.

Basic Usage

Chaining Calls

You can retrieve child resources by chaining calls on the parent object.

// get the first siteconst[site]=awaitwebflow.sites();// get the first collection in the siteconst[collection]=awaitsite.collections();// get the first item in the collectionconst[item]=awaitcollection.items();// get one item from the collectionconstitem=awaitcollection.items({itemId: "[ITEM ID]"});

Pagination

To paginate results, pass in the limit and offset options.

// Get the first page of resultsconstpage1=awaitcollection.items({limit: 20});// Get the second page of resultsconstpage2=awaitcollection.items({limit: 20,offset: 20});

Rate Limit

Check rate limit status on each call by checking the _meta property.

// make an api callconstsite=awaitwebflow.site({siteId: "[SITE ID]"});// check rate limitconst{ rateLimit }=site._meta;// { limit: 60, remaining: 56 }

Update Token

If you need to update the access token, you can set the token property at any time.

// token is unsetconstwebflow=newWebflow();// set tokenwebflow.token="[ACCESS TOKEN]";// remove the tokenwebflow.clearToken();

Calling APIs Directly

All Webflow API endpoints can be called directly using the get, post, put, and delete methods.

// call the sites endpoint directlyconstsites=awaitwebflow.get("/sites");// post to an endpoint directlyconstresult=awaitwebflow.post("/sites/[SITE ID]/publish",{domains: ["hello-webflow.com"],});

OAuth

To implement OAuth, you'll need a Webflow App registered and a webserver running, that is publicly facing.

Authorize

The first step in OAuth is to generate an authorization url to redirect the user to.

// Get the authorization url to redirect users toconsturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",state: "1234567890",// optionalredirect_uri: "https://my.server.com/oauth/callback",// optional});// redirect user from your server routeres.redirect(url);

Using the scopes Parameter with v2 API

The v2 API introduces the concept of 'scopes', providing more control over app permissions. Instead of using the scope parameter as a single string, you can define multiple permissions using the scopes array:

consturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",redirect_uri: "https://my.server.com/oauth/callback",scopes: ["read:sites","write:items","read:users"],});

For more information and a detailed list of available scopes, refer to our Scopes Guide.

Access Token

Once a user has authorized their Webflow resource(s), Webflow will redirect back to your server with a code. Use this to get an access token.

constauth=awaitwebflow.accessToken({
client_id,
client_secret,
code,
redirect_uri,// optional - required if used in the authorize step});// you now have the user's access token to make API requests withconstuserWF=newWebflow({token: auth.access_token});// pull information for the userconstauthenticatedUser=awaituserWF.authenticatedUser();

Revoke Token

If the user decides to disconnect from your server, you should call revoke token to remove the authorization.

constresult=awaitwebflow.revokeToken({
client_id,
client_secret,
access_token,});// ensure it went throughresult.didRevoke===true;

Examples

Sites

Get all sites available or lookup by site id.

// List all sitesconstsites=awaitwebflow.sites();// Get a single siteconstsite=awaitwebflow.site({siteId: "[SITE ID]"});

Collections

Get all collections available for a site or lookup by collection id.

// Get a site's collection from the siteconstcollections=awaitsite.collections();// Get a site's collection by passing in a site idconstcollections=awaitwebflow.collections({siteId: "[SITE ID]"});// Get a single collectionconstcollection=awaitwebflow.collection({collectionId: "[COLLECTION ID]"});

Collection Items

Get all collection items available for a collection or lookup by item id.

// Get the items from a collectionconstitems=awaitcollection.items();// Get a subset of itemsconstitems=awaitcollection.items({limit: 10,offset: 2});// Get a single itemconstitem=awaitwebflow.item({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]"});

Update an Item

// Set the fields to updateconstfields={name: "New Name",_archived: false,_draft: false,slug: "new-name",};// call updateconstupdatedItem=awaitwebflow.updateItem({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]",
fields,});

Memberships

// Get a site's users from the siteconstusers=awaitsite.users();// Get a site's users with a site idconstusers=awaitwebflow.users({siteId: "[SITE ID]",});// Get a single userconstuser=awaitsite.user({siteId: "[SITE ID]",userId: "[USER ID]",});// Get a site's access groupsconstaccessGroups=awaitsite.accessGroups();// Get a site's access groups with a site idconstaccessGroups=awaitwebflow.accessGroups({siteId: "[SITE ID]",});

Webhooks

// get webhooks for a siteconstwebhooks=awaitsite.webhooks();// create a webhookconstwebhook=awaitsite.createWebhook({triggerType: "form_submission",url: "https://webhook.site",});

Authenticated User

// pull information for the authenticated userconstauthenticatedUser=awaitwebflow.authenticatedUser();

Contributing

Contributions are welcome - feel free to open an issue or pull request.

License

The MIT license - see LICENSE.

About

Node.js SDK for the Webflow Data API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - cernak/js-webflow-api: Node.js SDK for the Webflow Data API · GitHub
Skip to content

Repository files navigation

Webflow Data API SDK

Installation

Using npm:

$ npm install webflow-api

Using yarn

$ yarn add webflow-api

Usage

The constructor takes in a few optional parameters to initialize the API client

  • token - the access token to use
  • headers - additional headers to add to the request
  • version - the version of the API you wish to use
constWebflow=require("webflow-api");// initialize the client with the access tokenconstwebflow=newWebflow({token: "[ACCESS TOKEN]"});// fully loadedconstwebflow=newWebflow({token: "[ACCESS TOKEN]",version: "1.0.0",headers: {"User-Agent": "My Webflow App / 1.0",},});

Transitioning to API v2

We're actively working on a new version of the SDK that will fully support API v2. In the meantime, to make use of API v2 with our SDK, there are some important changes you need to be aware of:

Setting Up For API v2

When initializing your client, it's crucial to set the beta flag to true in the client options. This ensures you're targeting the API v2 endpoints.

constwebflow=newWebflow({beta: true, ...otherOptions});

Please note, when the beta flag is set, several built-in methods will not be available. These methods include, but are not limited to, info, authenticatedUser, sites, site, etc. Attempting to use these will throw an error.

Calling API v2 Endpoints

To interact with API v2, you'll need to move away from using built-in methods, and instead use the provided HTTP methods directly.

For instance, where you previously used sites():

// get the first siteconst[site]=awaitwebflow.sites();

For API v2, you will need to use direct HTTP methods:

// get the first siteconstsites=awaitwebflow.get("/sites");constsite=sites[0];

We understand that this is a shift in how you interact with the SDK, but rest assured, our upcoming SDK version will streamline this process and offer a more integrated experience with API v2.

Basic Usage

Chaining Calls

You can retrieve child resources by chaining calls on the parent object.

// get the first siteconst[site]=awaitwebflow.sites();// get the first collection in the siteconst[collection]=awaitsite.collections();// get the first item in the collectionconst[item]=awaitcollection.items();// get one item from the collectionconstitem=awaitcollection.items({itemId: "[ITEM ID]"});

Pagination

To paginate results, pass in the limit and offset options.

// Get the first page of resultsconstpage1=awaitcollection.items({limit: 20});// Get the second page of resultsconstpage2=awaitcollection.items({limit: 20,offset: 20});

Rate Limit

Check rate limit status on each call by checking the _meta property.

// make an api callconstsite=awaitwebflow.site({siteId: "[SITE ID]"});// check rate limitconst{ rateLimit }=site._meta;// { limit: 60, remaining: 56 }

Update Token

If you need to update the access token, you can set the token property at any time.

// token is unsetconstwebflow=newWebflow();// set tokenwebflow.token="[ACCESS TOKEN]";// remove the tokenwebflow.clearToken();

Calling APIs Directly

All Webflow API endpoints can be called directly using the get, post, put, and delete methods.

// call the sites endpoint directlyconstsites=awaitwebflow.get("/sites");// post to an endpoint directlyconstresult=awaitwebflow.post("/sites/[SITE ID]/publish",{domains: ["hello-webflow.com"],});

OAuth

To implement OAuth, you'll need a Webflow App registered and a webserver running, that is publicly facing.

Authorize

The first step in OAuth is to generate an authorization url to redirect the user to.

// Get the authorization url to redirect users toconsturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",state: "1234567890",// optionalredirect_uri: "https://my.server.com/oauth/callback",// optional});// redirect user from your server routeres.redirect(url);

Using the scopes Parameter with v2 API

The v2 API introduces the concept of 'scopes', providing more control over app permissions. Instead of using the scope parameter as a single string, you can define multiple permissions using the scopes array:

consturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",redirect_uri: "https://my.server.com/oauth/callback",scopes: ["read:sites","write:items","read:users"],});

For more information and a detailed list of available scopes, refer to our Scopes Guide.

Access Token

Once a user has authorized their Webflow resource(s), Webflow will redirect back to your server with a code. Use this to get an access token.

constauth=awaitwebflow.accessToken({
client_id,
client_secret,
code,
redirect_uri,// optional - required if used in the authorize step});// you now have the user's access token to make API requests withconstuserWF=newWebflow({token: auth.access_token});// pull information for the userconstauthenticatedUser=awaituserWF.authenticatedUser();

Revoke Token

If the user decides to disconnect from your server, you should call revoke token to remove the authorization.

constresult=awaitwebflow.revokeToken({
client_id,
client_secret,
access_token,});// ensure it went throughresult.didRevoke===true;

Examples

Sites

Get all sites available or lookup by site id.

// List all sitesconstsites=awaitwebflow.sites();// Get a single siteconstsite=awaitwebflow.site({siteId: "[SITE ID]"});

Collections

Get all collections available for a site or lookup by collection id.

// Get a site's collection from the siteconstcollections=awaitsite.collections();// Get a site's collection by passing in a site idconstcollections=awaitwebflow.collections({siteId: "[SITE ID]"});// Get a single collectionconstcollection=awaitwebflow.collection({collectionId: "[COLLECTION ID]"});

Collection Items

Get all collection items available for a collection or lookup by item id.

// Get the items from a collectionconstitems=awaitcollection.items();// Get a subset of itemsconstitems=awaitcollection.items({limit: 10,offset: 2});// Get a single itemconstitem=awaitwebflow.item({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]"});

Update an Item

// Set the fields to updateconstfields={name: "New Name",_archived: false,_draft: false,slug: "new-name",};// call updateconstupdatedItem=awaitwebflow.updateItem({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]",
fields,});

Memberships

// Get a site's users from the siteconstusers=awaitsite.users();// Get a site's users with a site idconstusers=awaitwebflow.users({siteId: "[SITE ID]",});// Get a single userconstuser=awaitsite.user({siteId: "[SITE ID]",userId: "[USER ID]",});// Get a site's access groupsconstaccessGroups=awaitsite.accessGroups();// Get a site's access groups with a site idconstaccessGroups=awaitwebflow.accessGroups({siteId: "[SITE ID]",});

Webhooks

// get webhooks for a siteconstwebhooks=awaitsite.webhooks();// create a webhookconstwebhook=awaitsite.createWebhook({triggerType: "form_submission",url: "https://webhook.site",});

Authenticated User

// pull information for the authenticated userconstauthenticatedUser=awaitwebflow.authenticatedUser();

Contributing

Contributions are welcome - feel free to open an issue or pull request.

License

The MIT license - see LICENSE.

About

Node.js SDK for the Webflow Data API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' GitHub - cernak/js-webflow-api: Node.js SDK for the Webflow Data API · GitHub
Skip to content

Repository files navigation

Webflow Data API SDK

Installation

Using npm:

$ npm install webflow-api

Using yarn

$ yarn add webflow-api

Usage

The constructor takes in a few optional parameters to initialize the API client

  • token - the access token to use
  • headers - additional headers to add to the request
  • version - the version of the API you wish to use
constWebflow=require("webflow-api");// initialize the client with the access tokenconstwebflow=newWebflow({token: "[ACCESS TOKEN]"});// fully loadedconstwebflow=newWebflow({token: "[ACCESS TOKEN]",version: "1.0.0",headers: {"User-Agent": "My Webflow App / 1.0",},});

Transitioning to API v2

We're actively working on a new version of the SDK that will fully support API v2. In the meantime, to make use of API v2 with our SDK, there are some important changes you need to be aware of:

Setting Up For API v2

When initializing your client, it's crucial to set the beta flag to true in the client options. This ensures you're targeting the API v2 endpoints.

constwebflow=newWebflow({beta: true, ...otherOptions});

Please note, when the beta flag is set, several built-in methods will not be available. These methods include, but are not limited to, info, authenticatedUser, sites, site, etc. Attempting to use these will throw an error.

Calling API v2 Endpoints

To interact with API v2, you'll need to move away from using built-in methods, and instead use the provided HTTP methods directly.

For instance, where you previously used sites():

// get the first siteconst[site]=awaitwebflow.sites();

For API v2, you will need to use direct HTTP methods:

// get the first siteconstsites=awaitwebflow.get("/sites");constsite=sites[0];

We understand that this is a shift in how you interact with the SDK, but rest assured, our upcoming SDK version will streamline this process and offer a more integrated experience with API v2.

Basic Usage

Chaining Calls

You can retrieve child resources by chaining calls on the parent object.

// get the first siteconst[site]=awaitwebflow.sites();// get the first collection in the siteconst[collection]=awaitsite.collections();// get the first item in the collectionconst[item]=awaitcollection.items();// get one item from the collectionconstitem=awaitcollection.items({itemId: "[ITEM ID]"});

Pagination

To paginate results, pass in the limit and offset options.

// Get the first page of resultsconstpage1=awaitcollection.items({limit: 20});// Get the second page of resultsconstpage2=awaitcollection.items({limit: 20,offset: 20});

Rate Limit

Check rate limit status on each call by checking the _meta property.

// make an api callconstsite=awaitwebflow.site({siteId: "[SITE ID]"});// check rate limitconst{ rateLimit }=site._meta;// { limit: 60, remaining: 56 }

Update Token

If you need to update the access token, you can set the token property at any time.

// token is unsetconstwebflow=newWebflow();// set tokenwebflow.token="[ACCESS TOKEN]";// remove the tokenwebflow.clearToken();

Calling APIs Directly

All Webflow API endpoints can be called directly using the get, post, put, and delete methods.

// call the sites endpoint directlyconstsites=awaitwebflow.get("/sites");// post to an endpoint directlyconstresult=awaitwebflow.post("/sites/[SITE ID]/publish",{domains: ["hello-webflow.com"],});

OAuth

To implement OAuth, you'll need a Webflow App registered and a webserver running, that is publicly facing.

Authorize

The first step in OAuth is to generate an authorization url to redirect the user to.

// Get the authorization url to redirect users toconsturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",state: "1234567890",// optionalredirect_uri: "https://my.server.com/oauth/callback",// optional});// redirect user from your server routeres.redirect(url);

Using the scopes Parameter with v2 API

The v2 API introduces the concept of 'scopes', providing more control over app permissions. Instead of using the scope parameter as a single string, you can define multiple permissions using the scopes array:

consturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",redirect_uri: "https://my.server.com/oauth/callback",scopes: ["read:sites","write:items","read:users"],});

For more information and a detailed list of available scopes, refer to our Scopes Guide.

Access Token

Once a user has authorized their Webflow resource(s), Webflow will redirect back to your server with a code. Use this to get an access token.

constauth=awaitwebflow.accessToken({
client_id,
client_secret,
code,
redirect_uri,// optional - required if used in the authorize step});// you now have the user's access token to make API requests withconstuserWF=newWebflow({token: auth.access_token});// pull information for the userconstauthenticatedUser=awaituserWF.authenticatedUser();

Revoke Token

If the user decides to disconnect from your server, you should call revoke token to remove the authorization.

constresult=awaitwebflow.revokeToken({
client_id,
client_secret,
access_token,});// ensure it went throughresult.didRevoke===true;

Examples

Sites

Get all sites available or lookup by site id.

// List all sitesconstsites=awaitwebflow.sites();// Get a single siteconstsite=awaitwebflow.site({siteId: "[SITE ID]"});

Collections

Get all collections available for a site or lookup by collection id.

// Get a site's collection from the siteconstcollections=awaitsite.collections();// Get a site's collection by passing in a site idconstcollections=awaitwebflow.collections({siteId: "[SITE ID]"});// Get a single collectionconstcollection=awaitwebflow.collection({collectionId: "[COLLECTION ID]"});

Collection Items

Get all collection items available for a collection or lookup by item id.

// Get the items from a collectionconstitems=awaitcollection.items();// Get a subset of itemsconstitems=awaitcollection.items({limit: 10,offset: 2});// Get a single itemconstitem=awaitwebflow.item({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]"});

Update an Item

// Set the fields to updateconstfields={name: "New Name",_archived: false,_draft: false,slug: "new-name",};// call updateconstupdatedItem=awaitwebflow.updateItem({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]",
fields,});

Memberships

// Get a site's users from the siteconstusers=awaitsite.users();// Get a site's users with a site idconstusers=awaitwebflow.users({siteId: "[SITE ID]",});// Get a single userconstuser=awaitsite.user({siteId: "[SITE ID]",userId: "[USER ID]",});// Get a site's access groupsconstaccessGroups=awaitsite.accessGroups();// Get a site's access groups with a site idconstaccessGroups=awaitwebflow.accessGroups({siteId: "[SITE ID]",});

Webhooks

// get webhooks for a siteconstwebhooks=awaitsite.webhooks();// create a webhookconstwebhook=awaitsite.createWebhook({triggerType: "form_submission",url: "https://webhook.site",});

Authenticated User

// pull information for the authenticated userconstauthenticatedUser=awaitwebflow.authenticatedUser();

Contributing

Contributions are welcome - feel free to open an issue or pull request.

License

The MIT license - see LICENSE.

About

Node.js SDK for the Webflow Data API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - cernak/js-webflow-api: Node.js SDK for the Webflow Data API · GitHub
Skip to content

Repository files navigation

Webflow Data API SDK

Installation

Using npm:

$ npm install webflow-api

Using yarn

$ yarn add webflow-api

Usage

The constructor takes in a few optional parameters to initialize the API client

  • token - the access token to use
  • headers - additional headers to add to the request
  • version - the version of the API you wish to use
constWebflow=require("webflow-api");// initialize the client with the access tokenconstwebflow=newWebflow({token: "[ACCESS TOKEN]"});// fully loadedconstwebflow=newWebflow({token: "[ACCESS TOKEN]",version: "1.0.0",headers: {"User-Agent": "My Webflow App / 1.0",},});

Transitioning to API v2

We're actively working on a new version of the SDK that will fully support API v2. In the meantime, to make use of API v2 with our SDK, there are some important changes you need to be aware of:

Setting Up For API v2

When initializing your client, it's crucial to set the beta flag to true in the client options. This ensures you're targeting the API v2 endpoints.

constwebflow=newWebflow({beta: true, ...otherOptions});

Please note, when the beta flag is set, several built-in methods will not be available. These methods include, but are not limited to, info, authenticatedUser, sites, site, etc. Attempting to use these will throw an error.

Calling API v2 Endpoints

To interact with API v2, you'll need to move away from using built-in methods, and instead use the provided HTTP methods directly.

For instance, where you previously used sites():

// get the first siteconst[site]=awaitwebflow.sites();

For API v2, you will need to use direct HTTP methods:

// get the first siteconstsites=awaitwebflow.get("/sites");constsite=sites[0];

We understand that this is a shift in how you interact with the SDK, but rest assured, our upcoming SDK version will streamline this process and offer a more integrated experience with API v2.

Basic Usage

Chaining Calls

You can retrieve child resources by chaining calls on the parent object.

// get the first siteconst[site]=awaitwebflow.sites();// get the first collection in the siteconst[collection]=awaitsite.collections();// get the first item in the collectionconst[item]=awaitcollection.items();// get one item from the collectionconstitem=awaitcollection.items({itemId: "[ITEM ID]"});

Pagination

To paginate results, pass in the limit and offset options.

// Get the first page of resultsconstpage1=awaitcollection.items({limit: 20});// Get the second page of resultsconstpage2=awaitcollection.items({limit: 20,offset: 20});

Rate Limit

Check rate limit status on each call by checking the _meta property.

// make an api callconstsite=awaitwebflow.site({siteId: "[SITE ID]"});// check rate limitconst{ rateLimit }=site._meta;// { limit: 60, remaining: 56 }

Update Token

If you need to update the access token, you can set the token property at any time.

// token is unsetconstwebflow=newWebflow();// set tokenwebflow.token="[ACCESS TOKEN]";// remove the tokenwebflow.clearToken();

Calling APIs Directly

All Webflow API endpoints can be called directly using the get, post, put, and delete methods.

// call the sites endpoint directlyconstsites=awaitwebflow.get("/sites");// post to an endpoint directlyconstresult=awaitwebflow.post("/sites/[SITE ID]/publish",{domains: ["hello-webflow.com"],});

OAuth

To implement OAuth, you'll need a Webflow App registered and a webserver running, that is publicly facing.

Authorize

The first step in OAuth is to generate an authorization url to redirect the user to.

// Get the authorization url to redirect users toconsturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",state: "1234567890",// optionalredirect_uri: "https://my.server.com/oauth/callback",// optional});// redirect user from your server routeres.redirect(url);

Using the scopes Parameter with v2 API

The v2 API introduces the concept of 'scopes', providing more control over app permissions. Instead of using the scope parameter as a single string, you can define multiple permissions using the scopes array:

consturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",redirect_uri: "https://my.server.com/oauth/callback",scopes: ["read:sites","write:items","read:users"],});

For more information and a detailed list of available scopes, refer to our Scopes Guide.

Access Token

Once a user has authorized their Webflow resource(s), Webflow will redirect back to your server with a code. Use this to get an access token.

constauth=awaitwebflow.accessToken({
client_id,
client_secret,
code,
redirect_uri,// optional - required if used in the authorize step});// you now have the user's access token to make API requests withconstuserWF=newWebflow({token: auth.access_token});// pull information for the userconstauthenticatedUser=awaituserWF.authenticatedUser();

Revoke Token

If the user decides to disconnect from your server, you should call revoke token to remove the authorization.

constresult=awaitwebflow.revokeToken({
client_id,
client_secret,
access_token,});// ensure it went throughresult.didRevoke===true;

Examples

Sites

Get all sites available or lookup by site id.

// List all sitesconstsites=awaitwebflow.sites();// Get a single siteconstsite=awaitwebflow.site({siteId: "[SITE ID]"});

Collections

Get all collections available for a site or lookup by collection id.

// Get a site's collection from the siteconstcollections=awaitsite.collections();// Get a site's collection by passing in a site idconstcollections=awaitwebflow.collections({siteId: "[SITE ID]"});// Get a single collectionconstcollection=awaitwebflow.collection({collectionId: "[COLLECTION ID]"});

Collection Items

Get all collection items available for a collection or lookup by item id.

// Get the items from a collectionconstitems=awaitcollection.items();// Get a subset of itemsconstitems=awaitcollection.items({limit: 10,offset: 2});// Get a single itemconstitem=awaitwebflow.item({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]"});

Update an Item

// Set the fields to updateconstfields={name: "New Name",_archived: false,_draft: false,slug: "new-name",};// call updateconstupdatedItem=awaitwebflow.updateItem({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]",
fields,});

Memberships

// Get a site's users from the siteconstusers=awaitsite.users();// Get a site's users with a site idconstusers=awaitwebflow.users({siteId: "[SITE ID]",});// Get a single userconstuser=awaitsite.user({siteId: "[SITE ID]",userId: "[USER ID]",});// Get a site's access groupsconstaccessGroups=awaitsite.accessGroups();// Get a site's access groups with a site idconstaccessGroups=awaitwebflow.accessGroups({siteId: "[SITE ID]",});

Webhooks

// get webhooks for a siteconstwebhooks=awaitsite.webhooks();// create a webhookconstwebhook=awaitsite.createWebhook({triggerType: "form_submission",url: "https://webhook.site",});

Authenticated User

// pull information for the authenticated userconstauthenticatedUser=awaitwebflow.authenticatedUser();

Contributing

Contributions are welcome - feel free to open an issue or pull request.

License

The MIT license - see LICENSE.

About

Node.js SDK for the Webflow Data API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); GitHub - cernak/js-webflow-api: Node.js SDK for the Webflow Data API · GitHub
Skip to content

Repository files navigation

Webflow Data API SDK

Installation

Using npm:

$ npm install webflow-api

Using yarn

$ yarn add webflow-api

Usage

The constructor takes in a few optional parameters to initialize the API client

  • token - the access token to use
  • headers - additional headers to add to the request
  • version - the version of the API you wish to use
constWebflow=require("webflow-api");// initialize the client with the access tokenconstwebflow=newWebflow({token: "[ACCESS TOKEN]"});// fully loadedconstwebflow=newWebflow({token: "[ACCESS TOKEN]",version: "1.0.0",headers: {"User-Agent": "My Webflow App / 1.0",},});

Transitioning to API v2

We're actively working on a new version of the SDK that will fully support API v2. In the meantime, to make use of API v2 with our SDK, there are some important changes you need to be aware of:

Setting Up For API v2

When initializing your client, it's crucial to set the beta flag to true in the client options. This ensures you're targeting the API v2 endpoints.

constwebflow=newWebflow({beta: true, ...otherOptions});

Please note, when the beta flag is set, several built-in methods will not be available. These methods include, but are not limited to, info, authenticatedUser, sites, site, etc. Attempting to use these will throw an error.

Calling API v2 Endpoints

To interact with API v2, you'll need to move away from using built-in methods, and instead use the provided HTTP methods directly.

For instance, where you previously used sites():

// get the first siteconst[site]=awaitwebflow.sites();

For API v2, you will need to use direct HTTP methods:

// get the first siteconstsites=awaitwebflow.get("/sites");constsite=sites[0];

We understand that this is a shift in how you interact with the SDK, but rest assured, our upcoming SDK version will streamline this process and offer a more integrated experience with API v2.

Basic Usage

Chaining Calls

You can retrieve child resources by chaining calls on the parent object.

// get the first siteconst[site]=awaitwebflow.sites();// get the first collection in the siteconst[collection]=awaitsite.collections();// get the first item in the collectionconst[item]=awaitcollection.items();// get one item from the collectionconstitem=awaitcollection.items({itemId: "[ITEM ID]"});

Pagination

To paginate results, pass in the limit and offset options.

// Get the first page of resultsconstpage1=awaitcollection.items({limit: 20});// Get the second page of resultsconstpage2=awaitcollection.items({limit: 20,offset: 20});

Rate Limit

Check rate limit status on each call by checking the _meta property.

// make an api callconstsite=awaitwebflow.site({siteId: "[SITE ID]"});// check rate limitconst{ rateLimit }=site._meta;// { limit: 60, remaining: 56 }

Update Token

If you need to update the access token, you can set the token property at any time.

// token is unsetconstwebflow=newWebflow();// set tokenwebflow.token="[ACCESS TOKEN]";// remove the tokenwebflow.clearToken();

Calling APIs Directly

All Webflow API endpoints can be called directly using the get, post, put, and delete methods.

// call the sites endpoint directlyconstsites=awaitwebflow.get("/sites");// post to an endpoint directlyconstresult=awaitwebflow.post("/sites/[SITE ID]/publish",{domains: ["hello-webflow.com"],});

OAuth

To implement OAuth, you'll need a Webflow App registered and a webserver running, that is publicly facing.

Authorize

The first step in OAuth is to generate an authorization url to redirect the user to.

// Get the authorization url to redirect users toconsturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",state: "1234567890",// optionalredirect_uri: "https://my.server.com/oauth/callback",// optional});// redirect user from your server routeres.redirect(url);

Using the scopes Parameter with v2 API

The v2 API introduces the concept of 'scopes', providing more control over app permissions. Instead of using the scope parameter as a single string, you can define multiple permissions using the scopes array:

consturl=webflow.authorizeUrl({client_id: "[CLIENT ID]",redirect_uri: "https://my.server.com/oauth/callback",scopes: ["read:sites","write:items","read:users"],});

For more information and a detailed list of available scopes, refer to our Scopes Guide.

Access Token

Once a user has authorized their Webflow resource(s), Webflow will redirect back to your server with a code. Use this to get an access token.

constauth=awaitwebflow.accessToken({
client_id,
client_secret,
code,
redirect_uri,// optional - required if used in the authorize step});// you now have the user's access token to make API requests withconstuserWF=newWebflow({token: auth.access_token});// pull information for the userconstauthenticatedUser=awaituserWF.authenticatedUser();

Revoke Token

If the user decides to disconnect from your server, you should call revoke token to remove the authorization.

constresult=awaitwebflow.revokeToken({
client_id,
client_secret,
access_token,});// ensure it went throughresult.didRevoke===true;

Examples

Sites

Get all sites available or lookup by site id.

// List all sitesconstsites=awaitwebflow.sites();// Get a single siteconstsite=awaitwebflow.site({siteId: "[SITE ID]"});

Collections

Get all collections available for a site or lookup by collection id.

// Get a site's collection from the siteconstcollections=awaitsite.collections();// Get a site's collection by passing in a site idconstcollections=awaitwebflow.collections({siteId: "[SITE ID]"});// Get a single collectionconstcollection=awaitwebflow.collection({collectionId: "[COLLECTION ID]"});

Collection Items

Get all collection items available for a collection or lookup by item id.

// Get the items from a collectionconstitems=awaitcollection.items();// Get a subset of itemsconstitems=awaitcollection.items({limit: 10,offset: 2});// Get a single itemconstitem=awaitwebflow.item({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]"});

Update an Item

// Set the fields to updateconstfields={name: "New Name",_archived: false,_draft: false,slug: "new-name",};// call updateconstupdatedItem=awaitwebflow.updateItem({collectionId: "[COLLECTION ID]",itemId: "[ITEM ID]",
fields,});

Memberships

// Get a site's users from the siteconstusers=awaitsite.users();// Get a site's users with a site idconstusers=awaitwebflow.users({siteId: "[SITE ID]",});// Get a single userconstuser=awaitsite.user({siteId: "[SITE ID]",userId: "[USER ID]",});// Get a site's access groupsconstaccessGroups=awaitsite.accessGroups();// Get a site's access groups with a site idconstaccessGroups=awaitwebflow.accessGroups({siteId: "[SITE ID]",});

Webhooks

// get webhooks for a siteconstwebhooks=awaitsite.webhooks();// create a webhookconstwebhook=awaitsite.createWebhook({triggerType: "form_submission",url: "https://webhook.site",});

Authenticated User

// pull information for the authenticated userconstauthenticatedUser=awaitwebflow.authenticatedUser();

Contributing

Contributions are welcome - feel free to open an issue or pull request.

License

The MIT license - see LICENSE.

About

Node.js SDK for the Webflow Data API

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages