# Ravenhub API

## Send Notification

<mark style="color:green;">`POST`</mark> `https://api.ravenhub.io/company/:appId/subscribers/:subscriberId/events/:eventId`

Sends event data to Ravenhub which will trigger a notification(s) to be sent to the subscriber identified in the path. The body of the request can include JSON data that can be used in notification templates.

#### Path Parameters

| Name         | Type   | Description                                                                           |
| ------------ | ------ | ------------------------------------------------------------------------------------- |
| eventId      | string | Event Type ID which can be found in the Event Type section of the Ravenhub admin app. |
| subscriberId | string | Unique ID for the user who should receive the notification                            |
| appId        | string | Ravenhub app ID can be found in the top right corner of the Ravenhub admin app.       |

{% tabs %}
{% tab title="200 Successfully created the event" %}

```
event created successfully
```

{% endtab %}

{% tab title="400 Failed to create event" %}

```
failed to create event : <details>
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="curl" %}

```bash
curl https://api.ravenhub.io/company/MK6ey8wi3b/subscribers/foo1/events/owtDEKN0iP \
  -H 'Content-Type: application/json' \
  -d '{ "priority" : "Critical" }'

```

{% endtab %}

{% tab title="javascript" %}

```javascript
const subscriberId = 'foo1';
let endpoint = 'https://api.ravenhub.io/company/MK6ey8wi3b/subscribers/'
               + subscriberId + '/events/owtDEKN0iP';
 
axios.post(endpoint, { "priority" : "Critical" }, {
 headers: {'Content-type': 'application/json'}
});

```

{% endtab %}
{% endtabs %}

## Send Broadcast

<mark style="color:green;">`POST`</mark> `https://api.ravenhub.io/company/:appId/broadcasts/:broadcastId`

Sends broadcast notifications to the list of subscriber IDs specified in the body of the request. See example below for formatting. The body of the request can include JSON data that can be used in notification templates.

#### Path Parameters

| Name        | Type   | Description                                                                                                                                                                                      |
| ----------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| appId       | string | Ravenhub app ID can be found in the top right corner of the Ravenhub admin app.                                                                                                                  |
| broadcastId | string | Broadcast ID is automatically generated when you create a broadcast through the admin app. Find it on the broadcast page in the URL or in the API endpoint field when viewing the Broadcast page |

{% tabs %}
{% tab title="200 Successfully created the event" %}

```
event broadcast sent successfully
```

{% endtab %}

{% tab title="400 Failed to create event" %}

```
failed to send broadcast : <details>
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="curl" %}

```bash
curl https://api.ravenhub.io/company/MK6ey8wi3b/broadcasts/owtDEKN0iP \
  -H 'Content-Type: application/json' \
  -d '{"notifications":[{"subscriberId":"foo1"},{"subscriberId":"foo2"}]}'

```

{% endtab %}

{% tab title="javascript" %}

```javascript
var endpoint = 'https://api.ravenhub.io/company/MK6ey8wi3b/broadcasts/owtDEKN0iP';
/* 
   The "data" key is optional within each notification
   object in the notifications array below.
*/

var postBody =
{
  "notifications" : [
     {
       "subscriberId" : "foo1",
       "data" : {
                  "val1" : "hello again",
                  "val2" : "hi",
                  "urlvar" : "https://google.com"
                }
     },
     {
       "subscriberId" : "foo2",
       "data" : {
                  "val1" : "hello again",
                  "val2" : "hi",
                  "urlvar" : "https://yahoo.com"
                }
     }
  ]
}
axios.post(endpoint, postBody, {
  headers: {'Content-type': 'application/json'}
});

```

{% endtab %}
{% endtabs %}
