{
  "openapi": "3.1.0",
  "info": {
    "title": "RewardsNP integration API",
    "version": "1.0.0",
    "summary": "Create customer session links, list a business's campaigns and record visits, from your own server.",
    "description": "A server-to-server API for systems that work alongside a business's RewardsNP campaigns: a till or billing system, a partner app, the business's own software. Every call is made with a key that belongs to ONE business; the business is known from the key and is never sent in a request. Versioning promise: within v1, changes are additive only - a new endpoint, a new optional request field, a new response field, a new error code for a new condition. No field is removed and none changes meaning. Ignore response fields you do not know.",
    "contact": {
      "name": "RewardsNP",
      "url": "https://rewardsnp.com/#contact"
    }
  },
  "servers": [
    {
      "url": "https://app.rewardsnp.com",
      "description": "The platform's address. A placeholder until the domain is chosen; your ConvertPlus contact gives you the live address and, for testing, a staging address."
    }
  ],
  "security": [
    {
      "connectionKey": []
    }
  ],
  "tags": [
    {
      "name": "Campaigns",
      "description": "What the business is running."
    },
    {
      "name": "Links",
      "description": "A session link for one customer, one time."
    },
    {
      "name": "Visits",
      "description": "Report a visit for a customer you can identify."
    }
  ],
  "x-rate-limits": {
    "window_seconds": 60,
    "keyed_by": "connection",
    "limits": {
      "GET /api/v1/campaigns": 60,
      "POST /api/v1/links": 600,
      "POST /api/v1/visits": 120
    }
  },
  "x-webhook-delivery": {
    "success": "any 2xx status",
    "timeout_seconds": 10,
    "retry_delays_seconds": [
      60,
      300,
      1800,
      7200,
      21600,
      86400
    ],
    "set_aside_after_failed_attempts": 7,
    "pause_after_consecutive_failures": 10,
    "replay_max_days": 31,
    "replay_max_messages": 1000,
    "content_kept_days": 90
  },
  "x-error-catalogue": {
    "key_missing": {
      "status": 401,
      "meaning": "No `Authorization` header was sent, or it is not in the form `Bearer <key>`: the word `Bearer` (its letter case does not matter), then one space, then the key.",
      "action": "Send the header on every call, exactly in that form."
    },
    "key_invalid": {
      "status": 401,
      "meaning": "The key is not one we know: mistyped, cut short, in the wrong form, or a key from another deployment.",
      "action": "Check the key you stored. Do not retry with the same key."
    },
    "key_revoked": {
      "status": 401,
      "meaning": "The key was switched off, or its connection was switched off.",
      "action": "Tell the business. It creates a new connection or key in its dashboard. Do not retry."
    },
    "key_expired": {
      "status": 401,
      "meaning": "The key was replaced and its 7 days have passed.",
      "action": "Use the key that replaced it."
    },
    "business_off": {
      "status": 401,
      "meaning": "The business has been switched off on the platform, so none of its connections work for now. The key itself is not at fault.",
      "action": "Tell the business. Do not retry until it is switched back on; nothing was recorded."
    },
    "scope_denied": {
      "status": 403,
      "meaning": "The connection's purpose does not cover this endpoint (for example a connection that only creates links tried to record a visit).",
      "action": "The business creates a connection with the right purpose. Do not retry."
    },
    "campaign_not_found": {
      "status": 404,
      "meaning": "The business has no campaign with this id. Another business's campaign answers the same way, on purpose.",
      "action": "Fetch the campaign list and use an id from it."
    },
    "campaign_archived": {
      "status": 409,
      "meaning": "The business has archived this campaign.",
      "action": "Stop sending for this campaign. Show something else."
    },
    "campaign_not_available": {
      "status": 409,
      "meaning": "The campaign exists but is not taking customers at the moment.",
      "action": "Show something else now; the same call may succeed later."
    },
    "invalid_json": {
      "status": 400,
      "meaning": "The request body is not valid JSON.",
      "action": "Fix the request. Do not retry unchanged."
    },
    "body_not_object": {
      "status": 400,
      "meaning": "The request body is valid JSON but is not an object: for example a bare number, `null` or a list.",
      "action": "Send a JSON object, in `{ }`. Do not retry unchanged."
    },
    "unsupported_charset": {
      "status": 400,
      "meaning": "The request body is not in UTF-8.",
      "action": "Send the body as UTF-8 text (`Content-Type: application/json; charset=utf-8`). Do not retry unchanged."
    },
    "unsupported_encoding": {
      "status": 400,
      "meaning": "The request body is compressed in a way we do not read (`Content-Encoding`).",
      "action": "Send the body uncompressed. Do not retry unchanged."
    },
    "campaign_required": {
      "status": 400,
      "meaning": "`campaign_id` is missing.",
      "action": "Send it."
    },
    "no_sessions": {
      "status": 400,
      "meaning": "This campaign is a kind of page that takes no session links and no visits.",
      "action": "Use a campaign from the campaign list - it only lists campaigns that can be used here."
    },
    "wrong_flow": {
      "status": 400,
      "meaning": "This campaign is set up in a way that cannot take a visit recorded for it.",
      "action": "Use a session link for this campaign instead."
    },
    "request_id_required": {
      "status": 400,
      "meaning": "`request_id` is missing.",
      "action": "Send your bill or order number."
    },
    "request_id_invalid": {
      "status": 400,
      "meaning": "`request_id` must be 1 to 64 visible ASCII characters with no spaces.",
      "action": "Send a shorter or plainer value."
    },
    "identifier_required": {
      "status": 400,
      "meaning": "The campaign needs a phone number or an email address and the call carried none it can use. `field` names what to send.",
      "action": "Normal for a bill with no customer details: nothing was recorded. Do not retry."
    },
    "invalid_phone": {
      "status": 400,
      "meaning": "The phone number is not valid in the format of the business's country: the national number, with or without the calling code (a Nepal business: 10 digits, with or without +977).",
      "action": "Nothing was recorded. Correct the number or drop the visit."
    },
    "invalid_email": {
      "status": 400,
      "meaning": "The email address is not valid.",
      "action": "Nothing was recorded. Correct the address or drop the visit."
    },
    "payload_too_large": {
      "status": 413,
      "meaning": "The request body is far larger than any request here needs to be.",
      "action": "Send only the fields the endpoint describes."
    },
    "not_found": {
      "status": 404,
      "anywhere": true,
      "meaning": "The address or the method is not one of the endpoints of this API.",
      "action": "Check the address and the method against this reference."
    },
    "rate_limited": {
      "status": 429,
      "meaning": "Too many calls in the last minute.",
      "action": "Wait the number of seconds in the `Retry-After` header, then try again."
    },
    "error": {
      "status": 500,
      "meaning": "Something failed on our side.",
      "action": "Try again after a short wait. For a visit, send the same `request_id` so it cannot be counted twice."
    },
    "busy": {
      "status": 503,
      "meaning": "The service is busy for a moment.",
      "action": "Wait the number of seconds in the `Retry-After` header, then try again. For a visit, send the same `request_id`: the retry cannot be counted twice."
    }
  },
  "paths": {
    "/api/v1/campaigns": {
      "get": {
        "operationId": "listCampaigns",
        "tags": [
          "Campaigns"
        ],
        "summary": "List the business's campaigns",
        "description": "The campaigns of the key's business that are live and can take a session: running, not archived, not waiting to start, and not a page that takes no customers. Use it to fill a campaign picker on your side. Being listed does not guarantee a visit will be accepted: a visit to a campaign set up in a way that cannot take a reported visit is still refused with `wrong_flow`. The list says nothing about customers, rewards or figures.",
        "x-purpose": "Creates links or Records visits (either)",
        "responses": {
          "200": {
            "description": "The campaigns.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CampaignList"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/KeyRefused"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceBusy"
          }
        }
      }
    },
    "/api/v1/links": {
      "post": {
        "operationId": "createLink",
        "tags": [
          "Links"
        ],
        "summary": "Create a session link",
        "description": "Returns a link that opens the campaign page with a session for ONE customer. The link works once and stops working 15 minutes after it is created. It names no customer. Use the link exactly as returned; to add your own tracking reference, append it with `&` under a name of your own that is not `sid`, `msg`, `ref` or `card`. Nothing is stored when a link is created: a link that is never opened costs nothing and leaves no record of the link. A bill amount or a branch that we cannot use never fails the call: the link is created without it.",
        "x-purpose": "Creates links",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LinkRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The link.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LinkResponse"
                }
              }
            }
          },
          "400": {
            "description": "The request cannot be used.",
            "x-codes": [
              "invalid_json",
              "body_not_object",
              "unsupported_charset",
              "unsupported_encoding",
              "campaign_required",
              "no_sessions"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/KeyRefused"
          },
          "403": {
            "$ref": "#/components/responses/PurposeRefused"
          },
          "404": {
            "$ref": "#/components/responses/CampaignNotFound"
          },
          "409": {
            "$ref": "#/components/responses/CampaignNotUsable"
          },
          "413": {
            "$ref": "#/components/responses/BodyTooLarge"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceBusy"
          }
        }
      }
    },
    "/api/v1/visits": {
      "post": {
        "operationId": "recordVisit",
        "tags": [
          "Visits"
        ],
        "summary": "Record a visit",
        "description": "Records a visit for a customer you identify by phone number or email address, as if staff had logged it on the business's dashboard: the same rewards and the same limits. The answer only says that the call was accepted, with a receipt id; it never says what the customer earned. The visit is timed when we receive it - a time you send is not read. Within 90 days, sending the same `request_id` again on the same connection returns the first call's receipt and records nothing. The order is: the key is accepted; the connection has the \"Records visits\" purpose and is within its limit (otherwise `scope_denied` or `rate_limited`); `campaign_id` and `request_id` are present and well formed; then a repeat gets the first call's receipt, before the campaign, the customer's details, the bill amount or the branch are looked at, so it holds whatever the rest of the repeat's body says and even if the campaign has since been archived. After 90 days the id is forgotten: the request is checked like a new one and gets a new receipt id. If the earlier request recorded a visit, no second visit or reward is recorded. If the earlier request only joined a visit already in progress, the repeat (once that visit's window has closed) is recorded as a new visit and can give a reward. On a \"play first, then identify\" campaign the wait between visits is kept per customer for a reported visit (a customer's own scan is still checked on that customer's device): a second report for the same customer inside the wait (after the visit window has closed) is accepted and gets its receipt id, but it is not recorded as a visit and it gives no reward.",
        "x-purpose": "Records visits",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VisitRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Accepted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VisitResponse"
                }
              }
            }
          },
          "400": {
            "description": "The request cannot be used. Nothing was recorded and no customer was created.",
            "x-codes": [
              "invalid_json",
              "body_not_object",
              "unsupported_charset",
              "unsupported_encoding",
              "campaign_required",
              "request_id_required",
              "request_id_invalid",
              "no_sessions",
              "wrong_flow",
              "identifier_required",
              "invalid_phone",
              "invalid_email"
            ],
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/KeyRefused"
          },
          "403": {
            "$ref": "#/components/responses/PurposeRefused"
          },
          "404": {
            "$ref": "#/components/responses/CampaignNotFound"
          },
          "409": {
            "$ref": "#/components/responses/CampaignNotUsable"
          },
          "413": {
            "$ref": "#/components/responses/BodyTooLarge"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "500": {
            "$ref": "#/components/responses/ServerError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceBusy"
          }
        }
      }
    }
  },
  "webhooks": {
    "visit.recorded": {
      "post": {
        "operationId": "onVisitRecorded",
        "summary": "A visit was recorded for a known customer - scanned by the customer, logged by staff, or reported through this API.",
        "x-schema-version": 1,
        "security": [],
        "parameters": [
          {
            "$ref": "#/components/parameters/Signature"
          },
          {
            "$ref": "#/components/parameters/EventId"
          },
          {
            "$ref": "#/components/parameters/SchemaVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Envelope"
                  },
                  {
                    "type": "object",
                    "required": [
                      "customer"
                    ],
                    "properties": {
                      "event": {
                        "type": "string",
                        "enum": [
                          "visit.recorded"
                        ]
                      },
                      "data": {
                        "$ref": "#/components/schemas/VisitRecordedData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Any 2xx status means delivered. The response body is ignored."
          }
        }
      }
    },
    "reward.unlocked": {
      "post": {
        "operationId": "onRewardUnlocked",
        "summary": "A customer earned a reward (any way except winning a draw), or spent points on one. Both people in a referral get their own event.",
        "x-schema-version": 1,
        "security": [],
        "parameters": [
          {
            "$ref": "#/components/parameters/Signature"
          },
          {
            "$ref": "#/components/parameters/EventId"
          },
          {
            "$ref": "#/components/parameters/SchemaVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Envelope"
                  },
                  {
                    "type": "object",
                    "required": [
                      "customer"
                    ],
                    "properties": {
                      "event": {
                        "type": "string",
                        "enum": [
                          "reward.unlocked"
                        ]
                      },
                      "data": {
                        "$ref": "#/components/schemas/RewardUnlockedData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Any 2xx status means delivered. The response body is ignored."
          }
        }
      }
    },
    "reward.claimed": {
      "post": {
        "operationId": "onRewardClaimed",
        "summary": "Staff handed a reward over to the customer.",
        "x-schema-version": 1,
        "security": [],
        "parameters": [
          {
            "$ref": "#/components/parameters/Signature"
          },
          {
            "$ref": "#/components/parameters/EventId"
          },
          {
            "$ref": "#/components/parameters/SchemaVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Envelope"
                  },
                  {
                    "type": "object",
                    "required": [
                      "customer"
                    ],
                    "properties": {
                      "event": {
                        "type": "string",
                        "enum": [
                          "reward.claimed"
                        ]
                      },
                      "data": {
                        "$ref": "#/components/schemas/RewardClaimedData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Any 2xx status means delivered. The response body is ignored."
          }
        }
      }
    },
    "lottery.won": {
      "post": {
        "operationId": "onLotteryWon",
        "summary": "A draw took place and this customer won. A draw win is never also sent as reward.unlocked.",
        "x-schema-version": 1,
        "security": [],
        "parameters": [
          {
            "$ref": "#/components/parameters/Signature"
          },
          {
            "$ref": "#/components/parameters/EventId"
          },
          {
            "$ref": "#/components/parameters/SchemaVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Envelope"
                  },
                  {
                    "type": "object",
                    "required": [
                      "customer"
                    ],
                    "properties": {
                      "event": {
                        "type": "string",
                        "enum": [
                          "lottery.won"
                        ]
                      },
                      "data": {
                        "$ref": "#/components/schemas/LotteryWonData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Any 2xx status means delivered. The response body is ignored."
          }
        }
      }
    },
    "loyalty.progress": {
      "post": {
        "operationId": "onLoyaltyProgress",
        "summary": "A visit added points to the customer's balance.",
        "x-schema-version": 1,
        "security": [],
        "parameters": [
          {
            "$ref": "#/components/parameters/Signature"
          },
          {
            "$ref": "#/components/parameters/EventId"
          },
          {
            "$ref": "#/components/parameters/SchemaVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Envelope"
                  },
                  {
                    "type": "object",
                    "required": [
                      "customer"
                    ],
                    "properties": {
                      "event": {
                        "type": "string",
                        "enum": [
                          "loyalty.progress"
                        ]
                      },
                      "data": {
                        "$ref": "#/components/schemas/LoyaltyProgressData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Any 2xx status means delivered. The response body is ignored."
          }
        }
      }
    },
    "streak.progress": {
      "post": {
        "operationId": "onStreakProgress",
        "summary": "A visit was counted on a visit ladder - every counted visit, not only the ones that reach a reward.",
        "x-schema-version": 1,
        "security": [],
        "parameters": [
          {
            "$ref": "#/components/parameters/Signature"
          },
          {
            "$ref": "#/components/parameters/EventId"
          },
          {
            "$ref": "#/components/parameters/SchemaVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Envelope"
                  },
                  {
                    "type": "object",
                    "required": [
                      "customer"
                    ],
                    "properties": {
                      "event": {
                        "type": "string",
                        "enum": [
                          "streak.progress"
                        ]
                      },
                      "data": {
                        "$ref": "#/components/schemas/StreakProgressData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Any 2xx status means delivered. The response body is ignored."
          }
        }
      }
    },
    "passport.progress": {
      "post": {
        "operationId": "onPassportProgress",
        "summary": "A visit stamped a branch the customer had not visited before on a branch passport.",
        "x-schema-version": 1,
        "security": [],
        "parameters": [
          {
            "$ref": "#/components/parameters/Signature"
          },
          {
            "$ref": "#/components/parameters/EventId"
          },
          {
            "$ref": "#/components/parameters/SchemaVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Envelope"
                  },
                  {
                    "type": "object",
                    "required": [
                      "customer"
                    ],
                    "properties": {
                      "event": {
                        "type": "string",
                        "enum": [
                          "passport.progress"
                        ]
                      },
                      "data": {
                        "$ref": "#/components/schemas/PassportProgressData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Any 2xx status means delivered. The response body is ignored."
          }
        }
      }
    },
    "endpoint.test": {
      "post": {
        "operationId": "onEndpointTest",
        "summary": "A test message, sent when Send test is pressed for your address, by the business on its dashboard or by the ConvertPlus team. It names no customer and no campaign.",
        "x-schema-version": 1,
        "security": [],
        "parameters": [
          {
            "$ref": "#/components/parameters/Signature"
          },
          {
            "$ref": "#/components/parameters/EventId"
          },
          {
            "$ref": "#/components/parameters/SchemaVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Envelope"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "event": {
                        "type": "string",
                        "enum": [
                          "endpoint.test"
                        ]
                      },
                      "data": {
                        "$ref": "#/components/schemas/EndpointTestData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Any 2xx status means delivered. The response body is ignored."
          }
        }
      }
    },
    "endpoint.verification": {
      "post": {
        "operationId": "onEndpointVerification",
        "summary": "Sent once, when your address is first set up. Nothing else is sent until you answer it correctly.",
        "x-schema-version": 1,
        "security": [],
        "parameters": [
          {
            "$ref": "#/components/parameters/Signature"
          },
          {
            "$ref": "#/components/parameters/EventId"
          },
          {
            "$ref": "#/components/parameters/SchemaVersion"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/Envelope"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "event": {
                        "type": "string",
                        "enum": [
                          "endpoint.verification"
                        ]
                      },
                      "data": {
                        "$ref": "#/components/schemas/EndpointVerificationData"
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Answer with a 2xx status and a JSON body of at most 4096 bytes whose top-level `challenge` equals the value you were sent, for example {\"challenge\":\"<the same value>\"}."
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "connectionKey": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "cpk_<key id>_<secret>",
        "description": "The key of one connection, created by the business in its dashboard. Send it as `Authorization: Bearer cpk_<key id>_<secret>`: the word `Bearer` (its letter case does not matter), one space, then the key. The key itself is case-sensitive. The key id (12 characters) is not secret and is shown on the business's dashboard; the rest is shown once, when the key is created."
      }
    },
    "parameters": {
      "Signature": {
        "name": "X-ConvertPlus-Signature",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "`t=<unix seconds>,v1=<hex>` - or two `v1` values while a signing secret is being replaced."
      },
      "EventId": {
        "name": "X-ConvertPlus-Event-Id",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "The same value as `event_id` in the body."
      },
      "SchemaVersion": {
        "name": "X-ConvertPlus-Schema-Version",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string"
        },
        "description": "The same value as `schema_version` in the body, as text."
      }
    },
    "responses": {
      "KeyRefused": {
        "description": "The key is missing or not good, or the business it belongs to has been switched off.",
        "x-codes": [
          "key_missing",
          "key_invalid",
          "key_revoked",
          "key_expired",
          "business_off"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "PurposeRefused": {
        "description": "The key is good but its connection's purpose does not cover this endpoint.",
        "x-codes": [
          "scope_denied"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "CampaignNotFound": {
        "description": "No such campaign for this business.",
        "x-codes": [
          "campaign_not_found"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "CampaignNotUsable": {
        "description": "The campaign exists but cannot be used now.",
        "x-codes": [
          "campaign_archived",
          "campaign_not_available"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "BodyTooLarge": {
        "description": "The request body is too large.",
        "x-codes": [
          "payload_too_large"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Too many calls in the last minute.",
        "x-codes": [
          "rate_limited"
        ],
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait before the next call.",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ServiceBusy": {
        "description": "The service is busy for a moment. Nothing was changed by this call.",
        "x-codes": [
          "busy"
        ],
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait before trying again.",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ServerError": {
        "description": "A failure on our side. The body never carries internal detail.",
        "x-codes": [
          "error"
        ],
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "object",
            "description": "What went wrong: a fixed code, a sentence for a person, and the field when one field is the cause.",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "A fixed word. Decide what to do from this, never from the message. New codes may be added within v1, so treat a code you do not know by its HTTP status. The codes that exist today, each with its status and what to do, are listed in `x-error-catalogue` of this file and in the error table of the guide."
              },
              "message": {
                "type": "string",
                "description": "One plain sentence for a person reading a log. Its wording may change."
              },
              "field": {
                "type": "string",
                "description": "The request field the refusal is about, when there is one (`phone` or `email`)."
              }
            }
          }
        }
      },
      "Campaign": {
        "type": "object",
        "required": [
          "campaign_id",
          "name",
          "identifiers"
        ],
        "properties": {
          "campaign_id": {
            "type": "string",
            "description": "The id to send as `campaign_id`."
          },
          "name": {
            "type": "string",
            "description": "The name shown for this campaign: the label customers see on its card."
          },
          "identifiers": {
            "type": "array",
            "description": "What identifies a customer on this campaign. One entry: a visit must carry that one. Two entries: either is enough.",
            "items": {
              "type": "string",
              "enum": [
                "phone",
                "email"
              ]
            }
          }
        }
      },
      "CampaignList": {
        "type": "object",
        "required": [
          "campaigns"
        ],
        "properties": {
          "campaigns": {
            "type": "array",
            "description": "The business's campaigns that are live and can take a session.",
            "items": {
              "$ref": "#/components/schemas/Campaign"
            }
          }
        }
      },
      "LinkRequest": {
        "type": "object",
        "required": [
          "campaign_id"
        ],
        "properties": {
          "campaign_id": {
            "type": "string",
            "description": "A campaign of the key's business, from the campaign list."
          },
          "txn_value": {
            "type": [
              "number",
              "string"
            ],
            "minimum": 0,
            "description": "The bill amount, in the business's currency. Optional. Send a number of zero or more; plain text that is such a number, like \"12.5\", is read too. Anything else (for example \"1,200.00\", a negative number, or a number too large to be exact, above 9007199254740991) is ignored: the call goes ahead as if no amount was sent."
          },
          "branch": {
            "type": "string",
            "maxLength": 64,
            "description": "Your own code for the branch. Optional. The business enters each branch's codes in its dashboard. A code we do not recognise is ignored."
          }
        }
      },
      "LinkResponse": {
        "type": "object",
        "required": [
          "url",
          "expires_at"
        ],
        "properties": {
          "url": {
            "type": "string",
            "description": "The link, ending in `?sid=...`. Use it exactly as returned."
          },
          "expires_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the link stops working: 15 minutes after it was created (UTC)."
          }
        }
      },
      "VisitRequest": {
        "type": "object",
        "required": [
          "campaign_id",
          "request_id"
        ],
        "properties": {
          "campaign_id": {
            "type": "string",
            "description": "A campaign of the key's business, from the campaign list."
          },
          "request_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64,
            "pattern": "^[\\x21-\\x7E]{1,64}$",
            "description": "Your own id for this visit - the bill or order number. 1 to 64 visible ASCII characters, no spaces. Never a phone number or an email address. Remembered for 90 days per connection."
          },
          "phone": {
            "type": "string",
            "description": "The customer's phone number, in the format of the business's country: a Nepal business takes 10 digits, optionally preceded by +977 or 977. A full international number (+ and the calling code) is also accepted. Spaces and dashes are ignored. It is stored with its calling code."
          },
          "email": {
            "type": "string",
            "description": "The customer's email address. If you send both a phone number and an email address and they belong to two different customers, the phone number decides."
          },
          "name": {
            "type": "string",
            "description": "The customer's name. Optional. Stored only when the campaign's form collects a name; otherwise it is accepted and left out."
          },
          "txn_value": {
            "type": [
              "number",
              "string"
            ],
            "minimum": 0,
            "description": "The bill amount, in the business's currency. Optional. Send a number of zero or more; plain text that is such a number, like \"12.5\", is read too. Anything else (for example \"1,200.00\", a negative number, or a number too large to be exact, above 9007199254740991) is ignored: the call goes ahead as if no amount was sent."
          },
          "branch": {
            "type": "string",
            "maxLength": 64,
            "description": "Your own code for the branch. Optional. A code we do not recognise is ignored."
          }
        }
      },
      "VisitResponse": {
        "type": "object",
        "required": [
          "accepted",
          "event_id"
        ],
        "properties": {
          "accepted": {
            "type": "boolean",
            "enum": [
              true
            ],
            "description": "Always true: the visit was received."
          },
          "event_id": {
            "type": "string",
            "description": "A receipt id for this call. Keep it for support questions. It is NOT the `event_id` of the `visit.recorded` webhook."
          }
        }
      },
      "Customer": {
        "type": "object",
        "required": [
          "ref",
          "phone_sha256",
          "email_sha256"
        ],
        "properties": {
          "ref": {
            "type": "string",
            "description": "Our id for this customer at this business. Stable for the customer; treat it as opaque."
          },
          "phone_sha256": {
            "type": "string",
            "description": "SHA-256, lower-case hex, of the phone number as it is stored: the international form, the calling code followed by the national number (a Nepal number is +977 followed by 10 digits). An empty string when the customer has no phone number."
          },
          "email_sha256": {
            "type": "string",
            "description": "SHA-256, lower-case hex, of the email address trimmed and in lower case. An empty string when the customer has no email address."
          },
          "name": {
            "type": [
              "string",
              "null"
            ],
            "description": "Only when plain details are switched on for your address."
          },
          "phone": {
            "type": [
              "string",
              "null"
            ],
            "description": "Only when plain details are switched on for your address."
          },
          "email": {
            "type": [
              "string",
              "null"
            ],
            "description": "Only when plain details are switched on for your address."
          }
        }
      },
      "Envelope": {
        "type": "object",
        "required": [
          "event",
          "event_id",
          "schema_version",
          "occurred_at",
          "client_id",
          "campaign_id",
          "branch_id",
          "data"
        ],
        "properties": {
          "event": {
            "type": "string",
            "description": "The event's name."
          },
          "event_id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128,
            "description": "The id of this event. The same on every retry and every replay. Treat it as opaque; use it to drop repeats."
          },
          "schema_version": {
            "type": "integer",
            "enum": [
              1
            ],
            "description": "The version of this message format. Changes are additive only."
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time",
            "description": "When the thing happened (UTC). It does not change on a retry or a replay."
          },
          "client_id": {
            "type": "string",
            "description": "The business."
          },
          "campaign_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "The campaign. Null on the two endpoint events."
          },
          "customer": {
            "$ref": "#/components/schemas/Customer"
          },
          "branch_id": {
            "type": [
              "string",
              "null"
            ],
            "description": "The branch, when the event has one. Always present; null when there is none."
          },
          "data": {
            "type": "object",
            "description": "The event's own details."
          }
        }
      },
      "VisitRecordedData": {
        "type": "object",
        "required": [
          "channel",
          "transaction_value"
        ],
        "properties": {
          "channel": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "scan",
              "staff",
              "api",
              null
            ],
            "description": "How the visit was recorded: `scan` (the customer's own page), `staff` (logged on the dashboard), `api` (reported through this API). Null on old history."
          },
          "transaction_value": {
            "type": [
              "number",
              "null"
            ],
            "description": "The bill amount, when one was given."
          }
        }
      },
      "RewardUnlockedData": {
        "type": "object",
        "required": [
          "reward_name",
          "pool_ref",
          "pool_name",
          "earned_by",
          "claim_by",
          "referral_role"
        ],
        "properties": {
          "reward_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "The reward's name."
          },
          "pool_ref": {
            "type": [
              "string",
              "null"
            ],
            "description": "Which part of the campaign gave the reward. Treat it as opaque."
          },
          "pool_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "That part's name as the business wrote it."
          },
          "earned_by": {
            "type": [
              "string",
              "null"
            ],
            "description": "How it was earned: `referral`, `points_spent`, or a word such as `earned`, `granted` or `compensation`."
          },
          "claim_by": {
            "type": [
              "string",
              "null"
            ],
            "description": "The last moment to claim it (UTC), or null when it does not lapse."
          },
          "referral_role": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "referrer",
              "referred",
              null
            ],
            "description": "On a referral reward, which side this customer is."
          }
        }
      },
      "RewardClaimedData": {
        "type": "object",
        "required": [
          "reward_name",
          "pool_ref",
          "pool_name"
        ],
        "properties": {
          "reward_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "The reward's name."
          },
          "pool_ref": {
            "type": [
              "string",
              "null"
            ],
            "description": "Which part of the campaign gave the reward. Treat it as opaque."
          },
          "pool_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "That part's name as the business wrote it."
          }
        }
      },
      "LotteryWonData": {
        "type": "object",
        "required": [
          "draw_name",
          "round",
          "claim_by"
        ],
        "description": "Carries EITHER `reward_name` (a prize) OR `points` (points added to the balance) - the other key is absent.",
        "properties": {
          "draw_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "The draw's name."
          },
          "round": {
            "type": [
              "integer",
              "null"
            ],
            "description": "Which round of the draw."
          },
          "reward_name": {
            "type": [
              "string",
              "null"
            ],
            "description": "The prize, when the win is a prize."
          },
          "points": {
            "type": [
              "number",
              "null"
            ],
            "description": "The points won, when the win is points."
          },
          "claim_by": {
            "type": [
              "string",
              "null"
            ],
            "description": "The last moment to claim a prize (UTC). Null for a points win."
          }
        }
      },
      "LoyaltyProgressData": {
        "type": "object",
        "required": [
          "points_earned",
          "balance",
          "tier"
        ],
        "properties": {
          "points_earned": {
            "type": [
              "number",
              "null"
            ],
            "description": "Points added by this visit."
          },
          "balance": {
            "type": [
              "number",
              "null"
            ],
            "description": "The balance after it."
          },
          "tier": {
            "type": [
              "string",
              "null"
            ],
            "description": "The customer's tier name, or null."
          }
        }
      },
      "StreakProgressData": {
        "type": "object",
        "required": [
          "pool_ref",
          "visit_count",
          "position",
          "next_milestone"
        ],
        "properties": {
          "pool_ref": {
            "type": [
              "string",
              "null"
            ],
            "description": "Which visit ladder. Treat it as opaque."
          },
          "visit_count": {
            "type": [
              "number",
              "null"
            ],
            "description": "Visits counted on the ladder so far."
          },
          "position": {
            "type": [
              "number",
              "null"
            ],
            "description": "Where the customer stands on the ladder."
          },
          "next_milestone": {
            "type": [
              "number",
              "null"
            ],
            "description": "The visit count of the next reward. Null at the top."
          }
        }
      },
      "PassportProgressData": {
        "type": "object",
        "required": [
          "pool_ref",
          "stamps",
          "stamps_required",
          "stamped_branch"
        ],
        "properties": {
          "pool_ref": {
            "type": [
              "string",
              "null"
            ],
            "description": "Which passport. Treat it as opaque."
          },
          "stamps": {
            "type": [
              "number",
              "null"
            ],
            "description": "Branches stamped so far."
          },
          "stamps_required": {
            "type": [
              "number",
              "null"
            ],
            "description": "Branches needed to complete it."
          },
          "stamped_branch": {
            "type": [
              "string",
              "null"
            ],
            "description": "The branch this visit stamped. (`branch_id` on the message itself is null for this event.)"
          }
        }
      },
      "EndpointTestData": {
        "type": "object",
        "description": "Empty.",
        "properties": {}
      },
      "EndpointVerificationData": {
        "type": "object",
        "required": [
          "challenge"
        ],
        "properties": {
          "challenge": {
            "type": "string",
            "description": "32 lower-case hex characters. Send the same value back."
          }
        }
      }
    }
  }
}
