jrobinsonc
1/31/2017 - 2:39 PM

Backand PHP helper

Backand PHP helper

<?php

/* This must be defined. */
define('BACKAND_MASTER_TOKEN', '...');
define('BACKAND_USER_TOKEN', '...');

/**
 * string $object Object name
 * array $args Params to be sended.
 * @return string JSON with the result.
 */
function backand($object, $data)
{
    $result = file_get_contents('https://api.backand.com/1/objects/' . $object, false, stream_context_create([
        'http' => [
            'method'  => 'POST',
            'header'  => implode("\r\n", [
                'Authorization: Basic ' . base64_encode(sprintf('%s:%s', BACKAND_MASTER_TOKEN, BACKAND_USER_TOKEN)),
                'Content-type: application/json',
                'Accept: application/json',
                'charset: utf-8'
            ]),
            'content' => json_encode($data)
        ]
    ]));

    return $result;
}

/* Usage */
backand('<object name>', $args);