Usable code, right out of the box

You can get started using our API with any of our libraries, available to you on GitHub. You may also give our interactive API Documentation a spin and start making API calls, right inside your browser. Don't see your language supported yet? Feel free to roll your own solution - as long as your language can make HTTP requests and receive responses, you should be in business.

Getting started

Below are some example code snippets that make use of the PHP library to help you get started. These snippets will help you load your API key, authenticate and login to your account, upload and download some files, then logout.

Download PHP Sample Code »
Download Python Sample Code »

Setting the API key

To get started, you will want to add your custom API key to your application config. Here is an example using PHP, which makes use of our custom PHP library:


    $apiKey = 'myaccountname-XXXXXXXXXXXXXXXX';
    $apiUrl = '';


Once your API key is in place, you will likely want to authenticate so that you can begin uploading and downloading files, creating users, and all that other fun stuff.

    // create a new instance of the ExaVault API library class
    $api = new V1Api( new APIClient($apiKey, $apiUrl) );
    $accessToken = null;

    // call the authenticateUser method, passing your username and password
    $response = $api->authenticateUser('yourusername', 'yourpassword');

    // save this result for later, we will need it to logout
    $loginSuccess = $response->success;

    // if authentication was successful, store the access token
    // obtained via the response body in the API instance.

    if ($loginSuccess) {
	$accessToken = $response->results->accessToken;
    } else {
        // Handle the error...

Uploading a file

Uploading is a bit more complicated, as it first requires obtaining an appropriate upload URL and then making a separate HTTP request to upload the file to the correct upload URL.

    // set the local and remote paths
    $localPath = "/path/of/your/local/file";
    $remotePath = "/path/on/remote/host";
    // get the file size located at the local pathn
    $filesize = filesize($localPath);

    // get the upload URL from the Evapi object
    $uploadResults = $api->getUploadFileUrl($accessToken, $filesize, $remotePath, true);

    // if we were able to successfully get the upload URL, start
    // uploading. Otherwise, print an error message.

    if($uploadResults->success) {

       // initialize a new curl session by passing the uploadFileUrl
       $uploadUrl = $uploadResults->results->url;
       $ch = curl_init($uploadUrl);

       // create the open file handle
       $handle = fopen($localPath, 'r');

       // set the HTTP POST header, indicating the size of file to be uploaded
       $header = array("X_File_Size: " . $filesize,
                       "Content-Type: multipart/form-data",
                       "Content-Length: " . $filesize,

       // PHP uses curl for sending HTTP requests. If using a different language
       // you will likely do this differently

       curl_setopt($ch, CURLOPT_POST, true);             // perform upload via http post
       curl_setopt($ch, CURLOPT_HTTPHEADER, $header);    // specify the header
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);      // return string of result
       curl_setopt($ch, CURLOPT_INFILE, $handle);        // specify size of file to upload
       curl_setopt($ch, CURLOPT_SSLVERSION, 1);          // specify TLS 1.0
       curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);      // verify common name with specified hostname
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);   // verify certificate of remote peer
       $result = curl_exec($ch);                         // upload the file, get back result
       $result = json_decode($result, true);             // convert result to an array
       curl_close($ch);                                  // close the curl session
       fclose($handle);                                  // close the open file handle

       if ($result['success']) {
          // Your upload was successful!
       } else {
          // Wah-wah. Your upload failed for some reason.
    } else {
         // Wah-wah. Your upload failed for some reason.

Downloading a file

Downloading, like the upload process, first requires obtaining an appropriate download URL and then making a separate HTTP request to the API.

    // set the filename
    $filename = "file.txt";

    // set the local path of the file to download to
    $localPath = "/path/to/local/" . $filename;

    // set the remote path where the file is located
    $remotePath = "/path/to/remote/" . $filename;

    // call the getDownloadFileUrl method on the API object instance
    $downloadResults = $api->getDownloadFileUrl($accessToken, $remotePath);
    if($downloadResults->success) {

        // get the download URL and initialize a new curl session
        $downloadUrl = $downloadResults->results->url;
        $ch = curl_init($downloadUrl);

        // set the file handle to the appropriate path
        $handle = fopen($localPath, 'w');

        // set the cURL options
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FILE, $handle);
        curl_setopt($ch, CURLOPT_SSLVERSION, 1);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
        $result = curl_exec($ch);
        $result = json_decode($result, true);

        if ($result) {
            // Download successful!
        } else {
            // Oops, there was an error.
    } else {
        // Oops, there was an error.

Logging Out

Logging out of the API is very simple. The only thing that is required is to check to see if we were logged in in the first place; if yes then log out.

    // logout only if login was successful
    if ($loginResult) {

The call method

For those programmers that wish to provide their own API client, one possible implementation of an API call method is detailed below. This method, a member of a theoretical ApiClient class, will give you an idea of how requests are sent to the API, and how responses from the server are deserialized into an acceptable data structure to work with in your program.

    private function call($method, $params = null)
        // create an array of post fields
        $postfields = array();

        // set the access token stored in this instance of the ApiClient object
        $postfields["access_token"] = $this->_accessToken;

        // set the API key, stored in this instance of the ApiClient object
        $postfields["api_key"] = $this->_apiKey;

        if (!empty($params)) {
           $postfields = array_merge($postfields, $params);

        // PHP uses curl for sending HTTP requests. If using a different language
        // you will likely use another interface for this
        $ch = curl_init();
        $url = $config['apiUrl'] . "/v1" . "/" . $method;   // append the method name to the URL
        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 100);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        // We use the http_build_query here instead of passing in the array because CURL
        // does not handle nested arrays correctly. PHP's http_build_query function correctly
        // converts the array to a string in the form param1=value&param2=value&array[]=value1&array=value2     

        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
        $data = curl_exec($ch);

        // the JSON results are decoded and converted into an associative array
        $results = json_decode($data, true);
        // check to make sure we actually have an array
        if (!is_array($results)) {
           throw new Exception("Could not parse results from API call. String:\n".$data);
        return $results;

Taking it a step further...

This is but a sample of what options are available to you as a budding ExaVault API developer. For a complete listing of all supported API operations, please take a look at our API documentation.