onRequestInit

The onRequestInit callback is triggered after the action options have been converted into fetch options but before the request has been made.

Use cases

  • Manipulate the headers

  • Manipulate the body

  • Perform validation on the data

Arguments

Example

This example demonstrates how to include a value from the Webflow CMS in a request.

The below example assumes the CMS value is bound to a text element within the trigger elements parent element.

...
onRequestInit: {
  callback: async (options, triggerEl) => {
    const id = triggerEl?.parentElement?.querySelector("[airtable-id]")?.textContent
    if (id) {
      // set the value dynamically
      options.body['id'] = id
      
      // return the updated options
      return options
    }
    
    // the request will not be executed
    return false
  }
},
...

Last updated