> ## Documentation Index
> Fetch the complete documentation index at: https://docs.withleaf.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect to Stara Telemetry API

> Connect Stara Telemetry to Leaf. Get API credentials, obtain tokens, and attach them to a Leaf user for standardized field data.

This tutorial walks through connecting Stara's telemetry platform to Leaf. You'll get developer credentials from Stara, obtain API tokens, and attach them to a Leaf user. Stara provides field names, field boundaries, planting operations, as-applied operations, and machine information.

<Tip>
  [Magic Link](/components/magic-link) and [Leaf Link](/components/leaf-link) can handle Stara authentication for you. This tutorial covers the manual API flow.
</Tip>

## Before you start

* A Leaf account with a valid API token.
* A Leaf user created.
* A Stara developer account. Contact Stara at [servicos@stara.com.br](mailto:servicos@stara.com.br) or +55 054 99706-7292 to request API access. They'll provide a username and password.

## Step 1: Get your API key

Authenticate with Stara to get an API key:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://v2apitelemetria.telemetriastara.com.br/autenticacao" \
    -H "Content-Type: application/json" \
    -d '{
      "login": "your-stara-username",
      "password": "your-stara-password"
    }'
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://v2apitelemetria.telemetriastara.com.br/autenticacao",
      json={
          "login": "your-stara-username",
          "password": "your-stara-password"
      }
  )
  api_key = response.json()["apiKey"]
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch(
    "https://v2apitelemetria.telemetriastara.com.br/autenticacao",
    {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({
        login: "your-stara-username",
        password: "your-stara-password",
      }),
    }
  );
  const { apiKey } = await res.json();
  ```
</CodeGroup>

## Step 2: Get access and refresh tokens

Use the API key to generate tokens:

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://v2apitelemetria.telemetriastara.com.br/token" \
    -H "Content-Type: application/json" \
    -d '{
      "apiKey": "your-stara-api-key"
    }'
  ```

  ```python Python theme={null}
  token_response = requests.post(
      "https://v2apitelemetria.telemetriastara.com.br/token",
      json={"apiKey": api_key}
  )
  tokens = token_response.json()
  access_token = tokens["accessToken"]
  access_token_client = tokens["accessTokenClient"]
  refresh_token = tokens["refreshToken"]
  ```

  ```javascript JavaScript theme={null}
  const tokenRes = await fetch(
    "https://v2apitelemetria.telemetriastara.com.br/token",
    {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ apiKey }),
    }
  );
  const { accessToken, accessTokenClient, refreshToken } = await tokenRes.json();
  ```
</CodeGroup>

## Step 3: Attach credentials to the Leaf user

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/stara-credentials" \
    -H "Authorization: Bearer YOUR_LEAF_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "apiKey": "the-api-key-from-step-1",
      "accessToken": "the-access-token-from-step-2",
      "accessTokenClient": "the-access-token-client-from-step-2",
      "refreshToken": "the-refresh-token-from-step-2"
    }'
  ```

  ```python Python theme={null}
  response = requests.post(
      f"https://api.withleaf.io/services/usermanagement/api/users/{leaf_user_id}/stara-credentials",
      headers={"Authorization": f"Bearer {leaf_token}"},
      json={
          "apiKey": api_key,
          "accessToken": access_token,
          "accessTokenClient": access_token_client,
          "refreshToken": refresh_token
      }
  )
  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const res = await fetch(
    `https://api.withleaf.io/services/usermanagement/api/users/${leafUserId}/stara-credentials`,
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${leafToken}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        apiKey: apiKey,
        accessToken: accessToken,
        accessTokenClient: accessTokenClient,
        refreshToken: refreshToken,
      }),
    }
  );
  console.log(await res.json());
  ```
</CodeGroup>

Leaf manages token refresh automatically and begins syncing data.

## Step 4: Confirm the credentials are attached

Check the stored credentials for the Leaf user:

```bash cURL theme={null}
curl "https://api.withleaf.io/services/usermanagement/api/users/{leafUserId}/stara-credentials" \
  -H "Authorization: Bearer YOUR_LEAF_TOKEN"
```

If this worked, Leaf returns the Stara credential object with `apiKey`, `accessToken`, `accessTokenClient`, and `refreshToken`.

## What you built

You connected Stara Telemetry to a Leaf user. Leaf now syncs field names, boundaries, planting, and application data from Stara. Query the data through the [field operations quickstart](/guides/tutorials/field-operations-quickstart).

If you don't have field boundaries set up yet, start with the [fields overview](/fields/overview) and [uploading boundaries](/fields/uploading-boundaries) docs.

For the credentials schema and management endpoints, see the [Stara provider guide](/providers/stara) and the [provider credentials API reference](/api-reference/providers).
