From 5e1109b13eeb58d21573af21fc8febd227a57103 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 19 Feb 2026 12:52:12 +0530 Subject: [PATCH] feat: add sdk examples for contacts --- .../application/contacts/conversations.yml | 18 +++++ swagger/paths/application/contacts/crud.yml | 46 ++++++++++++ swagger/paths/application/contacts/filter.yml | 16 ++++ swagger/paths/application/contacts/labels.yml | 38 ++++++++++ .../application/contacts/list_create.yml | 35 +++++++++ swagger/paths/application/contacts/search.yml | 29 +++++++ swagger/swagger.json | 75 +++++++++++++++++++ swagger/tag_groups/application_swagger.json | 75 +++++++++++++++++++ 8 files changed, 332 insertions(+) diff --git a/swagger/paths/application/contacts/conversations.yml b/swagger/paths/application/contacts/conversations.yml index b1bd7e522..4b7348c02 100644 --- a/swagger/paths/application/contacts/conversations.yml +++ b/swagger/paths/application/contacts/conversations.yml @@ -22,6 +22,24 @@ get: description: ID of the contact security: - userApiKey: [] + x-codeSamples: + - lang: python + label: "Get contact conversations" + source: | + from chatwoot import ChatwootClient + + client = ChatwootClient( + base_url="https://app.chatwoot.com", + api_token="your-api-token" + ) + + conversations = client.contacts.conversations( + account_id=1, + contact_id=100 + ) + + for conversation in conversations: + print(conversation.id, conversation.status) responses: '200': description: Success diff --git a/swagger/paths/application/contacts/crud.yml b/swagger/paths/application/contacts/crud.yml index dcabb145d..69bbdba65 100644 --- a/swagger/paths/application/contacts/crud.yml +++ b/swagger/paths/application/contacts/crud.yml @@ -15,6 +15,20 @@ get: security: - userApiKey: [] description: Get a contact belonging to the account using ID + x-codeSamples: + - lang: python + label: "Get contact details" + source: | + from chatwoot import ChatwootClient + + client = ChatwootClient( + base_url="https://app.chatwoot.com", + api_token="your-api-token" + ) + + contact = client.contacts.get(account_id=1, contact_id=100) + + print(contact.name, contact.email, contact.phone_number) responses: '200': description: Success @@ -43,6 +57,26 @@ put: security: - userApiKey: [] description: Update a contact belonging to the account using ID + x-codeSamples: + - lang: python + label: "Update a contact" + source: | + from chatwoot import ChatwootClient + + client = ChatwootClient( + base_url="https://app.chatwoot.com", + api_token="your-api-token" + ) + + contact = client.contacts.update( + account_id=1, + contact_id=100, + name="Jane Doe", + email="jane@example.com", + custom_attributes={"plan": "premium"} + ) + + print(contact.id, contact.name) requestBody: required: true content: @@ -77,6 +111,18 @@ delete: security: - userApiKey: [] description: Delete a contact belonging to the account using ID + x-codeSamples: + - lang: python + label: "Delete a contact" + source: | + from chatwoot import ChatwootClient + + client = ChatwootClient( + base_url="https://app.chatwoot.com", + api_token="your-api-token" + ) + + client.contacts.delete(account_id=1, contact_id=100) responses: '200': description: Success diff --git a/swagger/paths/application/contacts/filter.yml b/swagger/paths/application/contacts/filter.yml index 10d49f8c6..0c916caa6 100644 --- a/swagger/paths/application/contacts/filter.yml +++ b/swagger/paths/application/contacts/filter.yml @@ -6,6 +6,22 @@ post: summary: Contact Filter security: - userApiKey: [] + x-codeSamples: + - lang: python + label: "Filter contacts" + source: | + from chatwoot import ChatwootClient + + client = ChatwootClient( + base_url="https://app.chatwoot.com", + api_token="your-api-token" + ) + + # Use search to find contacts by name, email, or phone + contacts = client.contacts.search( + account_id=1, + query="example.com" + ) parameters: - $ref: '#/components/parameters/account_id' - name: page diff --git a/swagger/paths/application/contacts/labels.yml b/swagger/paths/application/contacts/labels.yml index a764e36b2..dd7cacc06 100644 --- a/swagger/paths/application/contacts/labels.yml +++ b/swagger/paths/application/contacts/labels.yml @@ -15,6 +15,24 @@ get: description: Lists all the labels of a contact security: - userApiKey: [] + x-codeSamples: + - lang: python + label: "List contact labels" + source: | + from chatwoot import ChatwootClient + + client = ChatwootClient( + base_url="https://app.chatwoot.com", + api_token="your-api-token" + ) + + labels = client.contacts.labels.list( + account_id=1, + contact_id=100 + ) + + print(labels) + # ['vip', 'enterprise'] responses: '200': description: Success @@ -43,6 +61,26 @@ post: description: Add labels to a contact. Note that this API would overwrite the existing list of labels associated to the conversation. security: - userApiKey: [] + x-codeSamples: + - lang: python + label: "Add labels to contact" + source: | + from chatwoot import ChatwootClient + + client = ChatwootClient( + base_url="https://app.chatwoot.com", + api_token="your-api-token" + ) + + # Note: this overwrites existing labels + labels = client.contacts.labels.add( + account_id=1, + contact_id=100, + labels=["vip", "enterprise"] + ) + + print(labels) + # ['vip', 'enterprise'] requestBody: required: true content: diff --git a/swagger/paths/application/contacts/list_create.yml b/swagger/paths/application/contacts/list_create.yml index eb5754a15..98b07cbd5 100644 --- a/swagger/paths/application/contacts/list_create.yml +++ b/swagger/paths/application/contacts/list_create.yml @@ -10,6 +10,21 @@ get: - $ref: '#/components/parameters/account_id' - $ref: '#/components/parameters/contact_sort_param' - $ref: '#/components/parameters/page' + x-codeSamples: + - lang: python + label: "List all contacts" + source: | + from chatwoot import ChatwootClient + + client = ChatwootClient( + base_url="https://app.chatwoot.com", + api_token="your-api-token" + ) + + contacts = client.contacts.list(account_id=1, page=1) + + for contact in contacts: + print(contact.name, contact.email) responses: '200': description: Success @@ -34,6 +49,26 @@ post: - userApiKey: [] parameters: - $ref: '#/components/parameters/account_id' + x-codeSamples: + - lang: python + label: "Create a contact" + source: | + from chatwoot import ChatwootClient + + client = ChatwootClient( + base_url="https://app.chatwoot.com", + api_token="your-api-token" + ) + + result = client.contacts.create( + account_id=1, + inbox_id=5, + name="John Doe", + email="john@example.com", + phone_number="+1234567890" + ) + + print(result.contact.id, result.contact_inbox.source_id) requestBody: required: true content: diff --git a/swagger/paths/application/contacts/search.yml b/swagger/paths/application/contacts/search.yml index 61075dc00..75306194a 100644 --- a/swagger/paths/application/contacts/search.yml +++ b/swagger/paths/application/contacts/search.yml @@ -15,6 +15,35 @@ get: description: Search using contact `name`, `identifier`, `email` or `phone number` - $ref: '#/components/parameters/contact_sort_param' - $ref: '#/components/parameters/page' + x-codeSamples: + - lang: python + label: "Search by email" + source: | + from chatwoot import ChatwootClient + + client = ChatwootClient( + base_url="https://app.chatwoot.com", + api_token="your-api-token" + ) + + contacts = client.contacts.search( + account_id=1, + query="john@example.com" + ) + + for contact in contacts: + print(contact.name, contact.email) + - lang: python + label: "Search by name" + source: | + from chatwoot import ChatwootClient + + client = ChatwootClient( + base_url="https://app.chatwoot.com", + api_token="your-api-token" + ) + + contacts = client.contacts.search(account_id=1, query="John Doe") responses: '200': description: Success diff --git a/swagger/swagger.json b/swagger/swagger.json index 00cf8007e..633af3741 100644 --- a/swagger/swagger.json +++ b/swagger/swagger.json @@ -2674,6 +2674,13 @@ "$ref": "#/components/parameters/page" } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "List all contacts", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\ncontacts = client.contacts.list(account_id=1, page=1)\n\nfor contact in contacts:\n print(contact.name, contact.email)\n" + } + ], "responses": { "200": { "description": "Success", @@ -2714,6 +2721,13 @@ "$ref": "#/components/parameters/account_id" } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "Create a contact", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\nresult = client.contacts.create(\n account_id=1,\n inbox_id=5,\n name=\"John Doe\",\n email=\"john@example.com\",\n phone_number=\"+1234567890\"\n)\n\nprint(result.contact.id, result.contact_inbox.source_id)\n" + } + ], "requestBody": { "required": true, "content": { @@ -2775,6 +2789,13 @@ } ], "description": "Get a contact belonging to the account using ID", + "x-codeSamples": [ + { + "lang": "python", + "label": "Get contact details", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\ncontact = client.contacts.get(account_id=1, contact_id=100)\n\nprint(contact.name, contact.email, contact.phone_number)\n" + } + ], "responses": { "200": { "description": "Success", @@ -2820,6 +2841,13 @@ } ], "description": "Update a contact belonging to the account using ID", + "x-codeSamples": [ + { + "lang": "python", + "label": "Update a contact", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\ncontact = client.contacts.update(\n account_id=1,\n contact_id=100,\n name=\"Jane Doe\",\n email=\"jane@example.com\",\n custom_attributes={\"plan\": \"premium\"}\n)\n\nprint(contact.id, contact.name)\n" + } + ], "requestBody": { "required": true, "content": { @@ -2875,6 +2903,13 @@ } ], "description": "Delete a contact belonging to the account using ID", + "x-codeSamples": [ + { + "lang": "python", + "label": "Delete a contact", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\nclient.contacts.delete(account_id=1, contact_id=100)\n" + } + ], "responses": { "200": { "description": "Success" @@ -2940,6 +2975,13 @@ "userApiKey": [] } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "Get contact conversations", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\nconversations = client.contacts.conversations(\n account_id=1,\n contact_id=100\n)\n\nfor conversation in conversations:\n print(conversation.id, conversation.status)\n" + } + ], "responses": { "200": { "description": "Success", @@ -3001,6 +3043,13 @@ "userApiKey": [] } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "List contact labels", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\nlabels = client.contacts.labels.list(\n account_id=1,\n contact_id=100\n)\n\nprint(labels)\n# ['vip', 'enterprise']\n" + } + ], "responses": { "200": { "description": "Success", @@ -3046,6 +3095,13 @@ "userApiKey": [] } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "Add labels to contact", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\n# Note: this overwrites existing labels\nlabels = client.contacts.labels.add(\n account_id=1,\n contact_id=100,\n labels=[\"vip\", \"enterprise\"]\n)\n\nprint(labels)\n# ['vip', 'enterprise']\n" + } + ], "requestBody": { "required": true, "content": { @@ -3138,6 +3194,18 @@ "$ref": "#/components/parameters/page" } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "Search by email", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\ncontacts = client.contacts.search(\n account_id=1,\n query=\"john@example.com\"\n)\n\nfor contact in contacts:\n print(contact.name, contact.email)\n" + }, + { + "lang": "python", + "label": "Search by name", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\ncontacts = client.contacts.search(account_id=1, query=\"John Doe\")\n" + } + ], "responses": { "200": { "description": "Success", @@ -3175,6 +3243,13 @@ "userApiKey": [] } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "Filter contacts", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\n# Use search to find contacts by name, email, or phone\ncontacts = client.contacts.search(\n account_id=1,\n query=\"example.com\"\n)\n" + } + ], "parameters": [ { "$ref": "#/components/parameters/account_id" diff --git a/swagger/tag_groups/application_swagger.json b/swagger/tag_groups/application_swagger.json index 61564a990..3e0f94454 100644 --- a/swagger/tag_groups/application_swagger.json +++ b/swagger/tag_groups/application_swagger.json @@ -1217,6 +1217,13 @@ "$ref": "#/components/parameters/page" } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "List all contacts", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\ncontacts = client.contacts.list(account_id=1, page=1)\n\nfor contact in contacts:\n print(contact.name, contact.email)\n" + } + ], "responses": { "200": { "description": "Success", @@ -1257,6 +1264,13 @@ "$ref": "#/components/parameters/account_id" } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "Create a contact", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\nresult = client.contacts.create(\n account_id=1,\n inbox_id=5,\n name=\"John Doe\",\n email=\"john@example.com\",\n phone_number=\"+1234567890\"\n)\n\nprint(result.contact.id, result.contact_inbox.source_id)\n" + } + ], "requestBody": { "required": true, "content": { @@ -1318,6 +1332,13 @@ } ], "description": "Get a contact belonging to the account using ID", + "x-codeSamples": [ + { + "lang": "python", + "label": "Get contact details", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\ncontact = client.contacts.get(account_id=1, contact_id=100)\n\nprint(contact.name, contact.email, contact.phone_number)\n" + } + ], "responses": { "200": { "description": "Success", @@ -1363,6 +1384,13 @@ } ], "description": "Update a contact belonging to the account using ID", + "x-codeSamples": [ + { + "lang": "python", + "label": "Update a contact", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\ncontact = client.contacts.update(\n account_id=1,\n contact_id=100,\n name=\"Jane Doe\",\n email=\"jane@example.com\",\n custom_attributes={\"plan\": \"premium\"}\n)\n\nprint(contact.id, contact.name)\n" + } + ], "requestBody": { "required": true, "content": { @@ -1418,6 +1446,13 @@ } ], "description": "Delete a contact belonging to the account using ID", + "x-codeSamples": [ + { + "lang": "python", + "label": "Delete a contact", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\nclient.contacts.delete(account_id=1, contact_id=100)\n" + } + ], "responses": { "200": { "description": "Success" @@ -1483,6 +1518,13 @@ "userApiKey": [] } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "Get contact conversations", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\nconversations = client.contacts.conversations(\n account_id=1,\n contact_id=100\n)\n\nfor conversation in conversations:\n print(conversation.id, conversation.status)\n" + } + ], "responses": { "200": { "description": "Success", @@ -1544,6 +1586,13 @@ "userApiKey": [] } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "List contact labels", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\nlabels = client.contacts.labels.list(\n account_id=1,\n contact_id=100\n)\n\nprint(labels)\n# ['vip', 'enterprise']\n" + } + ], "responses": { "200": { "description": "Success", @@ -1589,6 +1638,13 @@ "userApiKey": [] } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "Add labels to contact", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\n# Note: this overwrites existing labels\nlabels = client.contacts.labels.add(\n account_id=1,\n contact_id=100,\n labels=[\"vip\", \"enterprise\"]\n)\n\nprint(labels)\n# ['vip', 'enterprise']\n" + } + ], "requestBody": { "required": true, "content": { @@ -1681,6 +1737,18 @@ "$ref": "#/components/parameters/page" } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "Search by email", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\ncontacts = client.contacts.search(\n account_id=1,\n query=\"john@example.com\"\n)\n\nfor contact in contacts:\n print(contact.name, contact.email)\n" + }, + { + "lang": "python", + "label": "Search by name", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\ncontacts = client.contacts.search(account_id=1, query=\"John Doe\")\n" + } + ], "responses": { "200": { "description": "Success", @@ -1718,6 +1786,13 @@ "userApiKey": [] } ], + "x-codeSamples": [ + { + "lang": "python", + "label": "Filter contacts", + "source": "from chatwoot import ChatwootClient\n\nclient = ChatwootClient(\n base_url=\"https://app.chatwoot.com\",\n api_token=\"your-api-token\"\n)\n\n# Use search to find contacts by name, email, or phone\ncontacts = client.contacts.search(\n account_id=1,\n query=\"example.com\"\n)\n" + } + ], "parameters": [ { "$ref": "#/components/parameters/account_id"