Avannubo-SMS - Documentación

Ejemplos API

Autentificación

Puedes autentificarte de dos formas diferentes a nuestra API:

  • A través de un token fijo
  • A través de un token temporal

A través de un token

Crea o edita un usuario de tipo API para obtener un token para conectarte a la API.

A través de un token temporal

Los token temporales tienen un periodo de expiración después del cual se consideran caducados y serán rechazados, obligando al cliente a obtener un nuevo token. Esto aporta una capa de seguridad extra a tu aplicación.

En el siguiente ejemplo te enseñamos como obtener un token temporal para realizar peticiones a la API.


curl -i https://api.avannubo.com/v1/login -d email=put_here_your_email_here -d password=put_here_your_password


<?php
// Enter your email and password to access the site
define('EMAIL', 'ENTER_HERE_YOUR_EMAIL');
define('PASSWORD', 'ENTER_HERE_YOUR_PASSWORD');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_ACCESS_TOKEN',  API_VERSION.'/login');

// API AUTHENTIFICATION
$data = [
        'email'             =>   EMAIL,
        'password'          =>   PASSWORD,
];

// CURL REQUEST
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, BASE_URI.URL_ACCESS_TOKEN);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
$output = json_decode($output, true);

// CHECK THE REQUEST
if ( ! isset( $output['error'] ) )
{
    // Successful authentication.
    // We keep the response for use in API requests
    $token          = $output['data']['token'];
    $expires_in     = $output['data']['expires_in'];
    $expires_at     = $output['data']['expires_at'];

    var_dump($output);
}
else
{
    echo "There was errors in the authentication: ".$output['error']['message'];
    var_dump($output['error']);
    die();
}


<?php
require_once('../guzzle/autoloader.php');

// Enter your email and password to access the site
define('EMAIL', 'ENTER_HERE_YOUR_EMAIL');
define('PASSWORD', 'ENTER_HERE_YOUR_PASSWORD');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_ACCESS_TOKEN',  API_VERSION.'/login');

// API AUTHENTIFICATION
$data = [
    'email'             =>   EMAIL,
    'password'          =>   PASSWORD,
];

try
{
    $client = new GuzzleHttp\Client();

    $res = $client->request('POST', BASE_URI.URL_ACCESS_TOKEN, [
        'form_params' => $data
    ]);
}
catch (\GuzzleHttp\Exception\BadResponseException $e)
{
    // Catch BadResponseException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']);
    }
}
catch (RequestException $e)
{
    // Catch RequestException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']);
    }
}

$output = $res->getBody()->getContents();
$output = json_decode( $output, true);

// CHECK THE REQUEST
if ( ! isset( $output['error'] ) )
{
    // Successful authentication.
    // We keep the response for use in API requests
    $token          = $output['data']['token'];
    $expires_in     = $output['data']['expires_in'];
    $expires_at     = $output['data']['expires_at'];

    var_dump($output);
}
else
{
    echo "There was errors in the authentication: ".$output['error']['message'];
    var_dump($output['error']);
    die();
}


#! /usr/bin/env python
# -*- coding: utf-8 -*-

import json
import MultipartPostHandler
import urllib2

""" Enter your email and password to access the site. """
EMAIL = "ENTER_HERE_YOUR_EMAIL"
PASSWORD = "ENTER_HERE_YOUR_PASSWORD"

""" Do not change this """
BASE_URI = "https://api.avannubo.com/"
API_VERSION = "v1"
URL_ACCESS_TOKEN = "{0}/login".format( API_VERSION )

""" API AUTHENTIFICATION """
data = {
    'email'         : EMAIL,
    'password'      : PASSWORD
}

try:
    opener = urllib2.build_opener( MultipartPostHandler.MultipartPostHandler )
    output = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_ACCESS_TOKEN ), data ).read() )
except Exception, e:
    print "Something went wrong..."
    print type( e )
    print e
else:
    if 'error' not in output:
        """ Successful authentication. """
        """ We keep the response for use in API requests """
        token          = output['token']
        expires_in     = output['expires_in']
        expires_at     = output['expires_at']

        print "        token: {0}".format( token )
        print "   expires_in: {0}".format( expires_in )
        print "   expires_at: {0}".format( expires_at )
    else:
        print "There were errors in the authentication: {0}".format( output['error']['message'] )

Estrategias de autentificación con un token temporal

Si va a hacer un uso intensivo de la API con muchas peticiones en un intervalo corto de tiempo y utilizas un token temporal, te recomendamos seguir la siguiente estrategia de autentificación para optimizar las llamadas a nuestra API


    if ( thereAreTokenStored() )
    {
        if (! theTokenStoredIsValid() )
        {
            $authentication = authenticate();
        }
    }
    else
    {
        $authentication = authenticate();
    }


La función 'authenticate()' debe ser la encargada de realizar una petición para obtener un token válido. Si la petición es correcta, debe guardar en sesión/memoria los valores retornados ('token', 'expires_in', 'expires_at') para usarlos posteriormente.

La función 'thereAreTokenStored()' debe ser la encargada de comprobar si existen en sesión/memoria los datos de autentificación guardados previamente a través de la función 'authenticate()'

La función 'theTokenStoredIsValid()' debe ser la encargada de comprobar a través de la variable 'expires_in' o 'expires_at' que el token siga siendo válido.

Ejemplos envíos SMS

Envíos simples

En este ejemplo te enseñamos a realizar un envío simple a través de nuestra API.

Con un token fijo:


curl https://api.avannubo.com/v1/push/simple -d configuration_name=put_here_your_configuration_name_here -d message=put_here_your_message_here -d numbers=put_here_your_numbers_here -d api_token=put_your_api_token


<?php
// Enter your API TOKEN
define('API_TOKEN', 'ENTER_HERE_YOUR_API_TOKEN');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'Este es el texto del mensaje que queremos enviar');

// Enter the phone numbers separated by commas without spaces
// The phone numbers must contains the international prefix
define('NUMBERS', '34600100100,34600100200,34600100300');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_API_CALL', API_VERSION.'/push/simple');

// Post variables to add to the request.
$push_simple = array(
    'configuration_name'  =>  API_CONFIGURATION_NAME,
    'message'             =>  MESSAGE,
    'numbers'             =>  NUMBERS,
    'api_token'           =>  API_TOKEN
);

// CURL REQUEST FOR SIMPLE PUSH
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, BASE_URI.URL_API_CALL);
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $push_simple);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch2);
curl_close ($ch2);
$result = json_decode($result, true);


// CHECK THE REQUEST
if (isset($result['data']))
{
    // Successful response.
    var_dump($result['data']);
}
else if (isset($result['error']))
{
    //Api request failed
    echo "There was errors: ".$result['error']['message'];
    var_dump($result['error']);
}



<?php
require_once('../guzzle/autoloader.php');

// Enter your API TOKEN
define('API_TOKEN', 'ENTER_HERE_YOUR_API_TOKEN');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'Este es el texto del mensaje que queremos enviar');

// Enter the phone numbers separated by commas without spaces
// The phone numbers must contains the international prefix
define('NUMBERS', '34600100100,34600100200,34600100300');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_API_CALL', API_VERSION.'/push/simple');

// Post variables to add to the request.
$push_simple = array(
    'configuration_name'  =>  API_CONFIGURATION_NAME,
    'message'             =>  MESSAGE,
    'numbers'             =>  NUMBERS,
    'api_token'           =>  API_TOKEN
);

try
{
    $res = $client->request('POST', BASE_URI.URL_API_CALL,[
        'form_params'   => $push_simple,
    ]);
}
catch (\GuzzleHttp\Exception\BadResponseException $e)
{
    // Catch BadResponseException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']);
    }
}
catch (RequestException $e)
{
    // Catch RequestException

    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']);
    }
}

$result = $res->getBody()->getContents();
$result = json_decode( $result, true);

// CHECK THE REQUEST
if (isset($result['data']))
{
    // Successful response.
    var_dump($result['data']);
}
else if (isset($result['error']))
{
    //Api request failed
    echo "There was errors: ".$result['error']['message'];
    var_dump($result['error']);
}



#! /usr/bin/env python
# -*- coding: utf-8 -*-

import json
import MultipartPostHandler
import urllib2

""" Enter your API TOKEN. """
API_TOKEN = "ENTER_HERE_YOUR_API_TOKEN"

""" Set the API SEND CONFIGURATION """
""" Manage and create new configurations at https://sms.avannubo.com/api/configurations """
API_CONFIGURATION_NAME = "ENTER_YOUR_CONFIGURATION_NAME"

""" Set the message to be sent """
MESSAGE = "Este es el texto del mensaje que queremos enviar"

""" Enter the phone numbers separated by commas without spaces """
""" The phone numbers must contains the international prefix """
NUMBERS = "34600100100,34600100200,34600100300"

""" Do not change this """
BASE_URI = "https://api.avannubo.com/"
API_VERSION = "v1"
URL_API_CALL = "{0}/push/simple".format( API_VERSION )

""" Post variables to add to the request. """
push_simple = {
    'api_token'          : API_TOKEN,
    'configuration_name' : API_CONFIGURATION_NAME,
    'message'            : MESSAGE,
    'numbers'            : NUMBERS,
}

try:
    opener.addheaders = headers
    result = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_API_CALL ), push_simple ).read() )
except Exception, e:
    print "Something went wrong (push)..."
    print type(e)
    print e
else:
    """ CHECK THE REQUEST """
    if 'data' in result:
        print result['data']
    elif 'error' in result:
        print "There were errors: {0}".format( result['error']['message'] )
        print result

Con un token temporal:


curl -i https://api.avannubo.com/v1/login -d email=put_here_your_email_here -d password=put_here_your_password
curl -H "Authorization: Bearer put_here_your_token" https://api.avannubo.com/v1/push/simple -d configuration_name=put_here_your_configuration_name_here -d message=put_here_your_message_here -d numbers=put_here_your_numbers_here


<?php
// Enter your email and password to access the site
define('EMAIL', 'ENTER_HERE_YOUR_EMAIL');
define('PASSWORD', 'ENTER_HERE_YOUR_PASSWORD');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'Este es el texto del mensaje que queremos enviar');

// Enter the phone numbers separated by commas without spaces
// The phone numbers must contains the international prefix
define('NUMBERS', '34600100100,34600100200,34600100300');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_ACCESS_TOKEN',  API_VERSION.'/login');
define('URL_API_CALL', API_VERSION.'/push/simple');

// API AUTHENTIFICATION
$data = [
    'email'             =>   EMAIL,
    'password'          =>   PASSWORD,
];

// CURL REQUEST FOR AUTHENTIFICATION
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, BASE_URI.URL_ACCESS_TOKEN);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
$output = json_decode($output, true);

// CHECK THE REQUEST
if ( ! isset( $output['error'] ) )
{
    // Successful authentication.
    // We keep the response for use in API requests
    $token          = $output['data']['token'];
    $expires_in     = $output['data']['expires_in'];
    $expires_at     = $output['data']['expires_at'];

    // Add authorization header to the request
    // It contains the authorization for the request
    $headers = array(
    'Authorization: Bearer '.$token
    );

    // Post variables to add to the request.
    $push_simple = array(
        'configuration_name'  =>  API_CONFIGURATION_NAME,
        'message'             =>  MESSAGE,
        'numbers'             =>  NUMBERS,
    );

    // CURL REQUEST FOR SIMPLE PUSH
    $ch2 = curl_init();
    curl_setopt($ch2, CURLOPT_URL, BASE_URI.URL_API_CALL);
    curl_setopt($ch2, CURLOPT_POST, 1);
    curl_setopt($ch2, CURLOPT_POSTFIELDS, $push_simple);
    curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec ($ch2);
    curl_close ($ch2);
    $result = json_decode($result, true);


    // CHECK THE REQUEST
    if (isset($result['data']))
    {
        // Successful response.
        var_dump($result['data']);
    }
    else if (isset($result['error']))
    {
        //Api request failed
        echo "There was errors: ".$result['error']['message'];
        var_dump($result['error']);
    }
}
else
{
    //Authentication failed
    echo "There was errors in the authentication: ".$output['error'];
    var_dump($output['error']);
}


<?php
require_once('../guzzle/autoloader.php');

// Enter your email and password to access the site
define('EMAIL', 'ENTER_HERE_YOUR_EMAIL');
define('PASSWORD', 'ENTER_HERE_YOUR_PASSWORD');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'Este es el texto del mensaje que queremos enviar');

// Enter the phone numbers separated by commas without spaces
// The phone numbers must contains the international prefix
define('NUMBERS', '34600100100,34600100200,34600100300');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_ACCESS_TOKEN',  API_VERSION.'/login');
define('URL_API_CALL', API_VERSION.'/push/simple');

// API AUTHENTIFICATION
$data = [
    'email'             =>   EMAIL,
    'password'          =>   PASSWORD,
];

try
{
    $client = new GuzzleHttp\Client();

    $res = $client->request('POST', BASE_URI.URL_ACCESS_TOKEN, [
        'form_params' => $data
    ]);
}
catch (\GuzzleHttp\Exception\BadResponseException $e)
{
    // Catch BadResponseException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']['message']);
    }
}
catch (RequestException $e)
{
    // Catch RequestException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']['message']);
    }
}

$output = $res->getBody()->getContents();
$output = json_decode( $output, true);

// CHECK THE REQUEST
if ( ! isset( $output['error'] ) )
{
    // Successful authentication.
    // We keep the response for use in API requests
    $token          = $output['data']['token'];
    $expires_in     = $output['data']['expires_in'];
    $expires_at     = $output['data']['expires_at'];


    // Add authorization header to the request
    // It contains the authorization for the request
    $headers = array(
        'Authorization' => 'Bearer '.$token
    );

    // Post variables to add to the request.
    $push_simple = array(
    'configuration_name'  =>  API_CONFIGURATION_NAME,
    'message'             =>  MESSAGE,
    'numbers'             =>  NUMBERS,
    );

    try
    {
        $res = $client->request('POST', BASE_URI.URL_API_CALL,[
            'form_params'   => $push_simple,
            'headers'       => $headers,
        ]);
    }
    catch (\GuzzleHttp\Exception\BadResponseException $e)
    {
        // Catch BadResponseException
        if ($e->hasResponse())
        {
            $error = json_decode($e->getResponse()->getBody()->getContents(), true);
            die('Error: '.$error['error']);
        }
    }
    catch (RequestException $e)
    {
        // Catch RequestException

        if ($e->hasResponse())
        {
            $error = json_decode($e->getResponse()->getBody()->getContents(), true);
            die('Error: '.$error['error']);
        }
    }

    $result = $res->getBody()->getContents();
    $result = json_decode( $result, true);

    // CHECK THE REQUEST
    if (isset($result['data']))
    {
        // Successful response.
        var_dump($result['data']);
    }
    else if (isset($result['error']))
    {
        //Api request failed
        echo "There was errors: ".$result['error']['message'];
        var_dump($result['error']);
    }
}
else
{
    //Authentication failed
    echo "There was errors in the authentication: ".$output['error']['message'];
    var_dump($output['error']);
}


#! /usr/bin/env python
# -*- coding: utf-8 -*-

import json
import MultipartPostHandler
import urllib2

""" Enter your email and password to access the site. """
EMAIL = "ENTER_HERE_YOUR_EMAIL"
PASSWORD = "ENTER_HERE_YOUR_PASSWORD"

""" Set the API SEND CONFIGURATION """
""" Manage and create new configurations at https://sms.avannubo.com/api/configurations """
API_CONFIGURATION_NAME = "ENTER_YOUR_CONFIGURATION_NAME"

""" Set the message to be sent """
MESSAGE = "Este es el texto del mensaje que queremos enviar"

""" Enter the phone numbers separated by commas without spaces """
""" The phone numbers must contains the international prefix """
NUMBERS = "34600100100,34600100200,34600100300"

""" Do not change this """
BASE_URI = "https://api.avannubo.com/"
API_VERSION = "v1"
URL_ACCESS_TOKEN = "{0}/login".format( API_VERSION )
URL_API_CALL = "{0}/push/simple".format( API_VERSION )


""" API AUTHENTIFICATION """
data = {
    'email'         : EMAIL,
    'password'      : PASSWORD
}

try:
    opener = urllib2.build_opener( MultipartPostHandler.MultipartPostHandler )
    output = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_ACCESS_TOKEN ), data ).read() )
except Exception, e:
    print "Something went wrong (auth)..."
    print type( e )
    print e
else:
    if 'error' not in output:
        """ Successful authentication. """
        """ We keep the response for use in API requests """
        token          = output['token']
        expires_in     = output['expires_in']
        expires_at     = output['expires_at']

        """ Add authorization header to the request """
        """ It contains the authorization for the request """
        headers = [
            ( "Authorization", "Bearer {0}".format( token ) ),
        ]

        """ Post variables to add to the request. """
        push_simple = {
            'configuration_name' : API_CONFIGURATION_NAME,
            'message'            : MESSAGE,
            'numbers'            : NUMBERS,
        }

        try:
            opener.addheaders = headers
            result = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_API_CALL ), push_simple ).read() )
        except Exception, e:
            print "Something went wrong (push)..."
            print type(e)
            print e
        else:
            """ CHECK THE REQUEST """
            if 'data' in result:
                print result['data']
            elif 'error' in result:
                print "There were errors: {0}".format( result['error']['message'] )
                print result

    else:
        print "There were errors in the authentication: {0}".format( output['error']['message'] )

Envío múltiple API

En este ejemplo te enseñamos a crear un nuevo envío múltiple. Con el envío múltiple puedes enviar diferentes mensajes a cada número de teléfono hasta un máximo de 1000 destinatarios.

Con un token fijo:


curl https://api.avannubo.com/v1/push/multiple -d configuration_name=put_here_your_configuration_name_here -d messages=put_here_your_json_message_list -d api_token=put_your_api_token


<?php
// Enter your API TOKEN
define('API_TOKEN', 'ENTER_HERE_YOUR_API_TOKEN');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGES', '[{"number":"34600100200","message":"Message  2"},{"number":"34600100202","message":"Message 3"},{"number":"34600100203","message":"Message 4"}]');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_API_CALL', API_VERSION.'/push/multiple');

// Post variables to add to the request.
$push_simple = array(
    'configuration_name'  =>  API_CONFIGURATION_NAME,
    'messages'            =>  MESSAGES,
    'api_token'           =>  API_TOKEN
);

// CURL REQUEST FOR SIMPLE PUSH
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, BASE_URI.URL_API_CALL);
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $push_simple);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch2);
curl_close ($ch2);
$result = json_decode($result, true);

// CHECK THE REQUEST
if (isset($result['data']))
{
    // Successful response.
    var_dump($result['data']);
}
else if (isset($result['error']))
{
    //Api request failed
    echo "There was errors: ".$result['error']['message'];
    var_dump($result['error']);
}



<?php
require_once('../guzzle/autoloader.php');

// Enter your API TOKEN
define('API_TOKEN', 'ENTER_HERE_YOUR_API_TOKEN');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGES', '[{"number":"34600100200","message":"Message  2"},{"number":"34600100202","message":"Message 3"},{"number":"34600100203","message":"Message 4"}]');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_API_CALL', API_VERSION.'/push/multiple');

// Post variables to add to the request.
$push_simple = array(
    'configuration_name'  =>  API_CONFIGURATION_NAME,
    'messages'            =>  MESSAGES,
    'api_token'           =>  API_TOKEN
);

try
{
    $res = $client->request('POST', BASE_URI.URL_API_CALL,[
        'form_params'   => $push_simple,
    ]);
}
catch (\GuzzleHttp\Exception\BadResponseException $e)
{
    // Catch BadResponseException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']);
    }
}
catch (RequestException $e)
{
    // Catch RequestException

    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']);
    }
}

$result = $res->getBody()->getContents();
$result = json_decode( $result, true);

// CHECK THE REQUEST
if (isset($result['data']))
{
    // Successful response.
    var_dump($result['data']);
}
else if (isset($result['error']))
{
    //Api request failed
    echo "There was errors: ".$result['error']['message'];
    var_dump($result['error']);
}



#! /usr/bin/env python
# -*- coding: utf-8 -*-

import json
import MultipartPostHandler
import urllib2

""" Enter your API TOKEN. """
API_TOKEN = "ENTER_HERE_YOUR_API_TOKEN"

""" Set the API SEND CONFIGURATION """
""" Manage and create new configurations at https://sms.avannubo.com/api/configurations """
API_CONFIGURATION_NAME = "ENTER_YOUR_CONFIGURATION_NAME"

""" Set the message to be sent """
MESSAGES = '[{"number":"34600100200","message":"Message  2"},{"number":"34600100202","message":"Message 3"},{"number":"34600100203","message":"Message 4"}]'

""" Do not change this """
BASE_URI = "https://api.avannubo.com/"
API_VERSION = "v1"
URL_API_CALL = "{0}/push/multiple".format( API_VERSION )

""" Post variables to add to the request. """
push_simple = {
    'api_token'          : API_TOKEN,
    'configuration_name' : API_CONFIGURATION_NAME,
    'messages'           : MESSAGES
}

try:
    opener.addheaders = headers
    result = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_API_CALL ), push_simple ).read() )
except Exception, e:
    print "Something went wrong (push)..."
    print type(e)
    print e
else:
    """ CHECK THE REQUEST """
    if 'data' in result:
        print result['data']
    elif 'error' in result:
        print "There were errors: {0}".format( result['error']['message'] )
        print result

Con un token temporal:


curl -i https://api.avannubo.com/v1/login -d email=put_here_your_email_here -d password=put_here_your_password
curl -H "Authorization: Bearer put_here_your_token" https://api.avannubo.com/v1/push/multiple -d configuration_name=put_here_your_configuration_name_here -d messages=put_here_your_json_message_list


<?php
// Enter your email and password to access the site
define('EMAIL', 'ENTER_HERE_YOUR_EMAIL');
define('PASSWORD', 'ENTER_HERE_YOUR_PASSWORD');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGES', '[{"number":"34600100200","message":"Message  2"},{"number":"34600100202","message":"Message 3"},{"number":"34600100203","message":"Message 4"}]');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_ACCESS_TOKEN',  API_VERSION.'/login');
define('URL_API_CALL', API_VERSION.'/push/multiple');

// API AUTHENTIFICATION
$data = [
    'email'             =>   EMAIL,
    'password'          =>   PASSWORD,
];

// CURL REQUEST FOR AUTHENTIFICATION
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, BASE_URI.URL_ACCESS_TOKEN);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
$output = json_decode($output, true);

// CHECK THE REQUEST
if ( ! isset( $output['error'] ) )
{
    // Successful authentication.
    // We keep the response for use in API requests
    $token          = $output['data']['token'];
    $expires_in     = $output['data']['expires_in'];
    $expires_at     = $output['data']['expires_at'];

    // Add authorization header to the request
    // It contains the authorization for the request
    $headers = array(
    'Authorization: Bearer '.$token
    );

    // Post variables to add to the request.
    $push_simple = array(
        'configuration_name'  =>  API_CONFIGURATION_NAME,
        'messages'            =>  MESSAGES,
    );

    // CURL REQUEST FOR SIMPLE PUSH
    $ch2 = curl_init();
    curl_setopt($ch2, CURLOPT_URL, BASE_URI.URL_API_CALL);
    curl_setopt($ch2, CURLOPT_POST, 1);
    curl_setopt($ch2, CURLOPT_POSTFIELDS, $push_simple);
    curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec ($ch2);
    curl_close ($ch2);
    $result = json_decode($result, true);


    // CHECK THE REQUEST
    if (isset($result['data']))
    {
        // Successful response.
        var_dump($result['data']);
    }
    else if (isset($result['error']))
    {
        //Api request failed
        echo "There was errors: ".$result['error']['message'];
        var_dump($result['error']);
    }
}
else
{
    //Authentication failed
    echo "There was errors in the authentication: ".$output['error'];
    var_dump($output['error']);
}


<?php
require_once('../guzzle/autoloader.php');

// Enter your email and password to access the site
define('EMAIL', 'ENTER_HERE_YOUR_EMAIL');
define('PASSWORD', 'ENTER_HERE_YOUR_PASSWORD');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGES', '[{"number":"34600100200","message":"Message  2"},{"number":"34600100202","message":"Message 3"},{"number":"34600100203","message":"Message 4"}]');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_ACCESS_TOKEN',  API_VERSION.'/login');
define('URL_API_CALL', API_VERSION.'/push/multiple');

// API AUTHENTIFICATION
$data = [
    'email'             =>   EMAIL,
    'password'          =>   PASSWORD,
];

try
{
    $client = new GuzzleHttp\Client();

    $res = $client->request('POST', BASE_URI.URL_ACCESS_TOKEN, [
        'form_params' => $data
    ]);
}
catch (\GuzzleHttp\Exception\BadResponseException $e)
{
    // Catch BadResponseException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']['message']);
    }
}
catch (RequestException $e)
{
    // Catch RequestException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']['message']);
    }
}

$output = $res->getBody()->getContents();
$output = json_decode( $output, true);

// CHECK THE REQUEST
if ( ! isset( $output['error'] ) )
{
    // Successful authentication.
    // We keep the response for use in API requests
    $token          = $output['data']['token'];
    $expires_in     = $output['data']['expires_in'];
    $expires_at     = $output['data']['expires_at'];


    // Add authorization header to the request
    // It contains the authorization for the request
    $headers = array(
        'Authorization' => 'Bearer '.$token
    );

    // Post variables to add to the request.
    $push_simple = array(
    'configuration_name'  =>  API_CONFIGURATION_NAME,
    'messages'            =>  MESSAGES,
    );

    try
    {
        $res = $client->request('POST', BASE_URI.URL_API_CALL,[
            'form_params'   => $push_simple,
            'headers'       => $headers,
        ]);
    }
    catch (\GuzzleHttp\Exception\BadResponseException $e)
    {
        // Catch BadResponseException
        if ($e->hasResponse())
        {
            $error = json_decode($e->getResponse()->getBody()->getContents(), true);
            die('Error: '.$error['error']);
        }
    }
    catch (RequestException $e)
    {
        // Catch RequestException

        if ($e->hasResponse())
        {
            $error = json_decode($e->getResponse()->getBody()->getContents(), true);
            die('Error: '.$error['error']);
        }
    }

    $result = $res->getBody()->getContents();
    $result = json_decode( $result, true);

    // CHECK THE REQUEST
    if (isset($result['data']))
    {
        // Successful response.
        var_dump($result['data']);
    }
    else if (isset($result['error']))
    {
        //Api request failed
        echo "There was errors: ".$result['error']['message'];
        var_dump($result['error']);
    }
}
else
{
    //Authentication failed
    echo "There was errors in the authentication: ".$output['error']['message'];
    var_dump($output['error']);
}


#! /usr/bin/env python
# -*- coding: utf-8 -*-

import json
import MultipartPostHandler
import urllib2

""" Enter your email and password to access the site. """
EMAIL = "ENTER_HERE_YOUR_EMAIL"
PASSWORD = "ENTER_HERE_YOUR_PASSWORD"

""" Set the API SEND CONFIGURATION """
""" Manage and create new configurations at https://sms.avannubo.com/api/configurations """
API_CONFIGURATION_NAME = "ENTER_YOUR_CONFIGURATION_NAME"

""" Set the message to be sent """
MESSAGES = '[{"number":"34600100200","message":"Message  2"},{"number":"34600100202","message":"Message 3"},{"number":"34600100203","message":"Message 4"}]'


""" Do not change this """
BASE_URI = "https://api.avannubo.com/"
API_VERSION = "v1"
URL_ACCESS_TOKEN = "{0}/login".format( API_VERSION )
URL_API_CALL = "{0}/push/multiple".format( API_VERSION )


""" API AUTHENTIFICATION """
data = {
    'email'         : EMAIL,
    'password'      : PASSWORD
}

try:
    opener = urllib2.build_opener( MultipartPostHandler.MultipartPostHandler )
    output = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_ACCESS_TOKEN ), data ).read() )
except Exception, e:
    print "Something went wrong (auth)..."
    print type( e )
    print e
else:
    if 'error' not in output:
        """ Successful authentication. """
        """ We keep the response for use in API requests """
        token          = output['token']
        expires_in     = output['expires_in']
        expires_at     = output['expires_at']

        """ Add authorization header to the request """
        """ It contains the authorization for the request """
        headers = [
            ( "Authorization", "Bearer {0}".format( token ) ),
        ]

        """ Post variables to add to the request. """
        push_simple = {
            'configuration_name' : API_CONFIGURATION_NAME,
            'messages'           : MESSAGES
        }

        try:
            opener.addheaders = headers
            result = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_API_CALL ), push_simple ).read() )
        except Exception, e:
            print "Something went wrong (push)..."
            print type(e)
            print e
        else:
            """ CHECK THE REQUEST """
            if 'data' in result:
                print result['data']
            elif 'error' in result:
                print "There were errors: {0}".format( result['error']['message'] )
                print result

    else:
        print "There were errors in the authentication: {0}".format( output['error']['message'] )

Campañas - Configuración simple

En este ejemplo te enseñamos a crear una nueva campaña a través de nuestra API.

Con un token fijo:


curl https://api.avannubo.com/v1/push/campaigns -d name=put_here_your_name -d configuration_name=put_here_your_configuration_name_here -d message=put_here_your_message_here -d available_groups=put_here_your_available_groups -d api_token=put_your_api_token


<?php
// Enter your API TOKEN
define('API_TOKEN', 'ENTER_HERE_YOUR_API_TOKEN');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'This is the message to send');

// Enter the campaign name
define('NAME', 'Test Campaign Simple');

// Enter the agenda groups to send the message
define('AVAILABLE_GROUPS', '3,4');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_API_CALL', API_VERSION.'/push/campaigns');

// Post variables to add to the request.
$campaign = array(
    'configuration_name'  =>  API_CONFIGURATION_NAME,
    'message'             =>  MESSAGE,
    'name'                =>  NAME,
    'available_groups'    =>  AVAILABLE_GROUPS,
    'api_token'           =>  API_TOKEN
);

// CURL REQUEST FOR SIMPLE PUSH
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, BASE_URI.URL_API_CALL);
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $campaign);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch2);
curl_close ($ch2);
$result = json_decode($result, true);

// CHECK THE REQUEST
if (isset($result['data']))
{
    // Successful response.
    var_dump($result['data']);
}
else if (isset($result['error']))
{
    //Api request failed
    echo "There was errors: ".$result['error']['message'];
    var_dump($result['error']);
}


<?php
require_once('../guzzle/autoloader.php');

// Enter your API TOKEN
define('API_TOKEN', 'ENTER_HERE_YOUR_API_TOKEN');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'This is the message to send');

// Enter the campaign name
define('NAME', 'Test Campaign Simple');

// Enter the agenda groups to send the message
define('AVAILABLE_GROUPS', '3,4');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_API_CALL', API_VERSION.'/push/campaigns');

// Post variables to add to the request.
$campaign = array(
    'configuration_name'  =>  API_CONFIGURATION_NAME,
    'message'             =>  MESSAGE,
    'name'                =>  NAME,
    'available_groups'    =>  AVAILABLE_GROUPS,
    'api_token'           =>  API_TOKEN
);

try
{
    $res = $client->request('POST', BASE_URI.URL_API_CALL,[
        'form_params'   => $campaign,
    ]);
}
catch (\GuzzleHttp\Exception\BadResponseException $e)
{
    // Catch BadResponseException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']['message']);
    }
}
catch (RequestException $e)
{
    // Catch RequestException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']['message']);
    }
}

$result = $res->getBody()->getContents();
$result = json_decode( $result, true);

// CHECK THE REQUEST
if (isset($result['data']))
{
    // Successful response.
    var_dump($result['data']);
}
else if (isset($result['error']))
{
    //Api request failed
    echo "There was errors: ".$result['error']['message'];
    var_dump($result['error']);
}


#! /usr/bin/env python
# -*- coding: utf-8 -*-

import json
import MultipartPostHandler
import urllib2

""" Enter your API TOKEN. """
API_TOKEN = "ENTER_HERE_YOUR_API_TOKEN"

""" Set the API SEND CONFIGURATION """
""" Manage and create new configurations at https://sms.avannubo.com/api/configurations """
API_CONFIGURATION_NAME = "ENTER_YOUR_CONFIGURATION_NAME"

""" Set the message to be sent """
MESSAGE = "This is the message to send"

""" Enter the campaign name """
NAME = "Test Campaign Simple"

""" Enter the agenda groups to send the message """
AVAILABLE_GROUPS = "3,4"

""" Do not change this """
BASE_URI = "https://api.avannubo.com/"
API_VERSION = "v1"
URL_API_CALL = "{0}/push/campaigns".format( API_VERSION )

""" Post variables to add to the request. """
campaign = {
    'api_token'          : API_TOKEN,
    'configuration_name' : API_CONFIGURATION_NAME,
    'message'            : MESSAGE,
    'name'               : NAME,
    'available_groups'   : AVAILABLE_GROUPS,
}

try:
    opener.addheaders = headers
    result = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_API_CALL ), campaign ).read() )
except Exception, e:
    print "Something went wrong (campaign)..."
    print type(e)
    print e
else:
    """ CHECK THE REQUEST """
    if 'data' in result:
        print result['data']
    elif 'error' in result:
        print "There were errors: {0}".format( result['error']['message'] )
        print result

Con un token temporal:


curl -i https://api.avannubo.com/v1/login -d email=put_here_your_email_here -d password=put_here_your_password
curl -H "Authorization: Bearer put_here_your_token" https://api.avannubo.com/v1/push/campaigns -d name=put_here_your_name -d configuration_name=put_here_your_configuration_name_here -d message=put_here_your_message_here -d available_groups=put_here_your_available_groups


<?php
// Enter your email and password to access the site
define('EMAIL', 'ENTER_HERE_YOUR_EMAIL');
define('PASSWORD', 'ENTER_HERE_YOUR_PASSWORD');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'This is the message to send');

// Enter the campaign name
define('NAME', 'Test Campaign Simple');

// Enter the agenda groups to send the message
define('AVAILABLE_GROUPS', '3,4');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_ACCESS_TOKEN',  API_VERSION.'/login');
define('URL_API_CALL', API_VERSION.'/push/campaigns');

// API AUTHENTIFICATION
$data = [
    'email'             =>   EMAIL,
    'password'          =>   PASSWORD,
];

// CURL REQUEST FOR AUTHENTIFICATION
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, BASE_URI.URL_ACCESS_TOKEN);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
$output = json_decode($output, true);

// CHECK THE REQUEST
if ( ! isset( $output['error'] ) )
{
    // Successful authentication.
    // We keep the response for use in API requests
    $token          = $output['data']['token'];
    $expires_in     = $output['data']['expires_in'];
    $expires_at     = $output['data']['expires_at'];

    // Add authorization header to the request
    // It contains the authorization for the request
    $headers = array(
        'Authorization: Bearer '.$token
    );

    // Post variables to add to the request.
    $campaign = array(
        'configuration_name'  =>  API_CONFIGURATION_NAME,
        'message'             =>  MESSAGE,
        'name'                =>  NAME,
        'available_groups'    =>  AVAILABLE_GROUPS,
    );

    // CURL REQUEST FOR SIMPLE PUSH
    $ch2 = curl_init();
    curl_setopt($ch2, CURLOPT_URL, BASE_URI.URL_API_CALL);
    curl_setopt($ch2, CURLOPT_POST, 1);
    curl_setopt($ch2, CURLOPT_POSTFIELDS, $campaign);
    curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec ($ch2);
    curl_close ($ch2);
    $result = json_decode($result, true);

    // CHECK THE REQUEST
    if (isset($result['data']))
    {
        // Successful response.
        var_dump($result['data']);
    }
    else if (isset($result['error']))
    {
        //Api request failed
        echo "There was errors: ".$result['error']['message'];
        var_dump($result['error']);
    }
}
else
{
    //Authentication failed
    echo "There was errors in the authentication: ".$output['error']['message'];
    var_dump($output['error']);
}


<?php
require_once('../guzzle/autoloader.php');

// Enter your email and password to access the site
define('EMAIL', 'ENTER_HERE_YOUR_EMAIL');
define('PASSWORD', 'ENTER_HERE_YOUR_PASSWORD');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'This is the message to send');

// Enter the campaign name
define('NAME', 'Test Campaign Simple');

// Enter the agenda groups to send the message
define('AVAILABLE_GROUPS', '3,4');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_ACCESS_TOKEN',  API_VERSION.'/login');
define('URL_API_CALL', API_VERSION.'/push/campaigns');

// API AUTHENTIFICATION
$data = [
    'email'             =>   EMAIL,
    'password'          =>   PASSWORD,
];

try
{
    $client = new GuzzleHttp\Client();

    $res = $client->request('POST', BASE_URI.URL_ACCESS_TOKEN, [
    'form_params' => $data
    ]);
}
catch (\GuzzleHttp\Exception\BadResponseException $e)
{
    // Catch BadResponseException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']);
    }
}
catch (RequestException $e)
{
    // Catch RequestException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']);
    }
}

$output = $res->getBody()->getContents();
$output = json_decode( $output, true);

// CHECK THE REQUEST
if ( ! isset( $output['error'] ) )
{
    // Successful authentication.
    // We keep the response for use in API requests
    $token          = $output['data']['token'];
    $expires_in     = $output['data']['expires_in'];
    $expires_at     = $output['data']['expires_at'];

    // Add authorization header to the request
    // It contains the authorization for the request
    $headers = array(
        'Authorization' => 'Bearer '.$token
    );

    // Post variables to add to the request.
    $campaign = array(
        'configuration_name'  =>  API_CONFIGURATION_NAME,
        'message'             =>  MESSAGE,
        'name'                =>  NAME,
        'available_groups'    =>  AVAILABLE_GROUPS,
    );

    try
    {
        $res = $client->request('POST', BASE_URI.URL_API_CALL,[
            'form_params'   => $campaign,
            'headers'       => $headers,
        ]);
    }
    catch (\GuzzleHttp\Exception\BadResponseException $e)
    {
        // Catch BadResponseException
        if ($e->hasResponse())
        {
            $error = json_decode($e->getResponse()->getBody()->getContents(), true);
            die('Error: '.$error['error']['message']);
        }
    }
    catch (RequestException $e)
    {
        // Catch RequestException
        if ($e->hasResponse())
        {
            $error = json_decode($e->getResponse()->getBody()->getContents(), true);
            die('Error: '.$error['error']['message']);
        }
    }

    $result = $res->getBody()->getContents();
    $result = json_decode( $result, true);

    // CHECK THE REQUEST
    if (isset($result['data']))
    {
        // Successful response.
        var_dump($result['data']);
    }
    else if (isset($result['error']))
    {
        //Api request failed
        echo "There was errors: ".$result['error']['message'];
        var_dump($result['error']);
    }
}
else
{
    //Authentication failed
    echo "There was errors in the authentication: ".$output['error']['message'];
    var_dump($output['error']);
}


#! /usr/bin/env python
# -*- coding: utf-8 -*-

import json
import MultipartPostHandler
import urllib2

""" Enter your email and password to access the site. """
EMAIL = "ENTER_HERE_YOUR_EMAIL"
PASSWORD = "ENTER_HERE_YOUR_PASSWORD"

""" Set the API SEND CONFIGURATION """
""" Manage and create new configurations at https://sms.avannubo.com/api/configurations """
API_CONFIGURATION_NAME = "ENTER_YOUR_CONFIGURATION_NAME"

""" Set the message to be sent """
MESSAGE = "This is the message to send"

""" Enter the campaign name """
NAME = "Test Campaign Simple"

""" Enter the agenda groups to send the message """
AVAILABLE_GROUPS = "3,4"

""" Do not change this """
BASE_URI = "https://api.avannubo.com/"
API_VERSION = "v1"
URL_ACCESS_TOKEN = "{0}/login".format( API_VERSION )
URL_API_CALL = "{0}/push/campaigns".format( API_VERSION )


""" API AUTHENTIFICATION """
data = {
    'email'         : EMAIL,
    'password'      : PASSWORD
}

try:
    opener = urllib2.build_opener( MultipartPostHandler.MultipartPostHandler )
    output = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_ACCESS_TOKEN ), data ).read() )
except Exception, e:
    print "Something went wrong (auth)..."
    print type( e )
    print e
else:
    if 'error' not in output:
        """ Successful authentication. """
        """ We keep the response for use in API requests """
        token          = output['token']
        expires_in     = output['expires_in']
        expires_at     = output['expires_at']

        """ Add authorization header to the request """
        """ It contains the authorization for the request """
        headers = [
            ( "Authorization", "Bearer {0}".format( token ) ),
        ]

        """ Post variables to add to the request. """
        campaign = {
            'configuration_name' : API_CONFIGURATION_NAME,
            'message'            : MESSAGE,
            'name'               : NAME,
            'available_groups'   : AVAILABLE_GROUPS,
        }

        try:
            opener.addheaders = headers
            result = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_API_CALL ), campaign ).read() )
        except Exception, e:
            print "Something went wrong (campaign)..."
            print type(e)
            print e
        else:
            """ CHECK THE REQUEST """
            if 'data' in result:
                print result['data']
            elif 'error' in result:
                print "There were errors: {0}".format( result['error']['message'] )
                print result

    else:
        print "There were errors in the authentication: {0}".format( output['error']['message'] )

Campañas - Configuración múltiple

En este ejemplo te enseñamos a crear una nueva campaña con configuración múltiple a través de nuestra API.

Las campañas de tipo múltiple son campañas en las que definimos la forma en la que se enviarán los mensajes, pudiendo definir el número de mensajes que se enviarán por bloque (smsxblock) y cada cuantos minutos se enviarán dichos bloques (minutesxblock). También podemos definir el horario permitido de envio de los mensajes (time_intervals) y los días de la semana permitidos para el envío (days).

Con un token fijo:


curl https://api.avannubo.com/v1/push/campaigns -d name=put_here_your_name -d configuration_name=put_here_your_configuration_name_here -d message=put_here_your_message_here -d available_groups=put_here_your_available_groups -d start_date=put_here_your_start_date -d minutesxblock=put_here_your_minutesxblock -d smsxblock=put_here_your_smsxblock -d days=put_here_your_days -d time_intervals=put_here_your_time_intervals -d api_token=put_your_api_token


<?php
// Enter your API TOKEN
define('API_TOKEN', 'ENTER_HERE_YOUR_API_TOKEN');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'This is the message to send');

// Enter the campaign name
define('NAME', 'Test Campaign Multiple');

// Enter the agenda groups ID to send the message
// A comma separated string without spaces with the agenda groups ID's
define('AVAILABLE_GROUPS', '2,3,4');

// Enter the start date in english format (yyyy-mm-dd hh:mm)
define('START_DATE', '2016-05-05 11:20');

//Number of messages sent per block.
// Required if ‘minutesxblock’ is present. If both are present, the campaign comfiguration is set to
// “custom configuration” and the values of ‘days’ and ‘time_intervals’ will be taken.
define('SMSXBLOCK', '10');

// Minute interval to send each message block. Required if ‘smsxblock’ is present.
// If both are present, the campaign comfiguration is set to “custom configuration” and the
// values of ‘days’ and ‘time_intervals’ will be taken.
define('MINUTESXBLOCK', '10');

// A comma separated string without spaces with the numbers of the days of the week in which messages will be sent.
// (1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday).
// Only used if ‘minutesxblock’ and ‘smsxblock’ are present
define('DAYS', '1,2,3,4,5');

// A comma separated string without spaces with the time intervals whithin which messages will be sent.
// The format of a time interval is: hh:mm-hh:mm.
// Only used if ‘minutesxblock’ and ‘smsxblock’ are present
define('TIME_INTERVALS', '09:00-13:00,17:00-21:00');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_API_CALL', API_VERSION.'/push/campaigns');

// Post variables to add to the request.
$campaign = array(
    'configuration_name'  =>  API_CONFIGURATION_NAME,
    'message'             =>  MESSAGE,
    'name'                =>  NAME,
    'available_groups'    =>  AVAILABLE_GROUPS,
    'start_date'          =>  START_DATE,
    'minutesxblock'       =>  MINUTESXBLOCK,
    'smsxblock'           =>  SMSXBLOCK,
    'days'                =>  DAYS,
    'time_intervals'      =>  TIME_INTERVALS,
    'api_token'           =>  API_TOKEN
);

// CURL REQUEST FOR SIMPLE PUSH
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_URL, BASE_URI.URL_API_CALL);
curl_setopt($ch2, CURLOPT_POST, 1);
curl_setopt($ch2, CURLOPT_POSTFIELDS, $campaign);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch2);
curl_close ($ch2);
$result = json_decode($result, true);


// CHECK THE REQUEST
if (isset($result['data']))
{
    // Successful response.
    var_dump($result['data']);
}
else if (isset($result['error']))
{
    //Api request failed
    echo "There was errors: ".$result['error']['message'];
    var_dump($result['error']);
}



<?php
require_once('../guzzle/autoloader.php');

// Enter your API TOKEN
define('API_TOKEN', 'ENTER_HERE_YOUR_API_TOKEN');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'This is the message to send');

// Enter the campaign name
define('NAME', 'Test Campaign Multiple');

// Enter the agenda groups ID to send the message
// A comma separated string without spaces with the agenda groups ID's
define('AVAILABLE_GROUPS', '3,4');

// Enter the start date in english format (yyyy-mm-dd hh:mm)
define('START_DATE', '2016-05-05 11:20');

//Number of messages sent per block.
// Required if ‘minutesxblock’ is present. If both are present, the campaign comfiguration is set to
// “custom configuration” and the values of ‘days’ and ‘time_intervals’ will be taken.
define('SMSXBLOCK', '10');

// Minute interval to send each message block. Required if ‘smsxblock’ is present.
// If both are present, the campaign comfiguration is set to “custom configuration” and the
// values of ‘days’ and ‘time_intervals’ will be taken.
define('MINUTESXBLOCK', '10');

// A comma separated string without spaces with the numbers of the days of the week in which messages will be sent.
// (1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday).
// Only used if ‘minutesxblock’ and ‘smsxblock’ are present
define('DAYS', '1,2,3,4,5');

// A comma separated string without spaces with the time intervals whithin which messages will be sent.
// The format of a time interval is: hh:mm-hh:mm.
// Only used if ‘minutesxblock’ and ‘smsxblock’ are present
define('TIME_INTERVALS', '09:00-13:00,17:00-21:00');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_API_CALL', API_VERSION.'/push/campaigns');

// Post variables to add to the request.
$campaign = array(
    'configuration_name'  =>  API_CONFIGURATION_NAME,
    'message'             =>  MESSAGE,
    'name'                =>  NAME,
    'available_groups'    =>  AVAILABLE_GROUPS,
    'start_date'          =>  START_DATE,
    'minutesxblock'       =>  MINUTESXBLOCK,
    'smsxblock'           =>  SMSXBLOCK,
    'days'                =>  DAYS,
    'time_intervals'      =>  TIME_INTERVALS,
    'api_token'           =>  API_TOKEN
);

try
{
    $res = $client->request('POST', BASE_URI.URL_API_CALL,[
        'form_params'   => $campaign,
    ]);
}
catch (\GuzzleHttp\Exception\BadResponseException $e)
{
    // Catch BadResponseException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']['message']);
    }
}
catch (RequestException $e)
{
    // Catch RequestException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']['message']);
    }
}

$result = $res->getBody()->getContents();
$result = json_decode( $result, true);

// CHECK THE REQUEST
if (isset($result['data']))
{
    // Successful response.
    var_dump($result['data']);
}
else if (isset($result['error']))
{
    //Api request failed
    echo "There was errors: ".$result['error']['message'];
    var_dump($result['error']);
}



#! /usr/bin/env python
# -*- coding: utf-8 -*-

import json
import MultipartPostHandler
import urllib2

""" Enter your API TOKEN. """
API_TOKEN = "ENTER_HERE_YOUR_API_TOKEN"

""" Set the API SEND CONFIGURATION """
""" Manage and create new configurations at https://sms.avannubo.com/api/configurations """
API_CONFIGURATION_NAME = "ENTER_YOUR_CONFIGURATION_NAME"

""" Set the message to be sent """
MESSAGE = "This is the message to send"

""" Enter the campaign name """
NAME = "Test Campaign Multiple"

""" Enter the agenda groups to send the message """
AVAILABLE_GROUPS = "3,4"

""" Enter the start date in english format (yyyy-mm-dd hh:mm) """
START_DATE ="2016-05-05 11:20"

""" Number of messages sent per block. """
"""  Required if ‘minutesxblock’ is present. If both are present, the campaign comfiguration is set to """
"""  “custom configuration” and the values of ‘days’ and ‘time_intervals’ will be taken. """
SMSXBLOCK= "10"

"""  Minute interval to send each message block. Required if ‘smsxblock’ is present. """
"""  If both are present, the campaign comfiguration is set to “custom configuration” and the """
"""  values of ‘days’ and ‘time_intervals’ will be taken. """
MINUTESXBLOCK= "10"

"""  A comma separated string without spaces with the numbers of the days of the week in which messages will be sent. """
"""  (1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday). """
"""  Only used if ‘minutesxblock’ and ‘smsxblock’ are present """
DAYS= "1,2,3,4,5"

"""  A comma separated string without spaces with the time intervals whithin which messages will be sent. """
"""  The format of a time interval is: hh:mm-hh:mm. """
"""  Only used if ‘minutesxblock’ and ‘smsxblock’ are present """
TIME_INTERVALS= "09:00-13:00,17:00-21:00"

""" Do not change this """
BASE_URI = "https://api.avannubo.com/"
API_VERSION = "v1"
URL_API_CALL = "{0}/push/campaigns".format( API_VERSION )

""" Post variables to add to the request. """
campaign = {
    'api_token'          : API_TOKEN,
    'configuration_name' : API_CONFIGURATION_NAME,
    'message'            : MESSAGE,
    'name'               : NAME,
    'available_groups'   : AVAILABLE_GROUPS,
    'start_date'         : START_DATE,
    'minutesxblock'      : MINUTESXBLOCK,
    'smsxblock'          : SMSXBLOCK,
    'days'               : DAYS,
    'time_intervals'     : TIME_INTERVALS,
}

try:
    opener.addheaders = headers
    result = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_API_CALL ), campaign ).read() )
    except Exception, e:
    print "Something went wrong (campaign)..."
    print type(e)
    print e
else:
    """ CHECK THE REQUEST """
    if 'data' in result:
        print result['data']
    elif 'error' in result:
        print "There were errors: {0}".format( result['error']['message'] )
        print result

Con un token temporal:


curl -i https://api.avannubo.com/v1/login -d email=put_here_your_email_here -d password=put_here_your_password
curl -H "Authorization: Bearer put_here_your_token" https://api.avannubo.com/v1/push/campaigns -d name=put_here_your_name -d configuration_name=put_here_your_configuration_name_here -d message=put_here_your_message_here -d available_groups=put_here_your_available_groups -d start_date=put_here_your_start_date -d minutesxblock=put_here_your_minutesxblock -d smsxblock=put_here_your_smsxblock -d days=put_here_your_days -d time_intervals=put_here_your_time_intervals


<?php
// Enter your email and password to access the site
define('EMAIL', 'ENTER_HERE_YOUR_EMAIL');
define('PASSWORD', 'ENTER_HERE_YOUR_PASSWORD');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'This is the message to send');

// Enter the campaign name
define('NAME', 'Test Campaign Multiple');

// Enter the agenda groups ID to send the message
// A comma separated string without spaces with the agenda groups ID's
define('AVAILABLE_GROUPS', '2,3,4');

// Enter the start date in english format (yyyy-mm-dd hh:mm)
define('START_DATE', '2016-05-05 11:20');

//Number of messages sent per block.
// Required if ‘minutesxblock’ is present. If both are present, the campaign comfiguration is set to
// “custom configuration” and the values of ‘days’ and ‘time_intervals’ will be taken.
define('SMSXBLOCK', '10');

// Minute interval to send each message block. Required if ‘smsxblock’ is present.
// If both are present, the campaign comfiguration is set to “custom configuration” and the
// values of ‘days’ and ‘time_intervals’ will be taken.
define('MINUTESXBLOCK', '10');

// A comma separated string without spaces with the numbers of the days of the week in which messages will be sent.
// (1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday).
// Only used if ‘minutesxblock’ and ‘smsxblock’ are present
define('DAYS', '1,2,3,4,5');

// A comma separated string without spaces with the time intervals whithin which messages will be sent.
// The format of a time interval is: hh:mm-hh:mm.
// Only used if ‘minutesxblock’ and ‘smsxblock’ are present
define('TIME_INTERVALS', '09:00-13:00,17:00-21:00');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_ACCESS_TOKEN',  API_VERSION.'/login');
define('URL_API_CALL', API_VERSION.'/push/campaigns');

// API AUTHENTIFICATION
$data = [
    'email'             =>   EMAIL,
    'password'          =>   PASSWORD,
];

// CURL REQUEST FOR AUTHENTIFICATION
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, BASE_URI.URL_ACCESS_TOKEN);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);
curl_close ($ch);
$output = json_decode($output, true);

// CHECK THE REQUEST
if ( ! isset( $output['error'] ) )
{
    // Successful authentication.
    // We keep the response for use in API requests
    $token          = $output['data']['token'];
    $expires_in     = $output['data']['expires_in'];
    $expires_at     = $output['data']['expires_at'];


    // Add authorization header to the request
    // It contains the authorization for the request
    $headers = array(
        'Authorization: Bearer '.$token
    );

    // Post variables to add to the request.
    $campaign = array(
        'configuration_name'  =>  API_CONFIGURATION_NAME,
        'message'             =>  MESSAGE,
        'name'                =>  NAME,
        'available_groups'    =>  AVAILABLE_GROUPS,
        'start_date'          =>  START_DATE,
        'minutesxblock'       =>  MINUTESXBLOCK,
        'smsxblock'           =>  SMSXBLOCK,
        'days'                =>  DAYS,
        'time_intervals'      =>  TIME_INTERVALS,
    );

    // CURL REQUEST FOR SIMPLE PUSH
    $ch2 = curl_init();
    curl_setopt($ch2, CURLOPT_URL, BASE_URI.URL_API_CALL);
    curl_setopt($ch2, CURLOPT_POST, 1);
    curl_setopt($ch2, CURLOPT_POSTFIELDS, $campaign);
    curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec ($ch2);
    curl_close ($ch2);
    $result = json_decode($result, true);


    // CHECK THE REQUEST
    if (isset($result['data']))
    {
        // Successful response.
        var_dump($result['data']);
    }
    else if (isset($result['error']))
    {
        //Api request failed
        echo "There was errors: ".$result['error']['message'];
        var_dump($result['error']);
    }
}
else
{
    //Authentication failed
    echo "There was errors in the authentication: ".$output['error']['message'];
    var_dump($output['error']);
}


<?php
require_once('../guzzle/autoloader.php');

// Enter your email and password to access the site
define('EMAIL', 'ENTER_HERE_YOUR_EMAIL');
define('PASSWORD', 'ENTER_HERE_YOUR_PASSWORD');

// Set the API SEND CONFIGURATION
// Manage and create new configurations at https://sms.avannubo.com/api/configurations
define('API_CONFIGURATION_NAME', 'ENTER_YOUR_CONFIGURATION_NAME');

// Set the message to be sent
define('MESSAGE', 'This is the message to send');

// Enter the campaign name
define('NAME', 'Test Campaign Multiple');

// Enter the agenda groups ID to send the message
// A comma separated string without spaces with the agenda groups ID's
define('AVAILABLE_GROUPS', '3,4');

// Enter the start date in english format (yyyy-mm-dd hh:mm)
define('START_DATE', '2016-05-05 11:20');

//Number of messages sent per block.
// Required if ‘minutesxblock’ is present. If both are present, the campaign comfiguration is set to
// “custom configuration” and the values of ‘days’ and ‘time_intervals’ will be taken.
define('SMSXBLOCK', '10');

// Minute interval to send each message block. Required if ‘smsxblock’ is present.
// If both are present, the campaign comfiguration is set to “custom configuration” and the
// values of ‘days’ and ‘time_intervals’ will be taken.
define('MINUTESXBLOCK', '10');

// A comma separated string without spaces with the numbers of the days of the week in which messages will be sent.
// (1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday).
// Only used if ‘minutesxblock’ and ‘smsxblock’ are present
define('DAYS', '1,2,3,4,5');

// A comma separated string without spaces with the time intervals whithin which messages will be sent.
// The format of a time interval is: hh:mm-hh:mm.
// Only used if ‘minutesxblock’ and ‘smsxblock’ are present
define('TIME_INTERVALS', '09:00-13:00,17:00-21:00');

// Do not change this
define('BASE_URI', 'https://api.avannubo.com/');
define('API_VERSION', 'v1');
define('URL_ACCESS_TOKEN',  API_VERSION.'/login');
define('URL_API_CALL', API_VERSION.'/push/campaigns');

// API AUTHENTIFICATION
$data = [
    'email'             =>   EMAIL,
    'password'          =>   PASSWORD,
];

try
{
    $client = new GuzzleHttp\Client();

    $res = $client->request('POST', BASE_URI.URL_ACCESS_TOKEN, [
        'form_params' => $data
    ]);
}
catch (\GuzzleHttp\Exception\BadResponseException $e)
{
    // Catch BadResponseException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']);
    }
}
catch (RequestException $e)
{
    // Catch RequestException
    if ($e->hasResponse())
    {
        $error = json_decode($e->getResponse()->getBody()->getContents(), true);
        die('Error: '.$error['error']);
    }
}

$output = $res->getBody()->getContents();
$output = json_decode( $output, true);

// CHECK THE REQUEST
if ( ! isset( $output['error'] ) )
{
    // Successful authentication.
    // We keep the response for use in API requests
    $token          = $output['data']['token'];
    $expires_in     = $output['data']['expires_in'];
    $expires_at     = $output['data']['expires_at'];


    // Add authorization header to the request
    // It contains the authorization for the request
    $headers = array(
        'Authorization' => 'Bearer '.$token
    );

    // Post variables to add to the request.
    $campaign = array(
        'configuration_name'  =>  API_CONFIGURATION_NAME,
        'message'             =>  MESSAGE,
        'name'                =>  NAME,
        'available_groups'    =>  AVAILABLE_GROUPS,
        'start_date'          =>  START_DATE,
        'minutesxblock'       =>  MINUTESXBLOCK,
        'smsxblock'           =>  SMSXBLOCK,
        'days'                =>  DAYS,
        'time_intervals'      =>  TIME_INTERVALS,
    );

    try
    {
        $res = $client->request('POST', BASE_URI.URL_API_CALL,[
            'form_params'   => $campaign,
            'headers'       => $headers,
        ]);
    }
    catch (\GuzzleHttp\Exception\BadResponseException $e)
    {
        // Catch BadResponseException
        if ($e->hasResponse())
        {
            $error = json_decode($e->getResponse()->getBody()->getContents(), true);
            die('Error: '.$error['error']['message']);
        }
    }
    catch (RequestException $e)
    {
        // Catch RequestException
        if ($e->hasResponse())
        {
            $error = json_decode($e->getResponse()->getBody()->getContents(), true);
            die('Error: '.$error['error']['message']);
        }
    }

    $result = $res->getBody()->getContents();
    $result = json_decode( $result, true);

    // CHECK THE REQUEST
    if (isset($result['data']))
    {
        // Successful response.
        var_dump($result['data']);
    }
    else if (isset($result['error']))
    {
        //Api request failed
        echo "There was errors: ".$result['error']['message'];
        var_dump($result['error']);
    }
}
else
{
    //Authentication failed
    echo "There was errors in the authentication: ".$output['error']['message'];
    var_dump($output['error']);
}


#! /usr/bin/env python
# -*- coding: utf-8 -*-

import json
import MultipartPostHandler
import urllib2

""" Enter your email and password to access the site. """
EMAIL = "ENTER_HERE_YOUR_EMAIL"
PASSWORD = "ENTER_HERE_YOUR_PASSWORD"

""" Set the API SEND CONFIGURATION """
""" Manage and create new configurations at https://sms.avannubo.com/api/configurations """
API_CONFIGURATION_NAME = "ENTER_YOUR_CONFIGURATION_NAME"

""" Set the message to be sent """
MESSAGE = "This is the message to send"

""" Enter the campaign name """
NAME = "Test Campaign Multiple"

""" Enter the agenda groups to send the message """
AVAILABLE_GROUPS = "3,4"

""" Enter the start date in english format (yyyy-mm-dd hh:mm) """
START_DATE ="2016-05-05 11:20"

""" Number of messages sent per block. """
"""  Required if ‘minutesxblock’ is present. If both are present, the campaign comfiguration is set to """
"""  “custom configuration” and the values of ‘days’ and ‘time_intervals’ will be taken. """
SMSXBLOCK= "10"

"""  Minute interval to send each message block. Required if ‘smsxblock’ is present. """
"""  If both are present, the campaign comfiguration is set to “custom configuration” and the """
"""  values of ‘days’ and ‘time_intervals’ will be taken. """
MINUTESXBLOCK= "10"

"""  A comma separated string without spaces with the numbers of the days of the week in which messages will be sent. """
"""  (1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday). """
"""  Only used if ‘minutesxblock’ and ‘smsxblock’ are present """
DAYS= "1,2,3,4,5"

"""  A comma separated string without spaces with the time intervals whithin which messages will be sent. """
"""  The format of a time interval is: hh:mm-hh:mm. """
"""  Only used if ‘minutesxblock’ and ‘smsxblock’ are present """
TIME_INTERVALS= "09:00-13:00,17:00-21:00"

""" Do not change this """
BASE_URI = "https://api.avannubo.com/"
API_VERSION = "v1"
URL_ACCESS_TOKEN = "{0}/login".format( API_VERSION )
URL_API_CALL = "{0}/push/campaigns".format( API_VERSION )


""" API AUTHENTIFICATION """
data = {
    'email'         : EMAIL,
    'password'      : PASSWORD
}

try:
    opener = urllib2.build_opener( MultipartPostHandler.MultipartPostHandler )
    output = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_ACCESS_TOKEN ), data ).read() )
except Exception, e:
    print "Something went wrong (auth)..."
    print type( e )
    print e
else:
    if 'error' not in output:
        """ Successful authentication. """
        """ We keep the response for use in API requests """
        token          = output['token']
        expires_in     = output['expires_in']
        expires_at     = output['expires_at']

        """ Add authorization header to the request """
        """ It contains the authorization for the request """
        headers = [
            ( "Authorization", "Bearer {0}".format( token ) ),
        ]

        """ Post variables to add to the request. """
        campaign = {
            'configuration_name' : API_CONFIGURATION_NAME,
            'message'            : MESSAGE,
            'name'               : NAME,
            'available_groups'   : AVAILABLE_GROUPS,
            'start_date'         : START_DATE,
            'minutesxblock'      : MINUTESXBLOCK,
            'smsxblock'          : SMSXBLOCK,
            'days'               : DAYS,
            'time_intervals'     : TIME_INTERVALS,
        }

        try:
            opener.addheaders = headers
            result = json.loads( opener.open( "{0}{1}".format( BASE_URI, URL_API_CALL ), campaign ).read() )
            except Exception, e:
            print "Something went wrong (campaign)..."
            print type(e)
            print e
        else:
            """ CHECK THE REQUEST """
            if 'data' in result:
                print result['data']
            elif 'error' in result:
                print "There were errors: {0}".format( result['error']['message'] )
                print result

    else:
        print "There were errors in the authentication: {0}".format( output['error']['message'] )