# Getting Started

import { Card, CardHeader, CardTitle, CardDescription } from "zudoku/ui/Card.js";

This guide shows the shortest path to your first successful Kordiam API request.

## Prerequisites

- A Kordiam account
- Client credentials (client ID and client secret). If you do not have them yet, generate them on the [API Page](https://kordiam.app/apiPage.htm) (you need admin rights to do this).

## Base URL

All API requests are made to:

```text title="Base URL"
https://api.kordiam.app/api/v2
```

## Your First Request

<Stepper>

1. **Obtain an access token**

   Exchange your client credentials for a bearer access token:

   ```bash title="Request a token"
   curl -X POST https://api.kordiam.app/api/v2/auth/token \
     -H "Content-Type: application/json" \
     -d '{
       "client_id": "your-client-id",
       "client_secret": "your-client-secret",
       "grant_type": "client_credentials"
     }'
   ```

   The response contains your access token:

   ```json title="Response"
   {
     "access_token": "eyJhbGciOi...",
     "token_type": "Bearer",
     "expires_in": 3600,
     "scope": "api.read api.write",
     "refresh_token": "dGhpcyBpcyBh..."
   }
   ```

   :::tip{title="Schedule refresh from expires_in"}
   Save the returned `access_token` and use the returned `expires_in` value when scheduling refresh logic instead of assuming a fixed token lifetime.
   :::

1. **Make your first API call**

   Use the access token in the `Authorization` header:

   ```bash title="List elements"
   ACCESS_TOKEN="eyJhbGciOi..."

   curl https://api.kordiam.app/api/v2/elements \
     -H "Authorization: Bearer $ACCESS_TOKEN"
   ```

   This first request returns a paginated element list. Follow `nextCursor` from the response to
   walk additional pages. The response shape and available query parameters are documented in the
   [API reference](/api), and shared pagination patterns are covered in
   [Querying Lists](/docs/guides/api-conventions/querying-lists).

</Stepper>

:::rocket{title="You're connected"}
You've issued a token and made an authenticated call. The guides below cover the data model, auth
lifecycle, and conventions you'll need for a full integration.
:::

## Next Steps

<div className="grid gap-4 sm:grid-cols-2 mt-6 not-prose">
  <a href="/docs/getting-started/editorial-concepts" className="no-underline">
    <Card className="h-full transition-colors hover:border-primary">
      <CardHeader>
        <CardTitle>Editorial Concepts</CardTitle>
        <CardDescription>Kordiam terms and workflow meaning</CardDescription>
      </CardHeader>
    </Card>
  </a>
  <a href="/docs/getting-started/data-model" className="no-underline">
    <Card className="h-full transition-colors hover:border-primary">
      <CardHeader>
        <CardTitle>Resource Model</CardTitle>
        <CardDescription>How the main API resources fit together</CardDescription>
      </CardHeader>
    </Card>
  </a>
  <a href="/docs/migration-from-v1/index" className="no-underline">
    <Card className="h-full transition-colors hover:border-primary">
      <CardHeader>
        <CardTitle>Migrating from v1</CardTitle>
        <CardDescription>How to plan a v1-to-v2 integration migration</CardDescription>
      </CardHeader>
    </Card>
  </a>
  <a href="/docs/guides/api-conventions/querying-lists" className="no-underline">
    <Card className="h-full transition-colors hover:border-primary">
      <CardHeader>
        <CardTitle>Querying Lists</CardTitle>
        <CardDescription>Filtering, sorting, and pagination</CardDescription>
      </CardHeader>
    </Card>
  </a>
  <a href="/docs/getting-started/authentication" className="no-underline">
    <Card className="h-full transition-colors hover:border-primary">
      <CardHeader>
        <CardTitle>Authentication</CardTitle>
        <CardDescription>Token lifecycle and refresh flows</CardDescription>
      </CardHeader>
    </Card>
  </a>
  <a href="/docs/guides/api-conventions/error-handling" className="no-underline">
    <Card className="h-full transition-colors hover:border-primary">
      <CardHeader>
        <CardTitle>Error Handling</CardTitle>
        <CardDescription>Understanding error responses</CardDescription>
      </CardHeader>
    </Card>
  </a>
  <a href="/docs/guides/api-conventions/write-semantics" className="no-underline">
    <Card className="h-full transition-colors hover:border-primary">
      <CardHeader>
        <CardTitle>Write Semantics</CardTitle>
        <CardDescription>How POST, PUT, PATCH, and DELETE behave</CardDescription>
      </CardHeader>
    </Card>
  </a>
  <a href="/api" className="no-underline">
    <Card className="h-full transition-colors hover:border-primary">
      <CardHeader>
        <CardTitle>API Reference</CardTitle>
        <CardDescription>Full endpoint documentation</CardDescription>
      </CardHeader>
    </Card>
  </a>
</div>
