{
  "openapi": "3.1.0",
  "info": {
    "title": "martcp agent commerce API",
    "version": "1.0.0",
    "description": "Search products from online stores that ship to Australia and create checkout links the user opens to pay on the seller's own store. No authentication. See /agents.md for a walkthrough."
  },
  "servers": [
    {
      "url": "https://www.martcp.com"
    }
  ],
  "paths": {
    "/v1/search": {
      "get": {
        "operationId": "searchProducts",
        "summary": "Search products across sellers",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "What the user wants"
          },
          {
            "name": "brand",
            "in": "query",
            "schema": {
              "type": "string",
              "maxLength": 100
            },
            "description": "Only this brand's products, e.g. Samsung"
          },
          {
            "name": "min_price",
            "in": "query",
            "schema": {
              "type": "number"
            },
            "description": "AUD, major units"
          },
          {
            "name": "max_price",
            "in": "query",
            "schema": {
              "type": "number"
            },
            "description": "AUD, major units"
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 25,
              "default": 10
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "next_cursor from the previous page"
          }
        ],
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "search_id": {
                      "type": "string"
                    },
                    "query": {
                      "type": "string"
                    },
                    "brand": {
                      "type": "string",
                      "description": "The brand filter, when one was given"
                    },
                    "results": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Offer"
                      }
                    },
                    "total_count": {
                      "type": "integer",
                      "description": "Approximate; not always present"
                    },
                    "next_cursor": {
                      "type": "string"
                    },
                    "sellers": {
                      "type": "object",
                      "description": "Store info for the sellers in this response, keyed by seller.id",
                      "additionalProperties": {
                        "$ref": "#/components/schemas/SellerInfo"
                      }
                    },
                    "notes": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Catalog unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/products/{product_id}": {
      "get": {
        "operationId": "getProduct",
        "summary": "Full product details, variants and seller policies",
        "parameters": [
          {
            "name": "product_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "seller",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "seller.id to limit to one seller"
          },
          {
            "name": "search_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Product with one offer per seller",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "product_id": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "offers": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Offer"
                      }
                    },
                    "sellers": {
                      "type": "object",
                      "description": "Store info for the sellers in this response, keyed by seller.id",
                      "additionalProperties": {
                        "$ref": "#/components/schemas/SellerInfo"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "502": {
            "description": "Catalog unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/carts": {
      "post": {
        "operationId": "createCarts",
        "summary": "Create checkout links (one per seller) for the user to pay",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "items"
                ],
                "properties": {
                  "search_id": {
                    "type": "string"
                  },
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 50,
                    "items": {
                      "type": "object",
                      "required": [
                        "variant_id"
                      ],
                      "properties": {
                        "variant_id": {
                          "type": "string"
                        },
                        "quantity": {
                          "type": "integer",
                          "minimum": 1,
                          "default": 1
                        }
                      }
                    }
                  },
                  "reason": {
                    "type": "string",
                    "maxLength": 500,
                    "description": "Why this offer was chosen (optional)"
                  },
                  "postcode": {
                    "type": "string",
                    "pattern": "^[0-9]{4}$",
                    "description": "The user's delivery postcode (optional), to price delivery. Never stored."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Carts created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "carts": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "cart_id": {
                            "type": "string"
                          },
                          "seller": {
                            "$ref": "#/components/schemas/Seller"
                          },
                          "items": {
                            "type": "array",
                            "items": {
                              "type": "object"
                            }
                          },
                          "subtotal": {
                            "$ref": "#/components/schemas/Money"
                          },
                          "discount": {
                            "allOf": [
                              {
                                "$ref": "#/components/schemas/Discount"
                              },
                              {
                                "type": "object",
                                "properties": {
                                  "amount": {
                                    "$ref": "#/components/schemas/Money"
                                  }
                                }
                              }
                            ]
                          },
                          "discounted_subtotal": {
                            "$ref": "#/components/schemas/Money"
                          },
                          "delivery": {
                            "type": "object",
                            "description": "Only when a postcode was given",
                            "properties": {
                              "postcode": {
                                "type": "string"
                              },
                              "options": {
                                "type": "array",
                                "items": {
                                  "type": "object",
                                  "properties": {
                                    "name": {
                                      "type": "string",
                                      "description": "Usually includes the delivery time"
                                    },
                                    "price": {
                                      "$ref": "#/components/schemas/Money"
                                    }
                                  }
                                }
                              },
                              "note": {
                                "type": "string",
                                "description": "Why delivery couldn't be priced, when it couldn't"
                              }
                            }
                          },
                          "estimated_total": {
                            "allOf": [
                              {
                                "$ref": "#/components/schemas/Money"
                              }
                            ],
                            "description": "Total after any discount code, with the cheapest delivery option"
                          },
                          "seller_info": {
                            "$ref": "#/components/schemas/SellerInfo"
                          },
                          "checkout_url": {
                            "type": "string",
                            "format": "uri",
                            "description": "Give this to the user"
                          }
                        }
                      }
                    },
                    "issues": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "instructions": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "No items could be added"
          },
          "502": {
            "description": "Catalog unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Money": {
        "type": "object",
        "properties": {
          "amount": {
            "type": "string",
            "example": "89.00",
            "description": "Decimal amount in major units"
          },
          "currency": {
            "type": "string",
            "example": "AUD"
          }
        },
        "required": [
          "amount",
          "currency"
        ]
      },
      "Seller": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "shop_91801911663"
          },
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "partner": {
            "type": "boolean"
          }
        }
      },
      "SellerInfo": {
        "type": "object",
        "description": "What the seller tells buyers about itself. Every field except name, website, provided_by and updated_on is optional; missing means unknown.",
        "properties": {
          "name": {
            "type": "string"
          },
          "website": {
            "type": "string",
            "format": "uri"
          },
          "legal_name": {
            "type": "string"
          },
          "abn": {
            "type": "string",
            "description": "Australian Business Number",
            "example": "51 824 753 556"
          },
          "location": {
            "type": "string"
          },
          "trading_since": {
            "type": "integer"
          },
          "about": {
            "type": "string"
          },
          "delivery": {
            "type": "object",
            "properties": {
              "dispatch": {
                "type": "string"
              },
              "time": {
                "type": "string"
              }
            }
          },
          "returns": {
            "type": "object",
            "properties": {
              "change_of_mind_days": {
                "type": "integer"
              },
              "summary": {
                "type": "string"
              }
            }
          },
          "support": {
            "type": "object",
            "properties": {
              "email": {
                "type": "string"
              },
              "phone": {
                "type": "string"
              },
              "hours": {
                "type": "string"
              },
              "tracking_url": {
                "type": "string",
                "format": "uri"
              },
              "contact_url": {
                "type": "string",
                "format": "uri"
              }
            }
          },
          "ratings": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "source": {
                  "type": "string"
                },
                "score": {
                  "type": "number"
                },
                "scale": {
                  "type": "number"
                },
                "count": {
                  "type": "integer"
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                },
                "as_of": {
                  "type": "string",
                  "format": "date"
                }
              }
            }
          },
          "provided_by": {
            "type": "string",
            "enum": [
              "seller"
            ]
          },
          "updated_on": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "Discount": {
        "type": "object",
        "description": "A discount code the seller offers through this service. It is added to checkout_url automatically.",
        "properties": {
          "code": {
            "type": "string",
            "example": "AGENTS10"
          },
          "percent_off": {
            "type": "number",
            "example": 10
          },
          "expires_on": {
            "type": "string",
            "format": "date",
            "description": "Last day the code works, if it ends"
          }
        },
        "required": [
          "code",
          "percent_off"
        ]
      },
      "Variant": {
        "type": "object",
        "properties": {
          "variant_id": {
            "type": "string",
            "example": "v_53509308055919"
          },
          "title": {
            "type": "string"
          },
          "sku": {
            "type": "string"
          },
          "price": {
            "$ref": "#/components/schemas/Money"
          },
          "discounted_price": {
            "$ref": "#/components/schemas/Money",
            "description": "Price after the seller's discount code; absent if the code doesn't cover this variant"
          },
          "available": {
            "type": "boolean"
          },
          "options": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      },
      "Offer": {
        "type": "object",
        "properties": {
          "position": {
            "type": "integer"
          },
          "featured": {
            "type": "boolean",
            "description": "Partner seller placed first"
          },
          "product_id": {
            "type": "string",
            "example": "p_1ksiweeFXz1plDhO3cO8jq"
          },
          "title": {
            "type": "string"
          },
          "seller": {
            "$ref": "#/components/schemas/Seller"
          },
          "price": {
            "$ref": "#/components/schemas/Money"
          },
          "list_price": {
            "$ref": "#/components/schemas/Money"
          },
          "discounted_price": {
            "$ref": "#/components/schemas/Money",
            "description": "What the user pays after the seller's discount code. Compare on this when present."
          },
          "discount": {
            "$ref": "#/components/schemas/Discount"
          },
          "available": {
            "type": "boolean"
          },
          "image": {
            "type": "string",
            "format": "uri"
          },
          "url": {
            "type": "string",
            "format": "uri",
            "description": "Product page"
          },
          "highlights": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "description": {
            "type": "string",
            "description": "Product detail endpoint only"
          },
          "policies": {
            "type": "array",
            "description": "Product detail endpoint only",
            "items": {
              "type": "object",
              "properties": {
                "type": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                }
              }
            }
          },
          "variant_count": {
            "type": "integer"
          },
          "variants": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Variant"
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}