Code Monkey home page Code Monkey logo

webhooks-php-sdk's Introduction

MessageMedia Webhooks PHP SDK

Travis Build Status Pull Requests Welcome PHP version

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.

Webhooks Flow

Table of Contents

πŸ” Authentication

Authentication is done via API keys. Sign up at https://developers.messagemedia.com/register/ to get your API keys.

Requests are authenticated using HTTP Basic Auth or HMAC. Provide your API key as the auth_user_name and API secret as the auth_password.

⁉️ Errors

Our API returns standard HTTP success or error status codes. For errors, we will also include extra information about what went wrong encoded in the response as JSON. The most common status codes are listed below.

HTTP Status Codes

Code Title Description
400 Invalid Request The request was invalid
401 Unauthorized Your API credentials are invalid
403 Disabled feature Feature not enabled
404 Not Found The resource does not exist
50X Internal Server Error An error occurred with our API

πŸ“° Information

Slack and Mailing List

If you have any questions, comments, or concerns, please join our Slack channel: https://developers.messagemedia.com/collaborate/slack/

Alternatively you can email us at: [email protected]

Bug reports

If you discover a problem with the SDK, we would like to know about it. You can raise an issue or send an email to: [email protected]

Contributing

We welcome your thoughts on how we could best provide you with SDKs that would simplify how you consume our services in your application. You can fork and create pull requests for any features you would like to see or raise an issue

⭐ Installation

Run the Composer command to install the latest stable version of the Messages SDK:

composer require messagemedia/webhooks-sdk

🎬 Get Started

It's easy to get started. Simply enter the API Key and secret you obtained from the MessageMedia Developers Portal into the code snippet below.

Create a webhook

<?php
require_once('vendor/autoload.php');

$basicAuthUserName = 'YOUR_API_KEY'; // The username to use with basic authentication
$basicAuthPassword = 'YOUR_SECRET_KEY'; // The password to use with basic authentication

$client = new MessageMediaWebhooksLib\MessageMediaWebhooksClient($basicAuthUserName, $basicAuthPassword);

$webhooks = $client->getWebhooks();

$body = new MessageMediaWebhooksLib\Models\CreateWebhookRequest();
$body->url = "http://webhook.com/asdasd";
$body->method = "POST";
$body->encoding = "JSON";
$body->headers = array("x-your-webhook-custom-header" => "custom-value");
$body->events = array("RECEIVED_SMS");
$body->template = '{"id":"$mtId","status":"$statusCode"}';

$result = $webhooks->createWebhook($body);

Retrieve all webhooks

<?php
require_once('vendor/autoload.php');

$basicAuthUserName = 'YOUR_API_KEY'; // The username to use with basic authentication
$basicAuthPassword = 'YOUR_SECRET_KEY'; // The password to use with basic authentication

$client = new MessageMediaWebhooksLib\MessageMediaWebhooksClient($basicAuthUserName, $basicAuthPassword);

$webhooks = $client->getWebhooks();

$page  =  0;
$pageSize  =  10;

$result  =  $webhooks->retrieveWebhook($page, $pageSize);
print_r($result);

Update a webhook

You can get a webhook ID by looking at the id of each webhook created from the response of the above example.

<?php
require_once('vendor/autoload.php');

$basicAuthUserName = 'YOUR_API_KEY'; // The username to use with basic authentication
$basicAuthPassword = 'YOUR_SECRET_KEY'; // The password to use with basic authentication

$client = new MessageMediaWebhooksLib\MessageMediaWebhooksClient($basicAuthUserName, $basicAuthPassword);

$webhooks = $client->getWebhooks();

$webhookId = "YOUR_WEBHOOK_ID";

$body = new MessageMediaWebhooksLib\Models\CreateWebhookRequest();
$body->url = "http://webhook.com/some_new_url";
$body->method = "POST";
$body->encoding = "JSON";
$body->headers = array("Account" => "teasdasdst");
$body->events = array("RECEIVED_SMS");
$body->template = '{"id":"$mtId","status":"$statusCode"}';


$result = $webhooks->updateWebhook($webhookId, $body);

Delete a webhook

You can get a webhook ID by looking at the id of each webhook created from the response of the retrieve webhooks example.

<?php
require_once('vendor/autoload.php');

$basicAuthUserName = 'YOUR_API_KEY'; // The username to use with basic authentication
$basicAuthPassword = 'YOUR_SECRET_KEY'; // The password to use with basic authentication

$client = new MessageMediaWebhooksLib\MessageMediaWebhooksClient($basicAuthUserName, $basicAuthPassword);

$webhooks = $client->getWebhooks();

$webhookId = "YOUR_WEBHOOK_ID";

$webhooks->deleteWebhook($webhookId);

πŸ“• API Reference Documentation

Check out the full API documentation for more detailed information.

πŸ˜• Need help?

Please contact developer support at [email protected] or check out the developer portal at developers.messagemedia.com

πŸ“ƒ License

Apache License. See the LICENSE file.

webhooks-php-sdk's People

Contributors

ibrahimtareq avatar jamesdale avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

webhooks-php-sdk's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.