Call API Handlers from Build Event Handlers
It’s possible to call an API handler from a build event handler. This is useful if you want to interact with the Integration API or Netlify API from a build event handler.
There are a few steps involved in this:
Generate a build token
In order for your build event handler to call an API handler, you need to generate a build token. This can be done by customizing the enablement flow or by creating a separate API handler that’s called from an Integration UI component.
The following example shows how to generate a build token inside an API handler that is called on the site level from an Integration UI component:
Create a Build Context
Once you’ve generated a build token, you’re ready to set up a Build Context. This creates a context object that you can access on any build event handler. This is a necessary step to pass data from an API handler to a build event handler.
Inside the file src/index.ts
, where you have defined your Netlify integration and your API handlers, add the following code:
Use the Build Context in a build event handler
Now that you have passed along data from your API handler to your build event handler, you can access the data from within your build event handler. The following example shows how to access the useful_data
from the Build Context: