Creating & Updating Data

  Date Updated: May 30th 2014

Adding or Updating?

Schemas

There are two methods you can use to add and edit records in the database: PUT and POST. For each request there are different sets of information that must be provided. Have a look at the schema for the endpoint to determine what information is required.

Time Zones

All responses from the EXO API Server include date and time information expressed in UTC, e.g. '1/1/2014 1am UTC'. All PUT and POST requests to the API Server that include a date and time must include the time zone, e.g. '1/1/2014 1pm NZDT'. If a time zone is not included in a PUT or POST request, the API Server will assume that the request is in the same time zone as the server.

HTTP PUT

Use the PUT method to update an existing entry in the database. For example, you would use the PUT method to update a customer record with new information.

Example: PUT {URI}/contact/1 will updated contact with data provided in request payload.

Please note:When updating an existing record, you will need to add the unique record identifier ID to the end of the URI.

Here's a C# sample using HTTP Web Request


using System;
using System.IO;
using System.Net;

class Test
{
   static void Main()
   {
       string json = "...";
       byte[] arr = System.Text.Encoding.UTF8.GetBytes(json);
       HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://localhost:8080/");
       request.Method = "PUT";
       request.ContentType = "text/json";
       request.ContentLength = arr.Length;
       Stream dataStream = request.GetRequestStream();
       dataStream.Write(arr, 0, arr.Length);
       dataStream.Close();
       HttpWebResponse response = (HttpWebResponse)request.GetResponse();
       string returnString = response.StatusCode.ToString();
       Console.WriteLine(returnString);
    }
}

HTTP POST

Use the POST method to add a new entry to the database, whether it already exists or not. For example, you might use the POST method to add a new customer to the database. If the customer you're adding already exists, another record for the customer will be added.

POST to {URI}/contact will create new contact resource.

Here's a PHP example using cURL


// Start curl
$ch = curl_init();
$putString = $jsonString;
// Put string into a temporary file
$putData = tmpfile();
fwrite($putData, $putString);
fseek($putData, 0);

// Headers
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PUT, true);
// setup the authentication
curl_setopt($ch, CURLOPT_USERPWD,  $username":"$password );
curl_setopt($ch, CURLOPT_INFILE, $putData);
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($putString));

$output = curl_exec($ch);
echo $output;

// Close the file
fclose($putData);
curl_close($ch);