Setting a payload for a Spell
A Payload is a set of data sent with your request. These data are related to the endpoint you're requested.
For example, if you want to create a new user, you'll send a request to the endpoint for user creation and set inside the payload all the user's details (name, email, etc...).
Set a payload manually
To set up a payload manually, click on the Payload button inside the code editor.
You can next set the JSON you want to be sent.
This payload will be set and be sent every time you will click on the Run button (for development).
At the top, we give you a code snippet to use inside your Spell to retrieve the payload's content.
Set a Payload from a webhook call
Prepare the Spell to receive the payload
First, you'll need to create a new blank Spell. Each Spell has a unique URL and this URL will be the destination of a webhook.
Open the Payload and clear it (leave an empty JSON object: {}
).
We'll now log the content of the params
variable to know what is coming from the webhook.
You can now retrieve the development URL by clicking on Versionning in the Spell details page:
and click inside the Dev environment. You'll see your URL and you can copy it with the default API key using the button.
The params
variable is always set inside your Spell.
This variable contains anything sent to your Spell, using query parameters inside the URL.
You can also call your Spell URL with the POST
method and the params
variable will contain the body of your request.
For example, if you add these parameters &firstName=Harry&lastName=Potter
to a Spell URL (ex: https://api.meta-api.io/api/spells/626c75a3123471b901ec7f71/runSync?dev=true&apikey=xxx&firstName=Harry&lastName=Potter
), your params
variable will contain:
{
firstName: "Harry",
lastname: "Potter"
}
Retrieve the Payload sent by the webhook
Now you have the URL, configure it on your favorite service and send a webhook.
Click on the Console button and you'll be able to see the content of the payload:
Update the payload in order to work with
You can now work directly with a payload or you can copy / paste the content of the payload inside the Payload popup to send this content during your Spell's development.