Send an API request
Send an HTTP request to an outside API and use the response.
integration.http sends an HTTP request and gives you the response.
Settings
| Setting | What it does |
|---|---|
| Method | GET, POST, PUT, PATCH or DELETE. |
| URL | The address, starting with https://. |
| Query | Added to the address, one name: value per line, encoded as they need to be. |
| Sign in with | Nothing, a bearer token, an API key header (X-API-Key), or a username and password. |
| Token or key | What to sign in with, such as {secret.API_KEY}. For a username and password, name:password. |
| Headers | One per line, such as Accept: application/json. |
| Body | JSON to send, such as { "name": "{user.name}" }. |
| Wait at most (seconds) | How long to wait for an answer, up to 30. The default is 10. |
| Keep from the answer | Parts of the answer to keep, one name: path per line, such as price: data.0.amount. Each is {temp.name} afterwards. |
Ways out
| Way out | Taken when |
|---|---|
Success | The request succeeded. |
Failed | It didn't, or the API answered with a status of 400 or more. |
Produces
| Token | Value |
|---|---|
{http.status} | The status code the API answered with |
{http.body} | The response. Reach into it with dots, like {http.body.name}, or by position in a list, like {http.body.items.0.title}. {http.body.items.length} is how long a list is. |
{temp.name} | Each part kept with Keep from the answer |
Notes
Keep keys out of messages
This step is the only one that fills in {secret.NAME}. Anywhere else the token is left empty, so a key can't end up in a message, a variable or the run log.
- Only public addresses can be reached.
- Put Defer reply before it, because Discord expects an answer within three seconds.
- To transform the answer further, put Run code after it: the answer is
ctx.http.bodythere. - The canvas shows the method and the URL without
https://.