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

# Auto Generate Purchase Orders

> Auto-generate purchase orders for stocks below PAR level.



## OpenAPI

````yaml post /inventory/purchase-orders/auto-generate
openapi: 3.1.0
info:
  title: Decoda API
  description: External API documentation for the Decoda Health platform.
  version: '1.0'
servers: []
security: []
paths:
  /inventory/purchase-orders/auto-generate:
    post:
      tags:
        - provider
        - inventory
      summary: Auto Generate Purchase Orders
      description: Auto-generate purchase orders for stocks below PAR level.
      operationId: >-
        auto_generate_purchase_orders_inventory_purchase_orders_auto_generate_post
      parameters:
        - name: TENANT
          in: header
          required: true
          schema:
            type: string
            title: Tenant
          description: The tenant you are making this request on behalf of
        - name: API-KEY
          in: header
          required: true
          schema:
            type: string
            title: Api-Key
          description: Your api key
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AutoGeneratePurchaseOrdersRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                items:
                  $ref: '#/components/schemas/PurchaseOrderResponse'
                type: array
                title: >-
                  Response Auto Generate Purchase Orders Inventory Purchase
                  Orders Auto Generate Post
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    AutoGeneratePurchaseOrdersRequest:
      properties:
        locationIds:
          items:
            type: string
          type: array
          title: Locationids
          description: List of location IDs to check stock levels for
      type: object
      required:
        - locationIds
      title: AutoGeneratePurchaseOrdersRequest
    PurchaseOrderResponse:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier for the purchase order
        supplierId:
          type: string
          title: Supplierid
          description: ID of the supplier
        status:
          $ref: '#/components/schemas/PurchaseOrderStatus'
          description: Status of the purchase order
          default: PENDING
        issueDate:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Issuedate
          description: Date when the purchase order was sent to supplier
        completedDate:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Completeddate
          description: Date when all shipments are DELIVERED (purchase order completed)
        supplier:
          anyOf:
            - $ref: '#/components/schemas/Supplier'
            - type: 'null'
          description: Optional supplier details
        lineItems:
          anyOf:
            - items:
                $ref: '#/components/schemas/PurchaseOrderLineItemWithDetails'
              type: array
            - type: 'null'
          title: Lineitems
          description: Line items with details
        notes:
          anyOf:
            - items:
                $ref: '#/components/schemas/PurchaseOrderNote'
              type: array
            - type: 'null'
          title: Notes
          description: Notes attached to this purchase order
        createdDate:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Createddate
          description: Date and time the purchase order was created
        updatedDate:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Updateddate
          description: Date and time the purchase order was last updated
        isArchived:
          type: boolean
          title: Isarchived
          description: Whether the purchase order is archived
          default: false
        leadTimeDays:
          anyOf:
            - type: integer
            - type: 'null'
          title: Leadtimedays
          description: >-
            Maximum lead time in days across all line items (estimated delivery
            time from order placement)
      type: object
      required:
        - supplierId
      title: PurchaseOrderResponse
      description: Purchase order response with computed lead time.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    PurchaseOrderStatus:
      type: string
      enum:
        - PENDING
        - PLACED
        - COMPLETED
        - CANCELLED
      title: PurchaseOrderStatus
      description: The status of a purchase order.
    Supplier:
      properties:
        name:
          type: string
          title: Name
          description: Name of the supplier
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          description: Optional description of the supplier
        website:
          anyOf:
            - type: string
            - type: 'null'
          title: Website
          description: Optional website of the supplier
        email:
          anyOf:
            - type: string
            - type: 'null'
          title: Email
          description: Optional email of the supplier
        preferredContactMethod:
          anyOf:
            - type: string
            - type: 'null'
          title: Preferredcontactmethod
          description: Optional preferred contact method
        phoneNumber:
          anyOf:
            - type: string
            - type: 'null'
          title: Phonenumber
          description: Optional phone number of the supplier
        addressLineOne:
          anyOf:
            - type: string
            - type: 'null'
          title: Addresslineone
          description: Optional first line of address
        addressLineTwo:
          anyOf:
            - type: string
            - type: 'null'
          title: Addresslinetwo
          description: Optional second line of address
        city:
          anyOf:
            - type: string
            - type: 'null'
          title: City
          description: Optional city
        state:
          anyOf:
            - type: string
            - type: 'null'
          title: State
          description: Optional state or province
        zipCode:
          anyOf:
            - type: string
            - type: 'null'
          title: Zipcode
          description: Optional ZIP or postal code
        country:
          anyOf:
            - type: string
            - type: 'null'
          title: Country
          description: Optional country
        shipmentTime:
          anyOf:
            - type: integer
            - type: 'null'
          title: Shipmenttime
          description: Shipment time in minutes
        isArchived:
          type: boolean
          title: Isarchived
          description: Whether the supplier is archived
          default: false
        defaultNotes:
          anyOf:
            - items:
                $ref: '#/components/schemas/SupplierNote'
              type: array
            - type: 'null'
          title: Defaultnotes
          description: Default notes for purchase orders
        id:
          type: string
          title: Id
          description: Unique identifier for the supplier
      type: object
      required:
        - name
      title: Supplier
    PurchaseOrderLineItemWithDetails:
      properties:
        supplierToStockUomId:
          type: string
          title: Suppliertostockuomid
          description: ID of the supplier-to-stock UOM
        locationId:
          type: string
          title: Locationid
          description: ID of the location
        quantity:
          type: number
          exclusiveMinimum: 0
          title: Quantity
          description: Quantity in the ordered UoM
        cost:
          anyOf:
            - type: integer
              minimum: 0
            - type: 'null'
          title: Cost
          description: Total line cost in cents (calculated from UOM price if not provided)
        id:
          type: string
          title: Id
          description: Unique identifier for the line item
        purchaseOrderId:
          type: string
          title: Purchaseorderid
          description: ID of the purchase order
        status:
          $ref: '#/components/schemas/PurchaseOrderLineItemStatus'
          description: Status of the line item
        quantityReceived:
          type: number
          minimum: 0
          title: Quantityreceived
          description: Quantity received in the ordered UoM
        createdDate:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Createddate
          description: Date and time the line item was created
        updatedDate:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Updateddate
          description: Date and time the line item was last updated
        supplierToStockUom:
          $ref: '#/components/schemas/PurchaseOrderLineItemSupplierToStockUom'
          description: Supplier-to-stock UOM details
        location:
          $ref: '#/components/schemas/LocationTinyWithName'
          description: Location details
      type: object
      required:
        - supplierToStockUomId
        - locationId
        - quantity
        - id
        - purchaseOrderId
        - status
        - quantityReceived
        - supplierToStockUom
        - location
      title: PurchaseOrderLineItemWithDetails
      description: Line item with denormalized supplier/stock info for display.
    PurchaseOrderNote:
      properties:
        name:
          anyOf:
            - type: string
              maxLength: 100
            - type: 'null'
          title: Name
          description: Optional title/label (e.g., 'Payment Method')
        content:
          type: string
          maxLength: 1000
          minLength: 1
          title: Content
          description: Content of the note
        id:
          type: string
          title: Id
          description: Unique identifier for the note
        purchaseOrderId:
          type: string
          title: Purchaseorderid
          description: ID of the purchase order
      type: object
      required:
        - content
        - id
        - purchaseOrderId
      title: PurchaseOrderNote
      description: Schema for a purchase order note response.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    SupplierNote:
      properties:
        name:
          anyOf:
            - type: string
              maxLength: 100
            - type: 'null'
          title: Name
          description: Optional title/label (e.g., 'Payment Method')
        content:
          type: string
          maxLength: 1000
          minLength: 1
          title: Content
          description: Content of the note
        id:
          type: string
          title: Id
          description: Unique identifier for the note
        supplierId:
          type: string
          title: Supplierid
          description: ID of the supplier
      type: object
      required:
        - content
        - id
        - supplierId
      title: SupplierNote
      description: Schema for a supplier note response.
    PurchaseOrderLineItemStatus:
      type: string
      enum:
        - PENDING
        - PARTIAL
        - DELIVERED
        - CANCELLED
      title: PurchaseOrderLineItemStatus
    PurchaseOrderLineItemSupplierToStockUom:
      properties:
        supplierPartNumber:
          type: string
          title: Supplierpartnumber
          description: Supplier part number for this stock
        uom:
          $ref: '#/components/schemas/Unit'
          description: Unit of measure
        conversionFactor:
          type: number
          exclusiveMinimum: 0
          title: Conversionfactor
          description: Base units per 1 UoM
          default: 1
        isDefault:
          type: boolean
          title: Isdefault
          description: Default UoM for this part number
          default: false
        displayLabel:
          anyOf:
            - type: string
            - type: 'null'
          title: Displaylabel
          description: Display label (e.g., 'Case of 200')
        price:
          anyOf:
            - type: integer
            - type: 'null'
          title: Price
          description: Price in cents per UoM
        leadTime:
          anyOf:
            - type: integer
              exclusiveMinimum: 0
            - type: 'null'
          title: Leadtime
          description: Lead time in days (must be > 0)
        id:
          type: string
          title: Id
          description: Unique identifier for the supplier-to-stock UOM
        supplierToStockId:
          type: string
          title: Suppliertostockid
          description: ID of the parent supplier-to-stock relationship
        createdDate:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Createddate
          description: Date the UOM was created
        updatedDate:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Updateddate
          description: Date the UOM was last updated
        isArchived:
          type: boolean
          title: Isarchived
          description: Whether the UOM is archived
          default: false
        supplierToStock:
          $ref: '#/components/schemas/PurchaseOrderLineItemSupplierToStock'
          description: Supplier-to-stock details
      type: object
      required:
        - supplierPartNumber
        - uom
        - id
        - supplierToStockId
        - supplierToStock
      title: PurchaseOrderLineItemSupplierToStockUom
    LocationTinyWithName:
      properties:
        id:
          type: string
          title: Id
        name:
          type: string
          title: Name
        isVirtual:
          type: boolean
          title: Isvirtual
      type: object
      required:
        - id
        - name
        - isVirtual
      title: LocationTinyWithName
      description: >-
        Location with name for analytics - avoids requiring eager loading
        everywhere.
    Unit:
      type: string
      enum:
        - AMPOULES
        - APPLICATORS
        - BOTTLES
        - BOXES
        - CAPSULES
        - CUPS
        - DOSES
        - G_PER_ML
        - GRAMS
        - IU
        - IU_PER_ML
        - OUNCES
        - FLUID_OUNCES
        - KG
        - KITS
        - LITERS
        - MCG
        - MG
        - MG_PER_ML
        - ML
        - MMOL
        - MICROGRAM_PER_ML
        - PACKS
        - PAIRS
        - PATCHES
        - PERCENTAGE
        - PIECES
        - POUCHES
        - ROLLS
        - SACHETS
        - SHEETS
        - SPRAYS
        - STRIPS
        - SYRINGES
        - TABLETS
        - TABLETS_PER_DAY
        - TESTS
        - TUBES
        - UNITS
        - VIALS
        - TREATMENTS
        - SESSIONS
        - PULSES
        - JOULES
        - CENTIMETERS
        - THREAD_COUNT
        - INJECTIONS
        - WRINKLE_UNITS
        - POUNDS
        - FEET
        - INCHES
      title: Unit
    PurchaseOrderLineItemSupplierToStock:
      properties:
        supplierId:
          type: string
          title: Supplierid
          description: ID of the supplier
        stockId:
          type: string
          title: Stockid
          description: ID of the stock
        id:
          type: string
          title: Id
          description: Unique identifier for the supplier-to-stock relationship
        stock:
          $ref: '#/components/schemas/StockTiny'
          description: Stock details
      type: object
      required:
        - supplierId
        - stockId
        - id
        - stock
      title: PurchaseOrderLineItemSupplierToStock
    StockTiny:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier for the stock
        name:
          type: string
          title: Name
          description: Name of the stock
        description:
          anyOf:
            - type: string
            - type: 'null'
          title: Description
          description: Optional description of the stock
        notes:
          anyOf:
            - type: string
            - type: 'null'
          title: Notes
          description: Notes about the stock
        category:
          anyOf:
            - type: string
            - type: 'null'
          title: Category
          description: Category name (references category.name)
        unit:
          $ref: '#/components/schemas/Unit'
          description: Unit of measurement
        minStockLevel:
          anyOf:
            - type: number
            - type: 'null'
          title: Minstocklevel
          description: Minimum stock level before alerting
        isArchived:
          type: boolean
          title: Isarchived
          description: Whether the stock is archived
          default: false
      type: object
      required:
        - name
        - unit
      title: StockTiny

````