# Getting Started

> Authenticate with the ZopNight API and make your first request — base URL, login flow, response envelope, pagination, and a sample resource listing call.

Source: https://zop.dev/developer-docs/overview/getting-started

---

This guide walks you through authenticating with the ZopNight API and making your first request.

## Prerequisites

- A ZopNight account with at least one organization
- At least one connected cloud account (AWS, GCP, or Azure)
- An API client or `curl` for making HTTP requests

## Base URL

All API requests are made to the gateway endpoint:

```plaintext
https://zopnight.com/api
```

**Info**

You do not need to include your organization ID in API requests. The gateway extracts it
from your JWT token and automatically injects it into the request path before routing to
backend services.

## Authentication

First, obtain an access token by logging in. ZopNight supports email/password, Google, GitHub, and SAML authentication.

### Step 1: Login

```bash title="Request"
curl -X POST https://zopnight.com/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "you@company.com",
    "password": "your-password",
    "provider": "email"
  }'
```

```json title="Response"
{
  "data": {
    "accessToken": "eyJhbGciOiJSUzI1NiIs...",
    "refreshToken": "dGhpcyBpcyBhIHJlZnJl...",
    "tenants": [
      {
        "id": "org_abc123",
        "name": "My Organization"
      }
    ],
    "user": {
      "email": "you@company.com",
      "name": "Your Name"
    }
  }
}
```

### Step 2: Use the Token

Include the access token in all subsequent requests via the `Authorization` header:

```bash title="Authenticated request"
curl https://zopnight.com/api/resources \
  -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIs..."
```

See the full [Authentication](https://zop.dev/docs/authentication) guide for token refresh, SSO, and more.

## Response Format

All API responses are wrapped in a standard envelope:

```json title="Success response"
{
  "data": {
    "id": "sch_abc123",
    "name": "Business Hours"
  }
}
```

```json title="Error response"
{
  "error": "schedule not found"
}
```

## Pagination

List endpoints support pagination via query parameters:

| Parameter | Type | Description |
|---|---|---|
| `page` | integer | Page number (default: 1) |
| `limit` | integer | Items per page (default: 20) |
| `sort_by` | string | Field to sort by |
| `sort_order` | string | `asc` or `desc` |

```bash title="Example"
curl "https://zopnight.com/api/resources?page=2&limit=50&sort_by=name&sort_order=asc" \
  -H "Authorization: Bearer <token>"
```

## Your First API Call

Let's list your discovered cloud resources:

```bash title="List resources"
curl https://zopnight.com/api/resources \
  -H "Authorization: Bearer <token>"
```

```json title="Response"
{
  "data": [
    {
      "id": "res_001",
      "name": "web-server-prod",
      "uid": "i-0abc123def456",
      "type": "aws-ec2",
      "provider": "aws",
      "region": "us-east-1",
      "status": "running",
      "instanceType": "t3.medium",
      "schedulable": true,
      "tags": { "Environment": "production" }
    }
  ]
}
```

## Next Steps

<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(220px, 1fr))', gap: '0.75rem' }}>
  {[
    { to: '/docs/cloud-accounts', title: 'Connect a Cloud Account', desc: 'Add your AWS, GCP, or Azure credentials' },
    { to: '/docs/schedules', title: 'Create a Schedule', desc: 'Set up automated start/stop rules' },
    { to: '/docs/resources', title: 'Explore Resources', desc: 'Filter and search your cloud inventory' },
    { to: '/docs/cloud-support', title: 'Cloud Support Matrix', desc: 'See supported resource types per provider' },
  ].map((card) => (
    <a key={card.to} href={card.to} className="link-card">
      <h3>{card.title}</h3>
      <p>{card.desc}</p>
    </a>
  ))}
</div>
