{
  "openapi": "3.1.0",
  "info": {
    "title": "Neptune Integration API",
    "version": "1.0.0",
    "description": "Sync catalogs, stock and orders between your platform or website and Neptune (Neptune Shopping stores and App Manager brands). Full guide: https://neptune.tn/developers/"
  },
  "servers": [
    {
      "url": "https://neptune.tn/api/integrations/v1"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Custom key (npk_...) or OAuth access token (npat_...)."
      },
      "oauth": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://partner.neptune.tn/integrations/oauth/authorize/",
            "tokenUrl": "https://neptune.tn/api/integrations/v1/oauth/token",
            "scopes": {
              "read_products": "View your products",
              "write_products": "Create and edit your products",
              "read_inventory": "View your inventory",
              "write_inventory": "Update your inventory",
              "read_orders": "View your orders and your customers' delivery details",
              "write_orders": "Update the status of your orders"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "examples": [
                  "missing_scope"
                ]
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "object"
              }
            }
          }
        }
      },
      "ProductInput": {
        "type": "object",
        "required": [
          "title",
          "price"
        ],
        "properties": {
          "title": {
            "type": "string",
            "maxLength": 200
          },
          "description": {
            "type": "string",
            "maxLength": 20000,
            "description": "Plain text. HTML tags are removed."
          },
          "price": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ]
          },
          "compare_at_price": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "draft",
              "archived"
            ],
            "default": "draft"
          },
          "track_inventory": {
            "type": "boolean",
            "default": true
          },
          "quantity": {
            "type": "integer",
            "minimum": 0,
            "maximum": 1000000,
            "description": "Stock when the product has no variants."
          },
          "weight": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ],
            "description": "Kilograms."
          },
          "category_id": {
            "type": "integer",
            "description": "Neptune Shopping stores only."
          },
          "images": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "string",
              "format": "uri"
            }
          },
          "options": {
            "type": "array",
            "maxItems": 3,
            "items": {
              "type": "object",
              "required": [
                "name",
                "values"
              ],
              "properties": {
                "name": {
                  "type": "string",
                  "maxLength": 60
                },
                "values": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "maxLength": 50
                  }
                }
              }
            }
          },
          "variants": {
            "type": "array",
            "maxItems": 100,
            "items": {
              "type": "object",
              "required": [
                "external_id"
              ],
              "properties": {
                "external_id": {
                  "type": "string",
                  "maxLength": 255
                },
                "option1": {
                  "type": "string"
                },
                "option2": {
                  "type": "string"
                },
                "option3": {
                  "type": "string"
                },
                "price": {
                  "type": "string",
                  "pattern": "^\\d+(\\.\\d{1,2})?$",
                  "examples": [
                    "49.90"
                  ]
                },
                "compare_at_price": {
                  "type": "string",
                  "pattern": "^\\d+(\\.\\d{1,2})?$",
                  "examples": [
                    "49.90"
                  ]
                },
                "sku": {
                  "type": "string",
                  "maxLength": 64
                },
                "quantity": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 1000000
                },
                "color_code": {
                  "type": "string",
                  "pattern": "^#[0-9a-fA-F]{6}$"
                }
              }
            }
          }
        }
      },
      "Variant": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "title": {
            "type": "string"
          },
          "option1": {
            "type": [
              "string",
              "null"
            ]
          },
          "option2": {
            "type": [
              "string",
              "null"
            ]
          },
          "option3": {
            "type": [
              "string",
              "null"
            ]
          },
          "price": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ]
          },
          "sku": {
            "type": "string"
          },
          "quantity": {
            "type": "integer"
          },
          "available": {
            "type": "boolean"
          }
        }
      },
      "Product": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "draft",
              "archived"
            ]
          },
          "price": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ]
          },
          "compare_at_price": {
            "type": [
              "string",
              "null"
            ]
          },
          "currency": {
            "type": "string"
          },
          "quantity": {
            "type": "integer"
          },
          "category_id": {
            "type": [
              "integer",
              "null"
            ]
          },
          "visible_in_app": {
            "type": "boolean",
            "description": "App Manager brands only."
          },
          "options": {
            "type": "array"
          },
          "variants": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Variant"
            }
          },
          "images": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "url": {
            "type": "string",
            "description": "Neptune Shopping stores only."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "LineItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "product_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "product_external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "variant_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "variant_external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "title": {
            "type": "string"
          },
          "quantity": {
            "type": "integer"
          },
          "price": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ]
          },
          "total": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ]
          }
        }
      },
      "Order": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "number": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "confirmed",
              "processing",
              "ready",
              "shipped",
              "delivered",
              "cancelled",
              "failed",
              "refunded"
            ]
          },
          "payment_status": {
            "type": "string"
          },
          "payment_method": {
            "type": "string"
          },
          "delivery_method": {
            "type": "string",
            "enum": [
              "neptune",
              "store"
            ]
          },
          "fulfilled_by_neptune": {
            "type": "boolean"
          },
          "fulfillment_type": {
            "type": "string",
            "enum": [
              "delivery",
              "pickup",
              "dine_in"
            ]
          },
          "currency": {
            "type": "string"
          },
          "subtotal": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ]
          },
          "shipping": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ]
          },
          "tax": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ]
          },
          "total": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ]
          },
          "neptune_commission": {
            "type": "string",
            "pattern": "^\\d+(\\.\\d{1,2})?$",
            "examples": [
              "49.90"
            ]
          },
          "customer": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "phone": {
                "type": "string"
              },
              "email": {
                "type": "string"
              }
            }
          },
          "shipping_address": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "object"
              }
            ]
          },
          "line_items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/LineItem"
            }
          },
          "external_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Webhook": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "topic": {
            "type": "string",
            "enum": [
              "order.created",
              "order.updated",
              "order.cancelled",
              "app.uninstalled"
            ]
          },
          "url": {
            "type": "string"
          },
          "active": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      }
    }
  },
  "paths": {
    "/oauth/token": {
      "post": {
        "summary": "Exchange an authorization code for an access token (platform apps)",
        "security": [],
        "tags": [
          "OAuth"
        ],
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "required": [
                  "grant_type",
                  "code",
                  "redirect_uri",
                  "client_id",
                  "client_secret"
                ],
                "properties": {
                  "grant_type": {
                    "const": "authorization_code"
                  },
                  "code": {
                    "type": "string"
                  },
                  "redirect_uri": {
                    "type": "string"
                  },
                  "client_id": {
                    "type": "string"
                  },
                  "client_secret": {
                    "type": "string"
                  },
                  "code_verifier": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "access_token": {
                      "type": "string"
                    },
                    "token_type": {
                      "const": "bearer"
                    },
                    "scope": {
                      "type": "string"
                    },
                    "installation_id": {
                      "type": "string"
                    },
                    "target": {
                      "type": "string",
                      "enum": [
                        "store",
                        "brand"
                      ]
                    },
                    "store_id": {
                      "type": "string"
                    },
                    "brand_id": {
                      "type": "string"
                    },
                    "webhook_secret": {
                      "type": "string"
                    }
                  }
                }
              }
            },
            "description": "Access granted"
          },
          "400": {
            "description": "RFC 6749 error"
          },
          "401": {
            "description": "invalid_client"
          }
        }
      }
    },
    "/oauth/revoke": {
      "post": {
        "summary": "Revoke the calling token and its installation",
        "tags": [
          "OAuth"
        ],
        "responses": {
          "204": {
            "description": "Revoked"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/shop": {
      "get": {
        "summary": "The installation and the store or brand it acts on",
        "tags": [
          "Shop"
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope missing or account not eligible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/categories": {
      "get": {
        "summary": "Neptune Shopping categories (stores only)",
        "tags": [
          "Products"
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope missing or account not eligible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/products": {
      "get": {
        "summary": "List products",
        "tags": [
          "Products"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 250,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "The next_cursor of the previous page."
          },
          {
            "name": "updated_at_min",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "products": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Product"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            },
            "description": "OK"
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope missing or account not eligible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/products/{product_id}": {
      "get": {
        "summary": "Get a product by Neptune id",
        "tags": [
          "Products"
        ],
        "parameters": [
          {
            "name": "product_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "product": {
                      "$ref": "#/components/schemas/Product"
                    }
                  }
                }
              }
            },
            "description": "OK"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope missing or account not eligible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/products/external/{external_id}": {
      "parameters": [
        {
          "name": "external_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string",
            "maxLength": 255
          }
        }
      ],
      "get": {
        "summary": "Get a product by your id",
        "tags": [
          "Products"
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope missing or account not eligible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "summary": "Create or replace a product by your id (idempotent)",
        "tags": [
          "Products"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProductInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated"
          },
          "201": {
            "description": "Created"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope missing or account not eligible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Refused by the business rules",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Archive a product (taken off sale, kept for past orders)",
        "tags": [
          "Products"
        ],
        "responses": {
          "204": {
            "description": "Archived"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope missing or account not eligible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/inventory/set": {
      "post": {
        "summary": "Set absolute stock levels (up to 250 per call)",
        "tags": [
          "Inventory"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "items"
                ],
                "properties": {
                  "items": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 250,
                    "items": {
                      "type": "object",
                      "required": [
                        "product_external_id",
                        "quantity"
                      ],
                      "properties": {
                        "product_external_id": {
                          "type": "string"
                        },
                        "variant_external_id": {
                          "type": "string"
                        },
                        "quantity": {
                          "type": "integer",
                          "minimum": 0
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Per-item results"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope missing or account not eligible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders": {
      "get": {
        "summary": "List orders",
        "tags": [
          "Orders"
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 250,
              "default": 50
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "The next_cursor of the previous page."
          },
          {
            "name": "updated_at_min",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "orders": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Order"
                      }
                    },
                    "next_cursor": {
                      "type": [
                        "string",
                        "null"
                      ]
                    }
                  }
                }
              }
            },
            "description": "OK"
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope missing or account not eligible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/orders/{order_id}": {
      "parameters": [
        {
          "name": "order_id",
          "in": "path",
          "required": true,
          "schema": {
            "type": "string"
          }
        }
      ],
      "get": {
        "summary": "Get an order",
        "tags": [
          "Orders"
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope missing or account not eligible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "summary": "Update status, payment status (brands) or your reference",
        "tags": [
          "Orders"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "status": {
                    "type": "string"
                  },
                  "payment_status": {
                    "type": "string"
                  },
                  "external_id": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "maxLength": 120
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated order"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Scope missing or account not eligible",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Refused by the business rules",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "summary": "List webhook subscriptions",
        "tags": [
          "Webhooks"
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "summary": "Subscribe to a topic",
        "tags": [
          "Webhooks"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "topic",
                  "url"
                ],
                "properties": {
                  "topic": {
                    "type": "string",
                    "enum": [
                      "order.created",
                      "order.updated",
                      "order.cancelled",
                      "app.uninstalled"
                    ]
                  },
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "pattern": "^https://"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "200": {
            "description": "Already existed"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Refused by the business rules",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "422": {
            "description": "Validation failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/webhooks/{webhook_id}": {
      "delete": {
        "summary": "Delete a subscription",
        "tags": [
          "Webhooks"
        ],
        "parameters": [
          {
            "name": "webhook_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Deleted"
          },
          "401": {
            "description": "Missing or invalid token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  }
}