Posted on

How to Make Your First API Request with curl

Monochrome technical illustration for How to Make Your First API Request with curl

curl is a command-line HTTP client. It lets you make a real API request, inspect the status and JSON, and reproduce a problem without writing a full application.

Before you start

  • A terminal with curl installed
  • A Weather Station app and Readings collection
  • An app API key with the required Read and Write scopes

Use placeholders in shared examples. Treat a real API key like a password and do not put it in source code, screenshots, shell history or a repository.

Set reusable shell values

export MEOW_API="https://meowmeowscratch.com/api"
export MEOW_USERNAME="YOUR_USERNAME"
export MEOW_APP_API_KEY="YOUR_APP_API_KEY"Code language: JavaScript (javascript)

Read a collection

curl -i "$MEOW_API/v1/$MEOW_USERNAME/weather-station/readings/" \
  -H "Authorization: Bearer $MEOW_APP_API_KEY"Code language: JavaScript (javascript)

GET is curl’s default method. The -i flag includes the response status and headers. A successful collection read returns 200 OK and JSON containing fields and records.

Create a record

curl -i -X POST \
  "$MEOW_API/apps/weather-station/endpoints/readings/records/" \
  -H "Authorization: Bearer $MEOW_APP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"data":{"temperature":22.5}}'Code language: JavaScript (javascript)

Expect 201 Created and save the returned UUID if you need to update or delete that record.

Try an intentional validation error

curl -i -X POST \
  "$MEOW_API/apps/weather-station/endpoints/readings/records/" \
  -H "Authorization: Bearer $MEOW_APP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"data":{"temperature":"warm"}}'Code language: JavaScript (javascript)

A numeric field receiving text should return a client error such as 400. Read the body for the field and validation detail; do not retry an unchanged invalid request.

Avoid shell history leaks

Keep the key in an environment variable rather than writing it into a command. For a temporary interactive shell, use a hidden prompt such as read -s MEOW_APP_API_KEY, then export it. Clear the variable when finished.

Common curl mistakes

  • Leaving out the trailing slash on a management write route.
  • Using a platform token where an app key is expected, or vice versa.
  • Forgetting Content-Type: application/json on a write.
  • Using single quotes or invalid JSON inside the body.
  • Following a redirect without checking whether the method and authorization were preserved.

Next step

Repeat the same request with Python in Install the Meow SDK and Make Your First Request. For method and status explanations, read HTTP Methods Explained and HTTP Status Codes Explained.