Spark API

In this example we use the following 2 request URLs to create a Spark room and use the id sent back in the POST response to add the users to the room:
spark_createspark_adduser

HTML

<form method=”POST” action=”/post.php”>
<input type=”text” required name=”title” placeholder=”Spark Room Title”>
<input type=”email” required name=”customer_email” placeholder=”Customer Email Address”>
<input type=”email” required name=”sales_email” placeholder=”Sales Engineer Email Address”>
<button type=”submit”>Create</button>
</form>

PHP

<?php
//define headers
$headers = array();
$headers[] = ‘Authorization: Bearer ABCDEFG–REALLYLONG–APIKEY-GOES-HERE’;
$headers[] = ‘Content-Type: application/json’;

//room title
$newroom = array(‘title’ => $_POST[‘title’]);
$json_newroom = json_encode($newroom);

//create room
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, “https://api.ciscospark.com/v1/rooms”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_newroom);
$server_output = curl_exec ($ch);
curl_close ($ch);

//save roomid from output
$results = json_decode($server_output);
$id = $results->{‘id’};

//bring it all together
$addcustomer = array(‘roomId’ => $id, ‘personEmail’ => $_POST[‘customer_email’], ‘isModerator’ => false);
$json_addcustomer = json_encode($addcustomer);
$addsales = array(‘roomId’ => $id, ‘personEmail’ => $_POST[‘sales_email’], ‘isModerator’ => false);
$json_addsales = json_encode($addsales);

//add customer
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, “https://api.ciscospark.com/v1/memberships”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_addcustomer);
$server_output = curl_exec ($ch);
curl_close ($ch);

//add sales
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, “https://api.ciscospark.com/v1/memberships”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_addsales);
$server_output = curl_exec ($ch);
curl_close ($ch);

print $server_output;

Read more @
https://developer.ciscospark.com/quick-reference.html