{"openapi":"3.1.0","info":{"title":"Cloud Buzz SMS CRM – POS API","version":"1.1.0","description":"Send customers from a point-of-sale system into a venue's Cloud Buzz SMS contact list. Customers are subscribed to SMS only when consent.sms is true. Test keys (cbk_test_…) validate requests and return realistic answers without saving anything."},"servers":[{"url":"https://cblk.site/api/v1"}],"security":[{"apiKey":[]}],"paths":{"/me":{"get":{"summary":"Check the connection","description":"Returns the venue the key belongs to and whether it is a live or test key.","responses":{"200":{"description":"OK","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Me"}}}},"401":{"description":"Missing, invalid or revoked key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Venue inactive or API not in its package","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/customers":{"post":{"summary":"Create or update a customer","description":"Matched by phone number. Existing customers only get blank fields filled in. consent.sms = true subscribes (or re-subscribes) them; leaving it out never unsubscribes anyone.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CustomerInput"}}}},"responses":{"200":{"description":"Updated (or already up to date)","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CustomerResponse"}}}},"201":{"description":"Created","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CustomerResponse"}}}},"400":{"description":"Validation error; `field` names the bad property","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"Invalid key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"Not allowed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"Rate limited (120 requests/minute per key); see Retry-After","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/customers/batch":{"post":{"summary":"Create or update up to 100 customers","description":"Each item is processed independently; invalid items are reported in `results` without stopping the others.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["customers"],"properties":{"customers":{"type":"array","minItems":1,"maxItems":100,"items":{"$ref":"#/components/schemas/CustomerInput"}}}}}}},"responses":{"200":{"description":"Processed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/BatchResponse"}}}},"400":{"description":"Body is not { customers: [...] } or has more than 100 items","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/customers/{phone}":{"get":{"summary":"Look up a customer","parameters":[{"name":"phone","in":"path","required":true,"schema":{"type":"string"},"example":"0771234567"}],"responses":{"200":{"description":"Found","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/Customer"}}}}}},"404":{"description":"No customer with this number","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/customers/{phone}/unsubscribe":{"post":{"summary":"Unsubscribe a customer from SMS","description":"Use when the customer asks at the counter to stop messages.","parameters":[{"name":"phone","in":"path","required":true,"schema":{"type":"string"},"example":"0771234567"}],"responses":{"200":{"description":"Unsubscribed","content":{"application/json":{"schema":{"type":"object","properties":{"customer":{"$ref":"#/components/schemas/Customer"}}}}}},"404":{"description":"No customer with this number","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/visits":{"post":{"summary":"Record a bill (visit and spend)","description":"Adds the bill to the customer's visit count and total spend, creating the customer if needed (without SMS consent unless customer.consent.sms is true). Idempotent per billNo: sending the same bill again returns 200 with duplicate: true and changes nothing.","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/VisitInput"}}}},"responses":{"200":{"description":"Duplicate billNo, nothing changed","content":{"application/json":{"schema":{"$ref":"#/components/schemas/VisitResponse"}}}},"201":{"description":"Recorded","content":{"application/json":{"schema":{"$ref":"#/components/schemas/VisitResponse"}}}},"400":{"description":"Validation error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"409":{"description":"billNo already recorded for a different phone","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/visits/batch":{"post":{"summary":"Record up to 100 bills","description":"For importing past bills or catching up after being offline. Items are handled one by one.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["visits"],"properties":{"visits":{"type":"array","minItems":1,"maxItems":100,"items":{"$ref":"#/components/schemas/VisitInput"}}}}}}},"responses":{"200":{"description":"Processed; see summary { recorded, duplicates, failed } and per-item results"}}}},"/visits/{billNo}/void":{"post":{"summary":"Void a bill","description":"For refunds or cancellations: removes the bill from the customer's visit count and spend. Safe to repeat.","parameters":[{"name":"billNo","in":"path","required":true,"schema":{"type":"string"},"description":"URL-encoded bill number"}],"responses":{"200":{"description":"Voided (or already voided)"},"404":{"description":"No bill with this billNo","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}},"components":{"securitySchemes":{"apiKey":{"type":"http","scheme":"bearer","description":"Authorization: Bearer cbk_live_… (or cbk_test_…)"}},"schemas":{"CustomerInput":{"type":"object","required":["phone"],"properties":{"phone":{"type":"string","description":"Sri Lankan mobile, any common format","example":"077 123 4567"},"name":{"type":"string","maxLength":100,"example":"Nimal Perera"},"email":{"type":"string","format":"email"},"birthday":{"type":"string","format":"date","example":"1990-05-21"},"externalId":{"type":"string","description":"Your POS customer ID","example":"CUST-0042"},"consent":{"type":"object","required":["sms"],"properties":{"sms":{"type":"boolean","description":"true only if the customer agreed to receive SMS offers"},"method":{"type":"string","enum":["pos_checkbox","verbal","signed_form","receipt_optin","other"]},"at":{"type":"string","format":"date-time","description":"When they agreed (defaults to now)"}}}}},"Customer":{"type":"object","properties":{"phone":{"type":"string","example":"94771234567"},"name":{"type":"string"},"email":{"type":["string","null"]},"birthday":{"type":["string","null"]},"externalId":{"type":["string","null"]},"source":{"type":"string","enum":["qr","import","manual","pos"]},"smsStatus":{"type":"string","enum":["subscribed","opted_out","no_consent"]},"subscribed":{"type":"boolean"},"consent":{"type":["object","null"],"properties":{"at":{"type":"string","format":"date-time"},"method":{"type":"string"}}},"visits":{"type":"object","properties":{"count":{"type":"integer"},"totalSpend":{"type":"number"},"firstVisitAt":{"type":["string","null"],"format":"date-time"},"lastVisitAt":{"type":["string","null"],"format":"date-time"}}},"createdAt":{"type":["string","null"],"format":"date-time"}}},"VisitInput":{"type":"object","required":["phone","billNo","amount"],"properties":{"phone":{"type":"string","example":"0771234567"},"billNo":{"type":"string","maxLength":100,"description":"Unique bill/receipt number from your POS","example":"INV-2026-001234"},"amount":{"type":"number","minimum":0,"description":"Bill total in LKR","example":4850},"currency":{"type":"string","enum":["LKR"]},"visitedAt":{"type":"string","format":"date-time","description":"When the bill was paid (defaults to now)"},"outlet":{"type":"string","maxLength":60,"example":"Main restaurant"},"customer":{"type":"object","description":"Optional customer details, same fields as CustomerInput without phone","properties":{"name":{"type":"string"},"email":{"type":"string"},"birthday":{"type":"string"},"externalId":{"type":"string"},"consent":{"type":"object"}}}}},"Visit":{"type":"object","properties":{"billNo":{"type":"string"},"phone":{"type":"string"},"amount":{"type":"number"},"currency":{"type":"string"},"visitedAt":{"type":"string","format":"date-time"},"outlet":{"type":["string","null"]},"voided":{"type":"boolean"}}},"VisitResponse":{"type":"object","properties":{"created":{"type":"boolean"},"duplicate":{"type":"boolean"},"customerCreated":{"type":"boolean"},"visit":{"$ref":"#/components/schemas/Visit"},"customer":{"$ref":"#/components/schemas/Customer"},"test":{"type":"boolean"}}},"CustomerResponse":{"type":"object","properties":{"created":{"type":"boolean"},"customer":{"$ref":"#/components/schemas/Customer"},"test":{"type":"boolean"}}},"BatchResponse":{"type":"object","properties":{"summary":{"type":"object","properties":{"created":{"type":"integer"},"updated":{"type":"integer"},"failed":{"type":"integer"}}},"results":{"type":"array","items":{"type":"object","properties":{"index":{"type":"integer"},"ok":{"type":"boolean"},"created":{"type":"boolean"},"customer":{"$ref":"#/components/schemas/Customer"},"error":{"$ref":"#/components/schemas/ErrorBody"}}}},"test":{"type":"boolean"}}},"Me":{"type":"object","properties":{"venue":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"type":{"type":"string"}}},"mode":{"type":"string","enum":["live","test"]}}},"ErrorBody":{"type":"object","properties":{"code":{"type":"string"},"message":{"type":"string"},"field":{"type":"string"}}},"Error":{"type":"object","properties":{"error":{"$ref":"#/components/schemas/ErrorBody"}}}}}}