> ## 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.

# Create an order

> Creates a pending order for the customer, who pays for it in our app through the returned payment_url. A replayed Idempotency-Key returns the original order with a 200 and the Idempotent-Replayed header.



## OpenAPI

````yaml /openapi.json post /orders
openapi: 3.1.2
info:
  title: Robograding
  version: 1.0.0
servers:
  - url: https://app.agscard.com/api/partner/v1
security:
  - http: []
tags:
  - name: Profile
  - name: Card products
  - name: Orders
paths:
  /orders:
    post:
      tags:
        - Orders
      summary: Create an order
      description: >-
        Creates a pending order for the customer, who pays for it in our app
        through the returned payment_url. A replayed Idempotency-Key returns the
        original order with a 200 and the Idempotent-Replayed header.
      operationId: createOrder
      parameters:
        - name: Idempotency-Key
          in: header
          schema:
            type: string
        - name: X-Tenant
          in: header
          schema:
            type: string
            enum:
              - us
              - gb
              - br
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/StoreOrderRequest'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/OrderResource'
                required:
                  - data
        '201':
          description: '`OrderResource`'
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/OrderResource'
                required:
                  - data
        '401':
          $ref: '#/components/responses/AuthenticationException'
        '409':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        const: idempotency_key_in_use
                      message:
                        type: string
                    required:
                      - code
                      - message
                required:
                  - error
        '422':
          description: Validation error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - validation_failed
                          - order_rejected
                          - idempotency_key_reused
                      message:
                        type: string
                      errors:
                        type: object
                        additionalProperties:
                          type: array
                          items:
                            type: string
                    required:
                      - code
                      - message
                required:
                  - error
components:
  schemas:
    StoreOrderRequest:
      type: object
      description: >-
        A partner order uses flat IDs and inline addresses. Orders shipped to
        the customer need a shipping address;

        the billing address defaults to it.
      properties:
        payment_plan_id:
          type: integer
        shipping_method_id:
          type: integer
        items:
          type: array
          items:
            type: object
            properties:
              card_product_id:
                type: integer
              quantity:
                type: integer
                minimum: 1
                maximum: 100
              declared_value_per_unit:
                type: integer
                minimum: 0
            required:
              - card_product_id
              - quantity
              - declared_value_per_unit
          minItems: 1
          maxItems: 100
        upcharges:
          type: array
          items:
            type: string
          uniqueItems: true
        shipping_address:
          type: object
          properties:
            first_name:
              type: string
              maxLength: 255
            last_name:
              type: string
              maxLength: 255
            address:
              type: string
              maxLength: 255
            address_2:
              type:
                - string
                - 'null'
              maxLength: 255
            city:
              type: string
              maxLength: 255
            state:
              type: string
              maxLength: 255
            zip:
              type: string
              maxLength: 20
            phone:
              type: string
              maxLength: 30
            country_code:
              type:
                - string
                - 'null'
        billing_address:
          type: object
          properties:
            first_name:
              type: string
              maxLength: 255
            last_name:
              type: string
              maxLength: 255
            address:
              type: string
              maxLength: 255
            address_2:
              type:
                - string
                - 'null'
              maxLength: 255
            city:
              type: string
              maxLength: 255
            state:
              type: string
              maxLength: 255
            zip:
              type: string
              maxLength: 20
            phone:
              type: string
              maxLength: 30
            country_code:
              type:
                - string
                - 'null'
      required:
        - payment_plan_id
        - shipping_method_id
        - items
      title: StoreOrderRequest
    OrderResource:
      type: object
      properties:
        id:
          type: integer
        order_number:
          type:
            - string
            - 'null'
        status:
          type: string
        payment_status:
          type: string
        payment_url:
          type:
            - string
            - 'null'
        payment_plan_id:
          type: integer
        price_per_card:
          type: number
        turnaround:
          type: string
        shipping_method:
          anyOf:
            - $ref: '#/components/schemas/ShippingMethodResource'
            - type: 'null'
        number_of_cards:
          type: integer
        upcharges:
          type: array
          items:
            type: object
            properties:
              code:
                type: string
              amount:
                type: number
            required:
              - code
              - amount
        service_fee:
          type:
            - number
            - 'null'
        shipping_fee:
          type:
            - number
            - 'null'
        upcharges_fee:
          type: number
        discounted_amount:
          type:
            - number
            - 'null'
        grand_total:
          type:
            - number
            - 'null'
        items:
          type: array
          items:
            $ref: '#/components/schemas/OrderItemResource'
        created_at:
          type:
            - string
            - 'null'
      required:
        - id
        - order_number
        - status
        - payment_status
        - payment_url
        - payment_plan_id
        - price_per_card
        - turnaround
        - shipping_method
        - number_of_cards
        - upcharges
        - service_fee
        - shipping_fee
        - upcharges_fee
        - discounted_amount
        - grand_total
        - created_at
      title: OrderResource
    ShippingMethodResource:
      type: object
      properties:
        id:
          type: integer
        code:
          type: string
        name:
          type: string
      required:
        - id
        - code
        - name
      title: ShippingMethodResource
    OrderItemResource:
      type: object
      properties:
        id:
          type: integer
        card_product_id:
          type: integer
        card_name:
          type: string
        declared_value:
          type: number
      required:
        - id
        - card_product_id
        - card_name
        - declared_value
      title: OrderItemResource
  responses:
    AuthenticationException:
      description: Unauthenticated
      content:
        application/json:
          schema:
            type: object
            properties:
              error:
                type: object
                properties:
                  code:
                    type: string
                    enum:
                      - unauthenticated
                  message:
                    type: string
                required:
                  - code
                  - message
            required:
              - error
  securitySchemes:
    http:
      type: http
      scheme: bearer

````

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