Making Your First API Call
February 5, 2025 32174b4 Edit this page

Making Your First API Call 🗄️ Archived

Step-by-step tutorial for making your first API request

This tutorial walks you through making your first successful API call.

Prerequisites

Before starting, ensure you have:

  • An API key or access token
  • A tool like cURL, Postman, or a programming language SDK
  • Basic understanding of HTTP requests

Step 1: Authenticate

First, obtain your authentication credentials:

curl -X POST https://api.example.com/v1/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "your-email@example.com",
    "password": "your-password"
  }'

Save the access_token from the response.

Step 2: Make a Simple GET Request

Retrieve a list of resources:

curl -X GET https://api.example.com/v1/resources \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Expected Response

{
  "data": [
    {
      "id": "res_1",
      "name": "First Resource",
      "created_at": "2025-01-15T10:00:00Z"
    },
    {
      "id": "res_2",
      "name": "Second Resource",
      "created_at": "2025-01-16T11:00:00Z"
    }
  ],
  "meta": {
    "page": 1,
    "total": 2
  }
}

Step 3: Create a Resource

Make a POST request to create a new resource:

curl -X POST https://api.example.com/v1/resources \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My New Resource",
    "description": "Created via API"
  }'

Using Different Languages

Python

import requests

url = "https://api.example.com/v1/resources"
headers = {
    "Authorization": "Bearer YOUR_ACCESS_TOKEN",
    "Content-Type": "application/json"
}

response = requests.get(url, headers=headers)
data = response.json()
print(data)

JavaScript

fetch('https://api.example.com/v1/resources', {
  headers: {
    'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
    'Content-Type': 'application/json'
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Go

package main

import (
    "fmt"
    "net/http"
    "io/ioutil"
)

func main() {
    client := &http.Client{}
    req, _ := http.NewRequest("GET", "https://api.example.com/v1/resources", nil)
    req.Header.Add("Authorization", "Bearer YOUR_ACCESS_TOKEN")
    
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Troubleshooting

Common Issues

401 Unauthorized

  • Check that your access token is valid
  • Ensure the token hasn’t expired
  • Verify the Authorization header format

429 Too Many Requests

  • You’ve hit the rate limit
  • Wait before making more requests
  • Implement exponential backoff

400 Bad Request

  • Validate your request body
  • Check required fields
  • Ensure proper JSON formatting

Next Steps

Now that you’ve made your first API call: