Skip to main content

Your First API Call

This guide will walk you through making your first API call to the Weir AI API v1.0.1. We’ll cover different scenarios based on your chosen API category.

Prerequisites

Before making your first API call, ensure you have:

API Credentials

Your client credentials (External APIs) or user account (Console APIs)

Access Token

A valid access token for authentication

HTTP Client

curl, Postman, or your preferred HTTP client

Base URL

The Weir AI API base URL: https://api.weir.ai

External API - First Call

Step 1: Generate Access Token

curl -X POST 'https://api.weir.ai/auth/token' \
  -H 'Content-Type: application/json' \
  -u 'your_client_id:your_secret_key'
{
  "data": {
    "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "expiresIn": 3600,
    "tokenType": "Bearer"
  },
  "message": "Access token generated successfully",
  "status": "success"
}

Step 2: Use the Access Token

curl -X GET 'https://api.weir.ai/external/endpoint' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'Content-Type: application/json'

Console API - First Call

Step 1: Login and Get Tokens

curl -X POST 'https://api.weir.ai/auth/login' \
  -H 'Content-Type: application/json' \
  -d '{
    "username": "John Doe",
    "password": "securePassword123"
  }'
{
  "data": {
    "accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refreshToken": "refresh_token_123456789",
    "expiresIn": 3600,
    "user": {
      "id": "user_123456789",
      "fullname": "John Doe",
      "email": "[email protected]",
      "role": "Organization_Admin"
    }
  },
  "message": "Login successful",
  "status": "success"
}

Step 2: Create Your First Team

curl -X POST 'https://api.weir.ai/org/create/team' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -H 'x-source: console' \
  -d '{
    "name": "My First Team"
  }'
{
  "data": {
    "teamId": "team_123456789",
    "name": "My First Team",
    "createdAt": "2025-01-15T10:30:00Z",
    "memberCount": 1,
    "status": "active"
  },
  "message": "Team created successfully",
  "status": "success"
}

Understanding the Response Format

All Weir AI API responses follow a consistent format:

Success Response Structure

{
  "data": {
    // Response data object
  },
  "message": "Human-readable message",
  "status": "success"
}

Error Response Structure

{
  "error": {
    "code": "ERROR_CODE",
    "message": "Human-readable error message",
    "details": "Additional error details"
  },
  "status": "error"
}

Common Response Fields

  • data: Contains the actual response data
  • message: Human-readable success message
  • status: Always “success” for successful requests
  • error.code: Machine-readable error code
  • error.message: Human-readable error message
  • error.details: Additional error information
  • status: Always “error” for failed requests

HTTP Status Codes

Success Codes

  • 200 OK: Successful GET, PUT, PATCH requests
  • 201 Created: Successful POST requests
  • 204 No Content: Successful DELETE requests

Error Codes

  • 400 Bad Request: Invalid request parameters
  • 401 Unauthorized: Authentication required
  • 403 Forbidden: Insufficient permissions
  • 404 Not Found: Resource not found
  • 429 Too Many Requests: Rate limit exceeded

Testing Your Setup

Verify Authentication

Make sure your authentication is working by generating a token or logging in successfully.

Test Basic Endpoint

Try a simple GET request to verify your setup is working correctly.

Check Response Format

Verify that you’re receiving responses in the expected format.

Handle Errors

Test error scenarios to ensure your error handling is working properly.

Code Examples

// External API Example
const response = await fetch('https://api.weir.ai/auth/token', {
  method: 'POST',
  headers: {
    'Authorization': 'Basic ' + btoa('client_id:secret_key'),
    'Content-Type': 'application/json'
  }
});

const data = await response.json();
console.log('Access Token:', data.data.accessToken);

// Use the token for subsequent requests
const apiResponse = await fetch('https://api.weir.ai/external/endpoint', {
  headers: {
    'Authorization': `Bearer ${data.data.accessToken}`,
    'Content-Type': 'application/json'
  }
});

Troubleshooting

Problem: Getting 401 Unauthorized errorsSolutions:
  • Check your credentials are correct
  • Ensure you’re using the right authentication method
  • Verify your access token hasn’t expired
  • Check the Authorization header format
Problem: Getting 400 Bad Request errorsSolutions:
  • Verify your request body is valid JSON
  • Check required parameters are included
  • Ensure parameter types are correct
  • Validate request headers
Problem: Getting 429 Too Many Requests errorsSolutions:
  • Check rate limit headers in responses
  • Implement exponential backoff
  • Reduce request frequency
  • Cache responses when possible

Next Steps

Congratulations! You’ve successfully made your first API call to the Weir AI API v1.0.1. You’re now ready to build powerful integrations with our platform.