# SMKlog Quote API workflows — Arazzo 1.0.1.
#
# Generated by scripts/build_api_artifacts.mjs; every operationId, parameter,
# body field and response pointer is checked against the live OpenAPI
# document (https://quote-api.smklog.com/openapi.json) before this file is written.
arazzo: '1.0.1'
info:
  title: SMKlog Quote API workflows
  summary: 'The sequences an agent runs against the SMKlog Quote API, from a quote to a tracked label.'
  description: 'Written by SMKlog from what the operations do and checked against the live contract on every build: quote to label (the human pays on smklog.com), one session per order of your own keyed on external_id, refund status, withdrawing an unopened link, and the holiday ship-by check. Agents price and prepare checkout; a human always completes payment.'
  version: '1.6.0'
sourceDescriptions:
  - name: quoteApi
    url: 'https://quote-api.smklog.com/openapi.json'
    type: openapi
workflows:
  - workflowId: quote-to-label
    summary: 'Quote a parcel, hand the checkout to a human, wait for the label, then track it'
    description: 'The whole path an agent drives: price the item between two postal codes, open a payment session on the quote (anchored to the first rate, best value first; the human may still pick another service at checkout), give handoff_url to the human, then read the session until the label is bought and track the parcel. Payment always happens on smklog.com. Polling every 15 minutes is the fallback; a callback_url on the session gets the same stages as signed webhooks (see the AsyncAPI document).'
    inputs:
      type: object
      required:
        - product
        - quantity
        - from_postal_code
        - to_postal_code
      properties:
        product:
          type: string
          description: 'The item in plain words, e.g. "cast iron skillet, 12 inch"'
        quantity:
          type: integer
          minimum: 1
          description: 'How many of the item ship together; 1 for a single item'
        from_postal_code:
          type: string
          description: US ZIP the parcel ships from
        to_postal_code:
          type: string
          description: ZIP or postal code it ships to
        to_country_code:
          type: string
          enum:
            - US
            - CA
            - GB
            - DE
            - AU
          default: US
          description: Destination country
    steps:
      - stepId: getQuote
        description: 'Live rates for the parcel; mode must be parcel_label_ready for a checkout to follow.'
        operationId: getParcelQuote
        requestBody:
          contentType: application/json
          payload:
            product: '$inputs.product'
            quantity: '$inputs.quantity'
            from_postal_code: '$inputs.from_postal_code'
            to_postal_code: '$inputs.to_postal_code'
            to_country_code: '$inputs.to_country_code'
        successCriteria:
          - condition: '$statusCode == 200'
          - condition: '$response.body#/mode == ''parcel_label_ready'''
        outputs:
          quote_id: '$response.body#/quote_id'
          service: '$response.body#/rates/0/service'
          amount: '$response.body#/rates/0/amount'
          mode: '$response.body#/mode'
      - stepId: openCheckout
        description: 'A payment session on the quote; give handoff_url to the human, who pays on smklog.com.'
        operationId: createPaymentSession
        requestBody:
          contentType: application/json
          payload:
            quote_id: '$steps.getQuote.outputs.quote_id'
            service: '$steps.getQuote.outputs.service'
        successCriteria:
          - condition: '$statusCode == 200'
        outputs:
          session_id: '$response.body#/session_id'
          handoff_url: '$response.body#/handoff_url'
          amount: '$response.body#/amount'
      - stepId: waitForLabel
        description: 'Read the session until the label is bought. A cancelled or refunded session ends the workflow; anything earlier is read again in 15 minutes, for up to a day.'
        operationId: getCheckoutStatus
        parameters:
          - name: session_id
            in: path
            value: '$steps.openCheckout.outputs.session_id'
        successCriteria:
          - condition: '$statusCode == 200'
          - context: '$response.body#/status'
            condition: '^(label_ready|delivered)$'
            type: regex
        onFailure:
          - name: sessionEnded
            type: end
            criteria:
              - context: '$response.body#/status'
                condition: '^(cancelled|refunded)$'
                type: regex
          - name: notYet
            type: retry
            retryAfter: 900
            retryLimit: 96
        outputs:
          status: '$response.body#/status'
          tracking_number: '$response.body#/checkout/tracking_number'
          next: '$response.body#/next'
      - stepId: track
        description: 'Scan events for the label; tracking answers only for labels bought on smklog.com.'
        operationId: trackParcel
        parameters:
          - name: tracking_number
            in: path
            value: '$steps.waitForLabel.outputs.tracking_number'
        successCriteria:
          - condition: '$statusCode == 200'
        outputs:
          tracking_status: '$response.body#/tracking/status'
          estimated_delivery: '$response.body#/tracking/estimated_delivery'
    outputs:
      session_id: '$steps.openCheckout.outputs.session_id'
      handoff_url: '$steps.openCheckout.outputs.handoff_url'
      tracking_number: '$steps.waitForLabel.outputs.tracking_number'
      tracking_status: '$steps.track.outputs.tracking_status'
      estimated_delivery: '$steps.track.outputs.estimated_delivery'
  - workflowId: sync-order-session
    summary: 'Keep one payment session per order of your own, keyed on external_id'
    description: 'Create or re-price the session that belongs to your order: PUT is keyed on your external_id, needs a bearer token (any agent registers its own client at POST /oauth/register and takes a token from /oauth/token), and an Idempotency-Key makes a retried call answer the stored result. 201 means created, 200 updated; 409 means the human already started checkout, and the session is then read, not changed.'
    inputs:
      type: object
      required:
        - access_token
        - external_id
        - idempotency_key
        - product
        - from_zip
        - to_zip
      properties:
        access_token:
          type: string
          description: 'Bearer token from POST https://quote-api.smklog.com/oauth/token (client_credentials)'
        external_id:
          type: string
          description: 'Your own order id; the same value updates the same session'
        idempotency_key:
          type: string
          description: 'A fresh key per logical change; repeat it only when retrying the same call'
        product:
          type: string
          description: The item in plain words
        from_zip:
          type: string
          description: US ZIP the parcel ships from
        to_zip:
          type: string
          description: ZIP or postal code it ships to
        to_country:
          type: string
          enum:
            - US
            - CA
            - GB
            - DE
            - AU
          default: US
          description: Destination country
        quantity:
          type: integer
          minimum: 1
          default: 1
          description: How many of the item ship together
    steps:
      - stepId: upsertSession
        description: Create or re-price the session stored under external_id.
        operationId: upsertPaymentSession
        parameters:
          - name: external_id
            in: path
            value: '$inputs.external_id'
          - name: Idempotency-Key
            in: header
            value: '$inputs.idempotency_key'
          - name: Authorization
            in: header
            value: 'Bearer {$inputs.access_token}'
        requestBody:
          contentType: application/json
          payload:
            product: '$inputs.product'
            from_zip: '$inputs.from_zip'
            to_zip: '$inputs.to_zip'
            to_country: '$inputs.to_country'
            quantity: '$inputs.quantity'
        successCriteria:
          - condition: '$statusCode == 200 || $statusCode == 201'
        onFailure:
          - name: humanAlreadyInCheckout
            type: end
            criteria:
              - condition: '$statusCode == 409'
        outputs:
          session_id: '$response.body#/session_id'
          handoff_url: '$response.body#/handoff_url'
          created: '$response.body#/created'
          amount: '$response.body#/amount'
      - stepId: readSession
        description: Where the checkout of this session stands.
        operationId: getCheckoutStatus
        parameters:
          - name: session_id
            in: path
            value: '$steps.upsertSession.outputs.session_id'
        successCriteria:
          - condition: '$statusCode == 200'
        outputs:
          status: '$response.body#/status'
          next: '$response.body#/next'
    outputs:
      session_id: '$steps.upsertSession.outputs.session_id'
      handoff_url: '$steps.upsertSession.outputs.handoff_url'
      created: '$steps.upsertSession.outputs.created'
      status: '$steps.readSession.outputs.status'
  - workflowId: check-refund
    summary: Find out whether the payment behind a session was refunded
    description: 'Read the session first: nothing paid means nothing to refund. For a paid session, the refund status says whether a refund was requested, is under review, declined or done, and how much came back; unused USPS labels are refunded automatically under the policy the answer carries.'
    inputs:
      type: object
      required:
        - session_id
      properties:
        session_id:
          type: string
          description: 'The session_id a payment-session call returned (as_...)'
    steps:
      - stepId: readSession
        description: Only a paid session can have a refund.
        operationId: getCheckoutStatus
        parameters:
          - name: session_id
            in: path
            value: '$inputs.session_id'
        successCriteria:
          - condition: '$statusCode == 200'
          - context: '$response.body#/status'
            condition: '^(paid|label_ready|delivered|refunded)$'
            type: regex
        onFailure:
          - name: nothingPaid
            type: end
        outputs:
          status: '$response.body#/status'
      - stepId: readRefund
        description: The refund of the payment behind the session.
        operationId: getRefundStatus
        parameters:
          - name: session_id
            in: path
            value: '$inputs.session_id'
        successCriteria:
          - condition: '$statusCode == 200'
        outputs:
          refund_status: '$response.body#/status'
          amount_paid: '$response.body#/amount_paid'
          amount_refunded: '$response.body#/amount_refunded'
          next: '$response.body#/next'
    outputs:
      session_status: '$steps.readSession.outputs.status'
      refund_status: '$steps.readRefund.outputs.refund_status'
      amount_refunded: '$steps.readRefund.outputs.amount_refunded'
  - workflowId: cancel-unopened-link
    summary: Withdraw a checkout link the human has not opened yet
    description: 'A session can be cancelled only while it is awaiting_checkout. Read it first; once the human has opened checkout the link stands, and a paid order is a refund matter for support, not a cancel.'
    inputs:
      type: object
      required:
        - session_id
      properties:
        session_id:
          type: string
          description: 'The session_id to withdraw (as_...)'
    steps:
      - stepId: readSession
        description: Cancel only what the human has not opened.
        operationId: getCheckoutStatus
        parameters:
          - name: session_id
            in: path
            value: '$inputs.session_id'
        successCriteria:
          - condition: '$statusCode == 200'
          - condition: '$response.body#/status == ''awaiting_checkout'''
        onFailure:
          - name: alreadyOpened
            type: end
        outputs:
          status: '$response.body#/status'
      - stepId: cancelSession
        description: The handoff link stops binding a checkout to this session.
        operationId: cancelPaymentSession
        parameters:
          - name: session_id
            in: path
            value: '$inputs.session_id'
        successCriteria:
          - condition: '$statusCode == 200'
        outputs:
          status: '$response.body#/status'
          cancelled_at: '$response.body#/cancelled_at'
    outputs:
      status: '$steps.cancelSession.outputs.status'
      cancelled_at: '$steps.cancelSession.outputs.cancelled_at'
  - workflowId: holiday-delivery-check
    summary: 'Before the holidays: the carriers’ ship-by dates, then live rates to compare against them'
    description: 'Read the ship-by dates USPS and FedEx publish for delivery by Christmas (UPS publishes none), then quote the parcel. Compare each rate’s delivery_days (the transit days the carrier quoted) with the carrier’s deliver_by date: the dates are the carriers’ own recommendations, never a guarantee.'
    inputs:
      type: object
      required:
        - product
        - quantity
        - from_postal_code
        - to_postal_code
      properties:
        product:
          type: string
          description: The item in plain words
        quantity:
          type: integer
          minimum: 1
          description: 'How many of the item ship together; 1 for a single item'
        from_postal_code:
          type: string
          description: US ZIP the parcel ships from
        to_postal_code:
          type: string
          description: US ZIP it ships to
    steps:
      - stepId: readDeadlines
        description: 'This season’s ship-by dates per carrier and service, and whether the season is over.'
        operationId: getHolidayShippingDeadlines
        successCriteria:
          - condition: '$statusCode == 200'
        outputs:
          carriers: '$response.body#/carriers'
          today: '$response.body#/today'
          season_over: '$response.body#/season_over'
      - stepId: getQuote
        description: 'Live rates with each service’s delivery_days, the transit days the carrier quoted (a date only where the carrier gives one).'
        operationId: getParcelQuote
        requestBody:
          contentType: application/json
          payload:
            product: '$inputs.product'
            quantity: '$inputs.quantity'
            from_postal_code: '$inputs.from_postal_code'
            to_postal_code: '$inputs.to_postal_code'
        successCriteria:
          - condition: '$statusCode == 200'
        outputs:
          rates: '$response.body#/rates'
          quote_id: '$response.body#/quote_id'
    outputs:
      deadlines: '$steps.readDeadlines.outputs.carriers'
      season_over: '$steps.readDeadlines.outputs.season_over'
      rates: '$steps.getQuote.outputs.rates'
      quote_id: '$steps.getQuote.outputs.quote_id'
x-provenance:
  method: published
  publisher: 'SMKlog (SMKLOG-2022 LLC)'
  source: 'https://smklog.com/developers/arazzo.yaml'
  published: '2026-11-26'
