Configure your HTTP request

When making a HTTP request using any of the HTTP actions, you might need to authenticate the request, set up a proxy, etc.

You can customize the request by using an Axios request configuration object as the last parameter of the action.

The following config options are set by Cloudhooks, and shouldn't be overwritten:

  • url
  • method
  • data

Please refer to the Axios request configuration documentation for more information.

As an example, this is how an API with bearer authentication can be called:

module.exports = async function(payload, actions, context) {
  const apiToken = 'XXXXXXXXXXXXXXXXXXX';
  const httpConfig = {
    headers: {
      'Authorization': `Bearer ${apiToken}`
    }
  }

  const response = await actions.http.get(
  	'https://api.example.com/api-endpoint/',
    httpConfig
  )
}