Octopus Cards

Login

Authenticate with the API and receive access and refresh tokens

POST /auth/login

Exchange your API credentials for an access token and refresh token pair.

Request

curl -X POST {{host}}/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "username": "your_api_key",
    "password": "your_api_secret"
  }'
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    body, _ := json.Marshal(map[string]string{
        "username": "your_api_key",
        "password": "your_api_secret",
    })

    resp, err := http.Post(
        "{{host}}/auth/login",
        "application/json",
        bytes.NewReader(body),
    )
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    var result struct {
        Success bool `json:"success"`
        Data    struct {
            AccessToken      string `json:"access_token"`
            RefreshToken     string `json:"refresh_token"`
            AccessExpiresAt  string `json:"access_expires_at"`
            RefreshExpiresAt string `json:"refresh_expires_at"`
            ClientID         int    `json:"client_id"`
        } `json:"data"`
    }
    json.NewDecoder(resp.Body).Decode(&result)

    fmt.Println("Access Token:", result.Data.AccessToken)
}

Request Parameters

KeyTypeRequiredDescription
usernamestringYesYour API key retrieved from your dashboard
passwordstringYesYour API secret retrieved from your dashboard

Response

{
  "success": true,
  "data": {
    "access_token": "eyJhbGciOiJIUzI1NiIs...",
    "refresh_token": "eyJhbGciOiJIUzI1NiIs...",
    "access_expires_at": "2025-01-15T13:00:00Z",
    "refresh_expires_at": "2025-01-22T12:00:00Z",
    "client_id": 42
  }
}

Response Fields

KeyTypeDescription
successbooleanAlways true on success
data.access_tokenstringJWT for authenticating API requests. Valid for 1 hour.
data.refresh_tokenstringJWT for obtaining new token pairs. Valid for 7 days.
data.access_expires_atstringISO 8601 expiry timestamp for the access token
data.refresh_expires_atstringISO 8601 expiry timestamp for the refresh token
data.client_idintegerYour client ID

Errors

400 Bad Request — Missing required fields.

{
  "error": {
    "name": "ValidationException",
    "code": "VALIDATION_FAILURE",
    "message": "Username and password are required"
  }
}

Returned when username or password is empty or missing from the request body.

401 Unauthorized — Credentials do not match.

{
  "error": {
    "name": "UnauthorizedError",
    "code": "UNAUTHORIZED",
    "message": "Invalid credentials"
  }
}

Returned when the username does not exist or the password does not match.

401 Unauthorized — Client account is disabled.

{
  "error": {
    "name": "UnauthorizedError",
    "code": "UNAUTHORIZED",
    "message": "Client account is not active"
  }
}

Returned when the client exists but their account status is not Active.

403 Forbidden — Request IP is not in the client's whitelist.

{
  "error": {
    "name": "ForbiddenError",
    "code": "FORBIDDEN",
    "message": "IP address not authorized"
  }
}

Returned when the client has IP whitelist entries configured and the request IP does not match any allowed CIDR range.

On this page