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

ArgumentTypeDescription

options

object

The fetch options used to initialise the request.

triggerEl

HTMLElement or null

The element that triggered the action. If the action was triggered programmatically via the API the triggerEl will be null.

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