# Quickstart

Start with your staging API token from [registration](/getting-started#registration).
Staging accounts and tokens are separate from production.

## 1. Check coverage and concurrency

Keep your token in an environment variable:

```shell
export MIARE_TOKEN="your-staging-token"

curl "https://ws.staging.miare.ir/area/third-party-api/v2/areas/" \
  --header "Authorization: Token $MIARE_TOKEN"
```

[List Areas](/api/public/area#list-areas) returns coverage polygons, your active trip count,
and your concurrency allowance. GeoJSON coordinates are ordered **longitude, latitude**;
API location objects use named `latitude` and `longitude` fields.

## 2. Create a trip

Send a pickup and one or more courses to [Create Trip](/api/public/delivery#create-trip).
A course describes a destination and its package. Set `pickup.deadline` to a future time
when the packages will be ready, including a timezone.

```python
import os
from datetime import datetime, timedelta, timezone

import requests

base_url = "https://ws.staging.miare.ir/trip-management/third-party-api/v2"
headers = {"Authorization": f"Token {os.environ['MIARE_TOKEN']}"}

response = requests.post(
    f"{base_url}/trips/",
    headers=headers,
    json={
        "pickup": {
            "name": "Example shop",
            "phone_number": "02100000000",
            "address": "Example pickup address, Tehran",
            "image": "https://example.com/shop.png",
            "location": {"latitude": 35.737004, "longitude": 51.413569},
            "deadline": (datetime.now(timezone.utc) + timedelta(minutes=30)).isoformat(),
        },
        "courses": [{
            "bill_number": "DEMO-100",
            "name": "Example recipient",
            "phone_number": "09000000000",
            "address": "Example delivery address, Tehran",
            "location": {"latitude": 35.740000, "longitude": 51.420000},
            "manifest_items": [{"name": "Example package", "quantity": 1}],
        }],
    },
)
response.raise_for_status()
trip = response.json()
print(trip["id"], trip["state"])
```

Use real pickup and recipient details and a pickup inside an area available to your account.
The values above are illustrative. Save the trip `id`, course IDs, and current `batch_id`.

:::note

Account configuration can require extra fields: `pickup.seller_id` for proxy invoicing,
or a five-digit course `delivery_code` for third-party Proof of Delivery. Automatic-batching
accounts can send only one course per trip. See [core concepts](/concepts) before enabling
round trips, boosting, or box requirements.

:::

## 3. Track changes and clean up

Read the trip with [Get Trip](/api/public/delivery#get-trip), or filter
[List Trips](/api/public/delivery#list-trips) by `bill_number` to find an order.
Pagination returns `data`, `next`, `previous`, and `total_count`; follow the next-page URL
until it is empty or null.

Staging has no active courier fleet. Cancel test trips with
[Cancel Trip](/api/public/delivery#cancel-trip) to free concurrency for further tests.

## 4. Receive events

Provide the technical team with your webhook URL, then follow
[Receiving webhooks](/guides/webhooks). Validate authorization, persist accepted events,
return `2XX`, and handle duplicates and out-of-order delivery.

Use the [webhook reference](/webhooks) for payloads and headers,
[Support integration](/guides/support) for delegated courier issues, and
[Accounting and invoices](/guides/accounting) for financial revisions and recovery.
Handle failures using stable [error codes](/errors).
