BuildcordDocs

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

SettingWhat it does
MethodGET, POST, PUT, PATCH or DELETE.
URLThe address, starting with https://.
QueryAdded to the address, one name: value per line, encoded as they need to be.
Sign in withNothing, a bearer token, an API key header (X-API-Key), or a username and password.
Token or keyWhat to sign in with, such as {secret.API_KEY}. For a username and password, name:password.
HeadersOne per line, such as Accept: application/json.
BodyJSON 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 answerParts of the answer to keep, one name: path per line, such as price: data.0.amount. Each is {temp.name} afterwards.

Ways out

Way outTaken when
SuccessThe request succeeded.
FailedIt didn't, or the API answered with a status of 400 or more.

Produces

TokenValue
{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.body there.
  • The canvas shows the method and the URL without https://.

On this page