Webflow CMS API not working

ive been trying to figure this out for a week and can’t. can anyone help me figure out why my netlify function keeps failing? CODE BELOW

Here is what I am trying to build: Loom | Free Screen & Video Recording Software | Loom

Read only Webflow - Ash Personal Website

I am attempting to integrate a Netlify function to call the Webflow API and retrieve items from a specific collection. I’ve set up the function to trigger on a GET request and pass any query parameters it receives directly to the Webflow API.

However, I’m encountering a 404 “Route not found” error when the function executes. The collection ID and site ID have been double-checked and are correct. I suspect there might be an issue with the endpoint URL or the way I am passing the API token.

The environment variables are set correctly in Netlify for the API token. The function is intended to be a straightforward GET request handler that interfaces with the Webflow API to return data about a collection’s items to the client.

Objective:

I want the Netlify function to successfully fetch the collection items from Webflow and return them in the response. The function should handle any errors gracefully and provide meaningful error messages.

javascriptCopy code


const axios = require('axios');

exports.handler = async function(event, context) {
  // Note: Replace [SITE_ID] and [COLLECTION_ID] with actual IDs, and ensure the API version is correct.
  const WEBFLOW_API_ENDPOINT = 'https://api.webflow.com/sites/[SITE_ID]/collections/[COLLECTION_ID]/items';

  try {
    // Pass through any query parameters received by the Netlify function to the Webflow API call
    const params = event.queryStringParameters;

    // Configure the request headers with the API token stored in environment variables
    const config = {
      method: 'get',
      url: WEBFLOW_API_ENDPOINT,
      headers: {
        'Authorization': `Bearer ${process.env.WEBFLOW_API_TOKEN}`,
        'accept-version': '1.1.0' // Use the API version supported by Webflow
      },
      params: params
    };

    // Make the GET request to the Webflow API
    const response = await axios(config);

    // Respond with the data from Webflow
    return {
      statusCode: 200,
      body: JSON.stringify(response.data)
    };
  } catch (error) {
    // Log and respond with the error information
    console.error('Error:', error);
    return {
      statusCode: error.response ? error.response.status : 500,
      body: JSON.stringify({
        message: 'Failed to retrieve items from Webflow collection.',
        details: error.message,
        error: error.response ? error.response.data : 'An unknown error occurred'
      })
    };
  }
};

Request for Help:

I’m looking for guidance on what might be causing the “Route not found” error and how to resolve it. If anyone has experience with Webflow’s API and Netlify functions and can spot a potential misconfiguration in my setup, your insights would be greatly appreciated.

Mod Edit: Fixed code display error. - [at]webdev

Hey @Asher_Fishman,

I’d double check that your API Key is for the version of the API endpoint you are targeting.

The “Route not found” can sometimes occur when hitting a v1 endpoint using a v2 token and vice versa.

you’re getting a 404 because this route you’re using doesn’t exist according to the docs. to get a collection’s items, you use either of these routes:

https://docs.developers.webflow.com/reference/list-collection-items