API
Making API Requests with cURL
In this tutorial, we will learn how to make requests against the Twisp GraphQL API using the curl command line tool.
Prerequisites
To complete this tutorial, you'll need:
- The URL endpoint for the API
- The
accountId
of your tenant - An authenticated JWT
To make HTTPS requests to the Twisp GraphQL API using cURL, follow these steps:
Open a command-line interface (Terminal on macOS/Linux or Command Prompt on Windows).
Type in the following command:
curl 'https://api.<region>.cloud.twisp.com/financial/v1/graphql' \
This line specifies the URL to which the cURL request will be made. Replace
<region>
with the AWS region for your ledger, e.g.us-east-1
.Add the required headers by typing the following lines:
-H 'authorization: Bearer <JWT>' \ -H 'content-type: application/json, application/json' \ -H 'x-twisp-account-id: <TwispAccountId>' \
Replace
<JWT>
with your authenticated JWT and<TwispAccountId>
with your Twisp account ID for the tenant.The
-H
flag is used to specify custom headers. In this case, the headers being set are:authorization
for authentication purposes.content-type
to indicate the type of data being sent in the request body.x-twisp-account-id
for specifying the account ID to be used in the request.
Add the request payload by typing the following line:
--data-raw '{"query":"query { accounts(index: { name: STATUS }, where: { status: { eq: "ACTIVE" } }, first: 5) { nodes { accountId code name } } }"}'
This line contains the
--data-raw
flag followed by a JSON string. This JSON string includes a GraphQL query to fetch accounts with the specified conditions (in this case, the first 5 active accounts). This is where you write your GraphQL operation.After entering all the lines, the complete cURL request should look like:
curl 'https://api.<region>.cloud.twisp.com/financial/v1/graphql' \ -H 'authorization: Bearer <JWT>' \ -H 'content-type: application/json, application/json' \ -H 'x-twisp-account-id: <TwispAccountId>' \ --data-raw '{"query":"query { accounts(index: { name: STATUS }, where: { status: { eq: "ACTIVE" } }, first: 5) { nodes { accountId code name } } }"}'
Press Enter to execute the cURL request. If successful, you should receive a JSON response containing the requested data.