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

# Creating orders

> Look up the reference data, create an order, and send the customer to pay.

Creating an order needs the `orders:write` scope. Each step below links to its endpoint in the API reference.

## 1. Look up the reference data

| Data | Endpoint | Used as |
| - | - | - |
| Service levels and prices | `GET /orders/payment-plans` | `payment_plan_id` |
| Shipping methods | `GET /orders/shipping-methods` | `shipping_method_id` |
| Optional services | `GET /orders/upcharges` | `upcharges` codes |
| Cards | `GET /card-products?search=charizard` | `items[].card_product_id` |

Card search needs at least 2 characters and returns up to 50 results per page.

## 2. Create the order

```bash theme={null}
curl -X POST https://app.agscard.com/api/partner/v1/orders \
  -H "Authorization: Bearer ACCESS_TOKEN" \
  -H "X-Tenant: us" \
  -H "Idempotency-Key: 9f8c2b1e-order-1042" \
  -H "Content-Type: application/json" \
  -d '{
    "payment_plan_id": 1,
    "shipping_method_id": 1,
    "items": [
      { "card_product_id": 52291, "quantity": 2, "declared_value_per_unit": 150 }
    ],
    "upcharges": ["signature"],
    "shipping_address": {
      "first_name": "Jane",
      "last_name": "Doe",
      "address": "1 Main Street",
      "city": "Austin",
      "state": "TX",
      "zip": "73301",
      "phone": "5125550100"
    }
  }'
```

* **Items:** up to 100 lines, each with a quantity of 1 to 100. A line with a quantity of 2 becomes two cards in the order.
* **Shipping address:** required unless the shipping method is vault storage. The billing address defaults to the shipping address. Send `billing_address`, with the same fields, to use a different one.
* **Optional services:** send their codes in `upcharges`. Fees that apply automatically, such as the sports card surcharge, can't be requested.
* **Idempotency:** send an `Idempotency-Key` so a retried request can't create a second order. See [Idempotency](https://docs.agscard.com/idempotency.md).

A new order returns `201` with the order.

## 3. Send the customer to pay

New orders are created as `placed` with a `payment_status` of `pending`. While the order is unpaid, it has a `payment_url`:

```json theme={null}
{
  "data": {
    "id": 81234,
    "order_number": "RG000081234",
    "status": "placed",
    "payment_status": "pending",
    "payment_url": "https://app.agscard.com/dashboard/submissions/81234/pay",
    "grand_total": 64.0
  }
}
```

Send the customer to `payment_url` to pay on AGS. Once paid, `payment_url` is `null`.

## Rules that reject an order

These come back as a `422` with the `order_rejected` error code, and a message explaining the problem:

* A card's declared value is above the service level's maximum protection.
* The order's total declared value is over \$500 and `signature` isn't in `upcharges`.
* A declared value or the order total is too large to store.

## Follow the order

`GET /orders` lists the orders you created through the API for the account, newest first. `GET /orders/{id}` returns one with its cards. Both need the `orders:read` scope.

Your app sees only the orders it created. Orders the customer created on AGS or through other apps return `404`.

| `status` | Meaning |
| - | - |
| `placed` | Created and waiting for the cards to arrive |
| `confirmed` | Cards reviewed |
| `graded` | Cards graded |
| `assembled` | Graded cards slabbed and packed for shipment |
| `shipped` | On the way back to the customer |
| `cancelled` | Cancelled |

`payment_status` is `pending`, `due` or `paid`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.