Skip to main content

The MessageMedia Webhooks allows you to subscribe to one or several events and when one of those events is triggered, an HTTP request is sent to the URL of your choice along with the message or payload. In simpler terms, it allows applications to "speak" to one another and get notified automatically when something new happens.

Project description

## How to Build


You must have Python ```2 >=2.7.9``` or Python ```3 >=3.4``` installed on your system to install and run this SDK. This SDK package depends on other Python packages like nose, jsonpickle etc.
These dependencies are defined in the ```requirements.txt``` file that comes with the SDK.
To resolve these dependencies, you can use the PIP Dependency manager. Install it by following steps at [https://pip.pypa.io/en/stable/installing/](https://pip.pypa.io/en/stable/installing/).

Python and PIP executables should be defined in your PATH. Open command prompt and type ```pip --version```.
This should display the version of the PIP Dependency Manager installed if your installation was successful and the paths are properly defined.

* Using command line, navigate to the directory containing the generated files (including ```requirements.txt```) for the SDK.
* Run the command ```pip install -r requirements.txt```. This should install all the required dependencies.

![Building SDK - Step 1](https://apidocs.io/illustration/python?step=installDependencies&workspaceFolder=MessageMediaWebhooks-Python)


## How to Use

The following section explains how to use the MessageMediaWebhooks SDK package in a new project.

### 1. Open Project in an IDE

Open up a Python IDE like PyCharm. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.

![Open project in PyCharm - Step 1](https://apidocs.io/illustration/python?step=pyCharm)

Click on ```Open``` in PyCharm to browse to your generated SDK directory and then click ```OK```.

![Open project in PyCharm - Step 2](https://apidocs.io/illustration/python?step=openProject0&workspaceFolder=MessageMediaWebhooks-Python)

The project files will be displayed in the side bar as follows:

![Open project in PyCharm - Step 3](https://apidocs.io/illustration/python?step=openProject1&workspaceFolder=MessageMediaWebhooks-Python&projectName=message_media_webhooks)

### 2. Add a new Test Project

Create a new directory by right clicking on the solution name as shown below:

![Add a new project in PyCharm - Step 1](https://apidocs.io/illustration/python?step=createDirectory&workspaceFolder=MessageMediaWebhooks-Python&projectName=message_media_webhooks)

Name the directory as "test"

![Add a new project in PyCharm - Step 2](https://apidocs.io/illustration/python?step=nameDirectory)

Add a python file to this project with the name "testsdk"

![Add a new project in PyCharm - Step 3](https://apidocs.io/illustration/python?step=createFile&workspaceFolder=MessageMediaWebhooks-Python&projectName=message_media_webhooks)

Name it "testsdk"

![Add a new project in PyCharm - Step 4](https://apidocs.io/illustration/python?step=nameFile)

In your python file you will be required to import the generated python library using the following code lines

```Python
from message_media_webhooks.message_media_webhooks_client import MessageMediaWebhooksClient
```

![Add a new project in PyCharm - Step 4](https://apidocs.io/illustration/python?step=projectFiles&workspaceFolder=MessageMediaWebhooks-Python&libraryName=message_media_webhooks.message_media_webhooks_client&projectName=message_media_webhooks&className=MessageMediaWebhooksClient)

After this you can write code to instantiate an API client object, get a controller object and make API calls. Sample code is given in the subsequent sections.

### 3. Run the Test Project

To run the file within your test project, right click on your Python file inside your Test project and click on ```Run```

![Run Test Project - Step 1](https://apidocs.io/illustration/python?step=runProject&workspaceFolder=MessageMediaWebhooks-Python&libraryName=message_media_webhooks.message_media_webhooks_client&projectName=message_media_webhooks&className=MessageMediaWebhooksClient)


## How to Test

You can test the generated SDK and the server with automatically generated test
cases. unittest is used as the testing framework and nose is used as the test
runner. You can run the tests as follows:

1. From terminal/cmd navigate to the root directory of the SDK.
2. Invoke ```pip install -r test-requirements.txt```
3. Invoke ```nosetests```

## Initialization

### Authentication
In order to setup authentication and initialization of the API client, you need the following information.

| Parameter | Description |
|-----------|-------------|
| basic_auth_user_name | The username to use with basic authentication |
| basic_auth_password | The password to use with basic authentication |



API client can be initialized as following.

```python
# Configuration parameters and credentials
basic_auth_user_name = 'basic_auth_user_name' # The username to use with basic authentication
basic_auth_password = 'basic_auth_password' # The password to use with basic authentication

client = MessageMediaWebhooksClient(basic_auth_user_name, basic_auth_password)
```



# Class Reference

## <a name="list_of_controllers"></a>List of Controllers

* [WebhooksController](#webhooks_controller)

## <a name="webhooks_controller"></a>![Class: ](https://apidocs.io/img/class.png ".WebhooksController") WebhooksController

### Get controller instance

An instance of the ``` WebhooksController ``` class can be accessed from the API Client.

```python
webhooks_controller = client.webhooks
```

### <a name="create_webhook"></a>![Method: ](https://apidocs.io/img/method.png ".WebhooksController.create_webhook") create_webhook

> Create a webhook for one or more of the specified events.
> A webhook would typically have the following structure:
> ```
> {
> "url": "http://webhook.com",
> "method": "POST",
> "encoding": "JSON",
> "headers": {
> "Account": "DeveloperPortal7000"
> },
> "events": [
> "RECEIVED_SMS"
> ],
> "template": "{\"id\":\"$mtId\",\"status\":\"$statusCode\"}"
> }
> ```
> A valid webhook must consist of the following properties:
> - ```url``` The configured URL which will trigger the webhook when a selected event occurs.
> - ```method``` The methods to map CRUD (create, retrieve, update, delete) operations to HTTP requests.
> - ```encoding``` The format in which the payload will be returned. You can choose from ```JSON```, ```FORM_ENCODED``` or ```XML```. This will automatically add the Content-Type header for you so you don't have to add it again in the `headers` property.
> - ```headers``` HTTP header fields which provide required information about the request or response, or about the object sent in the message body. This should not include the `Content-Type` header.
> - ```events``` Event or events that will trigger the webhook. Atleast one event should be present.
> - ```template``` The structure of the payload that will be returned.
> #### Types of Events
> You can select all of the events (listed below) or combine them in whatever way you like but atleast one event must be used. Otherwise, the webhook won't be created.
> A webhook will be triggered when any one or more of the events occur:
> + **SMS**
> + `RECEIVED_SMS` Receive an SMS
> + `OPT_OUT_SMS` Opt-out occured
> + **MMS**
> + `RECEIVED_MMS` Receive an MMS
> + **DR (Delivery Reports)**
> + `ENROUTE_DR` Message is enroute
> + `EXPIRED_DR` Message has expired
> + `REJECTED_DR` Message is rejected
> + `FAILED_DR` Message has failed
> + `DELIVERED_DR` Message is delivered
> + `SUBMITTED_DR` Message is submitted
> #### Template Parameters
> You can choose what to include in the data that will be sent as the payload via the Webhook.
> Keep in my mind, you must escape the JSON in the template value (see example above).
> The table illustrates a list of all the parameters that can be included in the template and which event types it can be applied to.
> | Data | Parameter Name | Example | Event Type |
> |:--|--|--|--|--|
> | **Service Type** | $type| `SMS` | `DR` `MO` `MO MMS` |
> | **Message ID** | $mtId, $messageId| `877c19ef-fa2e-4cec-827a-e1df9b5509f7` | `DR` `MO` `MO MMS`|
> | **Delivery Report ID** |$drId, $reportId| `01e1fa0a-6e27-4945-9cdb-18644b4de043` | `DR` |
> | **Reply ID**| $moId, $replyId| `a175e797-2b54-468b-9850-41a3eab32f74` | `MO` `MO MMS` |
> | **Account ID** | $accountId| `DeveloperPortal7000` | `DR` `MO` `MO MMS` |
> | **Message Timestamp** | $submittedTimestamp| `2016-12-07T08:43:00.850Z` | `DR` `MO` `MO MMS` |
> | **Provider Timestamp** | $receivedTimestamp| `2016-12-07T08:44:00.850Z` | `DR` `MO` `MO MMS` |
> | **Message Status** | $status| `enroute` | `DR` |
> | **Status Code** | $statusCode| `200` | `DR` |
> | **External Metadata** | $metadata.get('key')| `name` | `DR` `MO` `MO MMS` |
> | **Source Address**| $sourceAddress| `+61491570156` | `DR` `MO` `MO MMS` |
> | **Destination Address**| $destinationAddress| `+61491593156` | `MO` `MO MMS` |
> | **Message Content**| $mtContent, $messageContent| `Hi Derp` | `DR` `MO` `MO MMS` |
> | **Reply Content**| $moContent, $replyContent| `Hello Derpina` | `MO` `MO MMS` |
> | **Retry Count**| $retryCount| `1` | `DR` `MO` `MO MMS` |
> *Note: A 400 response will be returned if the `url` is invalid, the `events`, `encoding` or `method` is null or the `headers` has a Content-Type attribute.*

```python
def create_webhook(self,
body)
```

#### Parameters

| Parameter | Tags | Description |
|-----------|------|-------------|
| body | ``` Required ``` | TODO: Add a parameter description |



#### Example Usage

```python
body = CreateWebhookRequest()

result = webhooks_controller.create_webhook(body)

```

#### Errors

| Error Code | Error Description |
|------------|-------------------|
| 400 | Unexpected error in API call. See HTTP response body for details. |
| 409 | Unexpected error in API call. See HTTP response body for details. |




### <a name="retrieve_webhook"></a>![Method: ](https://apidocs.io/img/method.png ".WebhooksController.retrieve_webhook") retrieve_webhook

> Retrieve all the webhooks created for the connected account.
> A successful request to the retrieve webhook endpoint will return a response body as follows:
> ```
> {
> "page": 0,
> "pageSize": 100,
> "pageData": [
> {
> "url": "https://webhook.com",
> "method": "POST",
> "id": "8805c9d8-bef7-41c7-906a-69ede93aa024",
> "encoding": "JSON",
> "events": [
> "RECEIVED_SMS"
> ],
> "headers": {},
> "template": "{\"id\":\"$mtId\", \"status\":\"$statusCode\"}"
> }
> ]
> }
> ```
> *Note: Response 400 is returned when the `page` query parameter is not valid or the `pageSize` query parameter is not valid.*

```python
def retrieve_webhook(self,
page=None,
page_size=None)
```

#### Parameters

| Parameter | Tags | Description |
|-----------|------|-------------|
| page | ``` Optional ``` | TODO: Add a parameter description |
| pageSize | ``` Optional ``` | TODO: Add a parameter description |



#### Example Usage

```python
page = 85
page_size = 85

result = webhooks_controller.retrieve_webhook(page, page_size)

```

#### Errors

| Error Code | Error Description |
|------------|-------------------|
| 400 | Unexpected error in API call. See HTTP response body for details. |




### <a name="delete_webhook"></a>![Method: ](https://apidocs.io/img/method.png ".WebhooksController.delete_webhook") delete_webhook

> Delete a webhook that was previously created for the connected account.
> A webhook can be cancelled by appending the UUID of the webhook to the endpoint and submitting a DELETE request to the /webhooks/messages endpoint.
> *Note: Only pre-created webhooks can be deleted. If an invalid or non existent webhook ID parameter is specified in the request, then a HTTP 404 Not Found response will be returned.*

```python
def delete_webhook(self,
webhook_id)
```

#### Parameters

| Parameter | Tags | Description |
|-----------|------|-------------|
| webhookId | ``` Required ``` | TODO: Add a parameter description |



#### Example Usage

```python
webhook_id = a7f11bb0-f299-4861-a5ca-9b29d04bc5ad

webhooks_controller.delete_webhook(webhook_id)

```

#### Errors

| Error Code | Error Description |
|------------|-------------------|
| 404 | TODO: Add an error description |




### <a name="update_webhook"></a>![Method: ](https://apidocs.io/img/method.png ".WebhooksController.update_webhook") update_webhook

> Update a webhook. You can update individual attributes or all of them by submitting a PATCH request to the /webhooks/messages endpoint (the same endpoint used above to delete a webhook)
> A successful request to the retrieve webhook endpoint will return a response body as follows:
> ```
> {
> "url": "https://webhook.com",
> "method": "POST",
> "id": "04442623-0961-464e-9cbc-ec50804e0413",
> "encoding": "JSON",
> "events": [
> "RECEIVED_SMS"
> ],
> "headers": {},
> "template": "{\"id\":\"$mtId\", \"status\":\"$statusCode\"}"
> }
> ```
> *Note: Only pre-created webhooks can be deleted. If an invalid or non existent webhook ID parameter is specified in the request, then a HTTP 404 Not Found response will be returned.*

```python
def update_webhook(self,
webhook_id,
body)
```

#### Parameters

| Parameter | Tags | Description |
|-----------|------|-------------|
| webhookId | ``` Required ``` | TODO: Add a parameter description |
| body | ``` Required ``` | TODO: Add a parameter description |



#### Example Usage

```python
webhook_id = a7f11bb0-f299-4861-a5ca-9b29d04bc5ad
body_value = " { \"url\": \"https://myurl.com\", \"method\": \"POST\", \"encoding\": \"FORM_ENCODED\", \"events\": [ \"ENROUTE_DR\" ], \"template\": \"{\\\"id\\\":\\\"$mtId\\\", \\\"status\\\":\\\"$statusCode\\\"}\" }"
body = json.loads(body_value)

result = webhooks_controller.update_webhook(webhook_id, body)

```

#### Errors

| Error Code | Error Description |
|------------|-------------------|
| 400 | Unexpected error in API call. See HTTP response body for details. |
| 404 | TODO: Add an error description |




[Back to List of Controllers](#list_of_controllers)




Platform: UNKNOWN

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

messagemedia_webhooks_sdk-1.0.0.tar.gz (27.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page