Giter VIP home page Giter VIP logo

sendpulse-rest-api-php's Introduction

SendPulse REST client library

A simple SendPulse REST client library and example for PHP.

API Documentation https://sendpulse.com/api

Installing

Via Composer:

composer require sendpulse/rest-api

Usage

<?php
require 'vendor/autoload.php';

// Without Composer (and instead of "require 'vendor/autoload.php'"):
// require("your-path/sendpulse-rest-api-php/src/ApiInterface.php");
// require("your-path/sendpulse-rest-api-php/src/ApiClient.php");
// require("your-path/sendpulse-rest-api-php/src/Storage/TokenStorageInterface.php");
// require("your-path/sendpulse-rest-api-php/src/Storage/FileStorage.php");
// require("your-path/sendpulse-rest-api-php/src/Storage/SessionStorage.php");
// require("your-path/sendpulse-rest-api-php/src/Storage/MemcachedStorage.php");
// require("your-path/sendpulse-rest-api-php/src/Storage/MemcacheStorage.php");

use Sendpulse\RestApi\ApiClient;
use Sendpulse\RestApi\Storage\FileStorage;

// API credentials from https://login.sendpulse.com/settings/#api
define('API_USER_ID', '');
define('API_SECRET', '');
define('PATH_TO_ATTACH_FILE', __FILE__);

$SPApiClient = new ApiClient(API_USER_ID, API_SECRET, new FileStorage());

/*
 * Example: Get Mailing Lists
 */
var_dump($SPApiClient->listAddressBooks());

/*
 * Example: Add new email to mailing lists
 */
 $bookID = 123;
 $emails = array(
    array(
        'email' => '[email protected]',
        'variables' => array(
            'phone' => '+12345678900',
            'name' => 'User Name',
        )
    )
);
 $additionalParams = array(
   'confirmation' => 'force',
   'sender_email' => '[email protected]',
);
 // With confirmation
var_dump($SPApiClient->addEmails($bookID, $emails, $additionalParams));

// Without confirmation
var_dump($SPApiClient->addEmails($bookID, $emails));

/*
 * Example: Send mail using SMTP
 */
$email = array(
    'html' => '<p>Hello!</p>',
    'text' => 'Hello!',
    'subject' => 'Mail subject',
    'from' => array(
        'name' => 'John',
        'email' => '[email protected]',
    ),
    'to' => array(
        array(
            'name' => 'Subscriber Name',
            'email' => '[email protected]',
        ),
    ),
    'bcc' => array(
        array(
            'name' => 'Manager',
            'email' => '[email protected]',
        ),
    ),
    'attachments' => array(
        'file.txt' => file_get_contents(PATH_TO_ATTACH_FILE),
    ),
);
var_dump($SPApiClient->smtpSendMail($email));

/*
 * Example: create new push
 */
$task = array(
    'title' => 'Hello!',
    'body' => 'This is my first push message',
    'website_id' => 1,
    'ttl' => 20,
    'stretch_time' => 0,
);

// This is optional
$additionalParams = array(
    'link' => 'http://yoursite.com',
    'filter_browsers' => 'Chrome,Safari',
    'filter_lang' => 'en',
    'filter' => '{"variable_name":"some","operator":"or","conditions":[{"condition":"likewith","value":"a"},{"condition":"notequal","value":"b"}]}',
);
var_dump($SPApiClient->createPushTask($task, $additionalParams));

sendpulse-rest-api-php's People

Contributors

dshemendiuk avatar emirii avatar erickthered avatar foolsoft avatar keanor avatar mdzhym avatar mekras avatar paulkolbovich avatar qzmenko avatar sendpulse avatar usemint avatar

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.