View a markdown version of this page

Call the data API over HTTP - AWS Amplify

Call the data API over HTTP

You can call the Amplify backend data API of your AWS Amplify app with HTTP requests from other languages and tools, such as Python, Go or curl. Each table is at <backend URL>/rest/<table>, and each database function is at <backend URL>/rest/rpc/<function>. In JavaScript and TypeScript code, use the client SDK instead. The SDK keeps the user’s session and gets a new token when the old one expires. For more information, see the client SDK README on GitHub.

Get the backend URL and publishable key

Run the following commands to read the backend URL and the publishable key from the active deployment of an environment. Replace preview with the name of your environment.

API=$(aws amplifygen3 backend info --env preview --query BackendUrl --output text) KEY=$(aws amplifygen3 backend info --env preview --query PublishableKey --output text)

For more information about the local backend’s URL and key, see Develop locally.

Call as a visitor

Send the publishable key in the apikey header of every request. A request with only the key runs as the anon role. Run the following command to read the products table as a visitor:

curl -s "$API/rest/products?select=id,name" -H "apikey: $KEY"

For more information about roles, see API keys and roles.

Call as a signed-in user

Get a token for the user’s session, and send it with each request:

  1. Run the following command to sign the user in and save the session cookie that the backend returns in the file jar:

    curl -s -c jar -X POST "$API/auth/sign-in/email" -H "apikey: $KEY" -H 'content-type: application/json' \ -d '{"email":"a@example.com","password":"correct horse battery"}'
  2. Run the following command to get a token for the session:

    JWT=$(curl -s -b jar -H "apikey: $KEY" "$API/auth/token" | jq -r '.token')
  3. Run the following command to send the token in the Authorization header, together with the publishable key:

    curl -s "$API/rest/notes?select=id,body&order=created_at.desc&limit=20" \ -H "apikey: $KEY" -H "Authorization: Bearer $JWT"

A token expires after 15 minutes. Reuse the same token for your requests, and get a new one before it expires. When a request gets 401, call GET /auth/token once with the session cookie, and send the request again.

Call with full access from server code

Server code can sign a request with AWS credentials, using AWS Signature Version 4 (SigV4). A signed request needs no publishable key. It runs as service_role and can read and change every row. Sign requests only in code that runs on your server, never in browser or mobile app code. The identity that signs needs the amplifygen3:Connect permission in the backend’s AWS account. A signed request body can be up to 1 MiB. A signed body over 64 KiB gets 503 SERVICE_UNAVAILABLE with Retry-After while the backend is busy with other large signed requests. Send it again after the wait.

A signed request uses the signing name amplifygen3. A deployed backend URL doesn’t include an AWS Region, so the request signs for the AWS Region in AWS_REGION or AWS_DEFAULT_REGION. When your code runs outside AWS, such as a script on your computer, set AWS_REGION to your app’s AWS Region. Without either variable, each SDK call fails with Cannot determine the SigV4 signing region.

For more information about signed calls with the SDK, see Call the backend with full access.

Read, write and call functions

Each operation uses its own HTTP method. Filters, sorting and paging are query parameters, such as id=eq.1, order=created_at.desc and limit=50. Run the following commands to read, insert, update and delete rows, and to call a function. They use the headers from Call as a signed-in user:

H=(-H "apikey: $KEY" -H "Authorization: Bearer $JWT" -H 'content-type: application/json') ID=$(curl -s -X POST "$API/rest/notes" "${H[@]}" -H 'Prefer: return=representation' \ -d '{"body":"hello"}' | jq -r '.[0].id') # insert curl -s "$API/rest/notes?select=id,body&id=eq.$ID" "${H[@]}" # read curl -s -X PATCH "$API/rest/notes?id=eq.$ID" "${H[@]}" -H 'Prefer: return=representation' \ -d '{"body":"edited"}' # update curl -s -X DELETE "$API/rest/notes?id=eq.$ID" "${H[@]}" -H 'Prefer: return=representation' # delete curl -s -X POST "$API/rest/rpc/notes_since" "${H[@]}" -d '{"since":"2026-01-01"}' # call a function

The insert often returns an id other than 1, because identity values aren’t reused, so the commands keep the id that it returns.

For more information about filters and related tables, see Read data. For more information about upserts and changed rows, see Write data. For more information about functions, see Call database functions.

Call from browser code

If you call the data API with fetch from browser code, pass credentials: 'include' on your /auth calls, such as sign-in and GET /auth/token, so that the browser sends and keeps the session cookie. On /rest calls, send the user’s token in the Authorization header. Amplify allows calls from the Amplify URLs and custom domains of your environment. To call from another origin, add the origin to trustedOrigins. For more information about trusted origins, see Auth configuration.

Headers

Header Direction Use

apikey

Request

The publishable key. Send it on every request to /rest and /auth, except a signed request

Authorization

Request

Bearer <token> for a signed-in user. Don’t put the publishable key here

content-type

Request

application/json for a request body

Prefer

Request

return=representation returns the changed rows. count=exact returns the row count. resolution=merge-duplicates, with on_conflict=<column>, makes an insert an upsert

Range

Request

Not used. The deployed data API ignores it. To read a page of rows, use the limit and offset query parameters

Content-Range

Response

The range of rows returned, and the total when you send count=exact

Limits and errors

A read returns at most 1,000 rows. To read more, page with limit, offset and order. A request body can be up to 10 MiB on /rest and 1 MiB on /auth. A larger body gets 413 PAYLOAD_TOO_LARGE. For more information about error codes and their fixes, see Data API errors.