<a id="4c058a309ae74ea1a320187cb6b6fae3"></a><a id="4c058a30-9ae7-4ea1-a320-187cb6b6fae3"></a>

# Subscription

A subscription has:

- url

- account

- event

- <em>list (soon)</em>

Once a URL is subscribed to one of the [Events](/help/crm-api-d1fe9ce8/webhooks-839ef351#9f6549fb6ba74066a05692f49cfb4629) available, we will send a POST to that url each time the event occurs within the account. 

<em>soon: If there is an associated list, the hook only triggers for contacts included in the list </em>

<a id="9f6549fb6ba74066a05692f49cfb4629"></a>

# Events

<em>staff note: see </em>[<em>HookSubscription::VALID\_EVENTS</em>](https://github.com/dwaynemac/crm-hub/blob/229dced253f56f6b6a5df9f377967b7b63043050/app/models/hook_subscription.rb#L19)

These are the currently available events:

- contact\_created - When a contact is created

- contact\_updated - When a contact is modified

- enrollment\_created - When a student is enrolled

- dropout\_created - When a student drops out

- communication\_created - When a communication is registered with a contact.

# Payload

<em>staff note: see </em>[<em>Contacts::Contact#as\_json</em>](https://github.com/dwaynemac/crm-hub/blob/3a936d469d070b1f802be9d5ba26c470f0951377/app/models/contacts/contact.rb#L128)

Currently all events send the same payload in the body in JSON format

```json
{
	padma_id: "xx",
	friendly_name: "Vicky",
	first_name: "Maria Victoria",
	last_name: "Sanchez",
	level: "sádhaka",
	email: "secret@info.com",
	phone: "12341234",
	in_professional_trainning: true,
	...
}
```

# ACTIONS / ENDPOINTS

## <a id="crear-uma-subscription" data-help-heading="true"></a>Create a subscription

```txt
POST https://crm.derose.app/api/v1/hook_subscriptions
```

This endpoint registers an address to receive the payload every time the event occurs on your account.

### <a id="parametros" data-help-heading="true"></a>Parameters

- api\_key
- hook\_subscription\_event
- hook\_subscription\_url

### Response

HTTP status: 201

JSON Body:

```json
{"id": subscription_id}
```

## <a id="cancelar-subscription" data-help-heading="true"></a>Cancel subscription

```txt
DELETE https://crm.derose.app/api/v1/hook_subscriptions/:id
```

### <a id="parametros-1" data-help-heading="true"></a>Parameters

- api\_key

### Response

HTTP Status: 200

Body:

```json
"destroyed"
```

## <a id="ver-subscription" data-help-heading="true"></a>View subscription

```txt
GET https://crm.derose.app/api/v1/hook_subscriptions/:id
```

### <a id="parametros-2" data-help-heading="true"></a>Parameters

- api\_key

### Response

HTTP Status: 200

Body:

```json
{
	"id": 2222,
	"url": "https://your-url.com/webhooks",
	"event": "enrollment_created"
}
```