Webflow sync, pageviews & more.
NEW
Answers

How can we obtain the staging domain's URL when using the Webflow API command 'Publish site' and the 'List domains' command only returns custom domain names?

When using the Webflow API command 'Publish site', you can obtain the staging domain's URL by making an additional API call to retrieve the staging domain. The 'List domains' command only returns the custom domain names associated with the Webflow site.

To obtain the staging domain's URL, you can perform the following steps:

1. Make an API request to the 'List domains' endpoint using the Webflow API. This will return a list of custom domains associated with the site.

2. Iterate through the response and identify the domain with the 'default' value set to 'true'. This indicates that it is the staging domain.

3. Once you have identified the staging domain, you can extract the 'domain' property value from the API response. This will give you the staging domain's URL.

Here's an example of how you can achieve this using JavaScript and the Webflow API:

```javascript
// Replace 'your-api-key' and 'your-site-id' with your actual API key and site ID
const API_KEY = 'your-api-key';
const SITE_ID = 'your-site-id';

// Fetch the list of domains associated with the site
fetch(`https://api.webflow.com/sites/${SITE_ID}/domains`, {
headers: {
Authorization: `Bearer ${API_KEY}`,
},
})
.then((response) => response.json())
.then((data) => {
// Find the staging domain
const stagingDomain = data.domains.find((domain) => domain.default === true);

if (stagingDomain) {  // Print the staging domain's URL  console.log(\`Staging Domain URL: ${stagingDomain.domain}\`);} else {  console.log('Staging domain not found');}

})
.catch((error) => {
console.error('Error:', error);
});
```

Make sure to replace 'your-api-key' and 'your-site-id' with your actual API key and site ID. This code snippet will fetch the list of domains associated with your Webflow site using the Webflow API. It will then iterate through the domains and find the staging domain based on the 'default' property. Finally, it will print the staging domain's URL to the console.

By following these steps, you'll be able to obtain the staging domain's URL when using the Webflow API command 'Publish site'.

Rate this answer

Other Webflow Questions