{"__v":7,"_id":"561d098a09e6540d002ff602","category":{"__v":13,"_id":"55a64fe680c8a30d00b325e0","pages":["55a652b680c8a30d00b325ec","55a65a4251457325000e4d40","55a6705b80c8a30d00b32686","55a772393efe0c2f0074c8fe","55a7ae383efe0c2f0074caaf","55ae2ba22723e51900898fa0","55ae32628576b92300291cb3","55b0b0bbe7abe62300f9a8bb","55b0c6def202b12100cda2e7","55bf80af19dd820d0008a006","55c06be7344dc40d00f55859","55c06ccb37298d0d00088c72","561d098a09e6540d002ff602"],"project":"54ad7b1d9219922100751796","version":"5505581f728deb23005ec0f4","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-15T12:19:50.489Z","from_sync":false,"order":1,"slug":"rest-api-coming-soon","title":"REST API"},"project":"54ad7b1d9219922100751796","user":"55a38410912a6e2300882b88","version":{"__v":4,"_id":"5505581f728deb23005ec0f4","forked_from":"54ad7b1d9219922100751799","project":"54ad7b1d9219922100751796","createdAt":"2015-03-15T09:59:59.748Z","releaseDate":"2015-03-15T09:59:59.748Z","categories":["55055820728deb23005ec0f5","55055820728deb23005ec0f6","554213dacbc48d0d001544ef","55421a598aeff51700a20db6","55a64fe680c8a30d00b325e0"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"2.0.0","version":"2.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-10-13T13:39:22.751Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":9,"body":"Hooks allow you to set up integrations which subscribe to certain events on vCita. When one of those events is triggered, we’ll send a HTTP POST payload to the hook’s configured URL.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"1. Events\"\n}\n[/block]\nWhen configuring a hook, you choose which events you would like to receive payloads for and where to send them. Most common events are related to the lifecycle of objects in the vCita system - objects being created, updated, and deleted. Some object types may have additional events related to their lifecycle. Payment objects, for example, also have a 'paid' event which is triggered when a payment is made.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"2. Entities\"\n}\n[/block]\nThe following entities are currently set up to work with hooks in the vCita system along with the events that are available for each one.\n  * Clients - 'created', 'updated', 'deleted'\n  * Appointments -  'created', 'updated', 'deleted'\n  * Payments -  'created', 'paid', 'updated', 'deleted'\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Subscribing to hooks\"\n}\n[/block]\nIn order to subscribe to a hook you would need to make a call to the subscription route with proper authentication headers and specify:\n- the entity type for which you want to receive updates\n- the event you are interested in\n- the target_url to which you want vCita to send updates (your server). \n\nThe entity and event type are sent in a single 'event' field by combining the entity and event type with a '/' character between them. If you want to be updated when a client is created the 'event' parameter should be passed as 'client/created'.  The parameters should be sent as a JSON string in the body of the POST.\n\nSo, if you are interested in receiving a ping every time a new payment has been made, you would make the following call:\n\nPOST https://hook.vcita.com/v1/subscriptions/standard/subscribe\n{\"event\":\":client/create\",\"target_url\":\"URL_TO_SEND_UPDATES\"}\n\nNote: The subscribe call needs to have the same authorization headers as every other call to the vCita API.\n\nIf the subscription was successful you will get the following response:\n{\n  \"response\": \"Subscribed\"\n}\n\nIf you wish to unsubscribe from receiving updates, you would make an unsubscribe call with the target_url set up to receive updates as follows:\n\nPOST https://hook.vcita.com/v1/subscriptions/standard/unsubscribe\n{\"target_url\":\"URL_TO_SEND_UPDATES\"}\n\nNote: The unsubscribe call needs to have the same authorization headers as every other call to the vCita API.\n\nIf the unsubscribe was successful you will get the following response:\n{\n  \"response\": \"Unsubscribed\"\n}","excerpt":"","slug":"hooks","type":"basic","title":"Hooks"}
Hooks allow you to set up integrations which subscribe to certain events on vCita. When one of those events is triggered, we’ll send a HTTP POST payload to the hook’s configured URL. [block:api-header] { "type": "basic", "title": "1. Events" } [/block] When configuring a hook, you choose which events you would like to receive payloads for and where to send them. Most common events are related to the lifecycle of objects in the vCita system - objects being created, updated, and deleted. Some object types may have additional events related to their lifecycle. Payment objects, for example, also have a 'paid' event which is triggered when a payment is made. [block:api-header] { "type": "basic", "title": "2. Entities" } [/block] The following entities are currently set up to work with hooks in the vCita system along with the events that are available for each one. * Clients - 'created', 'updated', 'deleted' * Appointments - 'created', 'updated', 'deleted' * Payments - 'created', 'paid', 'updated', 'deleted' [block:api-header] { "type": "basic", "title": "Subscribing to hooks" } [/block] In order to subscribe to a hook you would need to make a call to the subscription route with proper authentication headers and specify: - the entity type for which you want to receive updates - the event you are interested in - the target_url to which you want vCita to send updates (your server). The entity and event type are sent in a single 'event' field by combining the entity and event type with a '/' character between them. If you want to be updated when a client is created the 'event' parameter should be passed as 'client/created'. The parameters should be sent as a JSON string in the body of the POST. So, if you are interested in receiving a ping every time a new payment has been made, you would make the following call: POST https://hook.vcita.com/v1/subscriptions/standard/subscribe {"event":":client/create","target_url":"URL_TO_SEND_UPDATES"} Note: The subscribe call needs to have the same authorization headers as every other call to the vCita API. If the subscription was successful you will get the following response: { "response": "Subscribed" } If you wish to unsubscribe from receiving updates, you would make an unsubscribe call with the target_url set up to receive updates as follows: POST https://hook.vcita.com/v1/subscriptions/standard/unsubscribe {"target_url":"URL_TO_SEND_UPDATES"} Note: The unsubscribe call needs to have the same authorization headers as every other call to the vCita API. If the unsubscribe was successful you will get the following response: { "response": "Unsubscribed" }