PHP Quick Start

VisualVault REST API requests using PHP

PHP Files

upload a file

// REQUEST
$AccessToken = '{AccessToken}';
$baseUrl = 'https://demo.visualvault.com/api/v1/{customerAlias}/{databaseAlias}/';
$endPoint = 'documents';
// all of the fields are required to create a new file. for fileName and name declare the name of the file to upload.
$fields = [
	'folderId' => '{folderId}',
	'documentState' => 1,
	'name' => 'example.csv',
	'description' => 'pre file upload for id',
	'revision' => '1',
	'allowNoFile' => true,
	'fileLength' => 0,
	'fileName' => 'example.csv',
	'indexFields' => '{}'
	];
$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_POST => 1,
    CURLOPT_HTTPHEADER => array(
        'Authorization: Bearer ' . $AccessToken),
    CURLOPT_POSTFIELDS => http_build_query($fields),
    CURLOPT_URL => $baseUrl . $endPoint,
    CURLOPT_VERBOSE => 1
    ));
curl_exec($ch);
curl_close($ch);

// RESPONSE
{
  "meta": {
    "status": 200,
    "statusMsg": "OK",
    "method": "POST",
    "href": "https://demo.visualvault.com/api/v1/{customerAlias}/{databaseAlias}/documents"
  },
  "data": {
    "href": "~/documents/75039c54-167f-e511-bf02-008cfa482110",
    "dataType": "Document",
    "id": "d6099d54-167f-e511-bf02-008cfa482110",
    "documentId": "75039c54-167f-e511-bf02-008cfa482110",
    "name": "GEN-9",
    "description": "pre file upload for id",
    "releaseState": 1,
    "checkInStatus": 0,
    "revision": "1",
    "reviewDate": "2016-07-26T07:56:00.02",
    "expireDate": "2016-10-24T07:56:00.02",
    "archive": 0,
    "abstract": "",
    "keywords": "",
    "changeText": null,
    "folderId": "10000000-1000-2000-1111-100000000010",
    "folderName": "General",
    "folderPath": "/General",
    "fileId": "77039c54-167f-e511-bf02-008cfa482110",
    "fileName": "example.csv",
    "fileSize": 0,
    "extension": "txt",
    "contentType": "application/octet-stream",
    "checkedInBy": "{userId}",
    "checkedOutById": "5eefec33-ca71-e511-befe-98991b71acc0",
    "checkedOutBy": "{userId}",
    "checkOutDate": "2015-10-30T07:56:00.027",
    "createDate": "2015-10-30T07:56:00.023",
    "createById": "5eefec33-ca71-e511-befe-98991b71acc0",
    "createBy": "{userId}",
    "modifyDate": "2015-10-30T07:56:00.027",
    "modifyById": "5eefec33-ca71-e511-befe-98991b71acc0",
    "modifyBy": "{userId}"
  }
}

First we need to create a document in order to upload a file. Once the file is created take the documentId and put it in the next script.

Now that we have a documentId from the first script. We can now upload a file for that documentId. To upload revisions continue to use the same documentId.

// REQUEST
$AccessToken = '{AccessToken}';
$baseUrl = 'https://demo.visualvault.com/api/v1/{customerAlias}/{databaseAlias}/';
$endpoint = 'files';
$request = $baseUrl . $endpoint;
// for the file upload object do as follows: $fileUpload = new CURLFILE('/pathToDoc/example.csv','mimetype','fileNameToPost')
$fileUpload = new CURLFILE('/home/vv/test.csv','text/csv','example.csv');
// mandatory fields for fileUpload. $fileUpload variable is the file object to upload. place documentId from first script under {documentId}.
// use name from output from first request under name or name of the document. 
$fields = [
	'documentId' => '{documentId}',
	'name' => 'gen-9',
	'revision' => '{revisionNumber}',
	'changeReason' => '1',
	'checkInDocumentState' => 'Released',
	'indexFields' => '{}',
	'fileName' => 'newFile.csv',
	'fileUpload' => $fileUpload
	];
$ch = curl_init();
curl_setopt_array($ch, array(
    CURLOPT_POST => 1,
    CURLOPT_HTTPHEADER => array(
        'Authorization: Bearer ' . $AccessToken),
    CURLOPT_POSTFIELDS => $fields,
    CURLOPT_URL => $request
    ));
curl_exec($ch);
curl_close($ch);

// RESPONSE
{
  "meta": {
    "status": 200,
    "statusMsg": "OK",
    "method": "POST",
    "href": "https://demo.visualvault.com/api/v1/{customerAlias}/{databaseAlias}/files",
    "checkInStatus": "CheckedIn"
  },
  "data": {
    "href": "~/documents/75039c54-167f-e511-bf02-008cfa482110",
    "dataType": "Document",
    "id": "8d702ac2-1d7f-e511-bf02-008cfa482110",
    "documentId": "75039c54-167f-e511-bf02-008cfa482110",
    "name": "GEN-9",
    "description": "pre file upload for id",
    "releaseState": 1,
    "checkInStatus": 0,
    "revision": "6",
    "reviewDate": "2016-07-26T07:56:00",
    "expireDate": "2016-10-24T07:56:00",
    "archive": 0,
    "abstract": "",
    "keywords": "",
    "changeText": "1",
    "folderId": "10000000-1000-2000-1111-100000000010",
    "folderName": "General",
    "folderPath": "/General",
    "fileId": "32242ac2-1d7f-e511-bf02-008cfa482110",
    "fileName": "newFile.csv",
    "fileSize": 39,
    "extension": "csv",
    "contentType": "application/octet-stream",
    "checkedInBy": "{userId}",
    "checkedOutById": "5eefec33-ca71-e511-befe-98991b71acc0",
    "checkedOutBy": "{userId}",
    "checkOutDate": "2015-10-30T08:48:57.653",
    "createDate": "2015-10-30T08:49:10.297",
    "createById": "5eefec33-ca71-e511-befe-98991b71acc0",
    "createBy": "{userId}",
    "modifyDate": "2015-10-30T08:49:10.303",
    "modifyById": "5eefec33-ca71-e511-befe-98991b71acc0",
    "modifyBy": "{userId}"
  }
}

This endpoint uploads a file for the documentId initially created in the first step. Once you have the id you can now upload revisions to VisualVault from your local machine. In the fields section under 'revision', place the value corresponding to the revision number it will be once uploaded. i.e. I have a current document at revision 5. I uploaded a new revision so under the 'revision' field I placed 6. Include Index Fields if there are any, also you maye either release the revision as Released or Unreleased in the fields section. This endpoint will also upload revisions of a file. Use the same documentId to continue uploading revisions for the file.

downloads a file

// REQUEST
$AccessToken = '{AccessToken}';
$baseUrl = 'https://demo.visualvault.com/api/v1/{customerAlias}/{databaseAlias}/';
$endpoint = 'files/';
$id = '{documentRevisionId}';
$request = $baseUrl . $endpoint . $id;
// under fopen(/pathForFileYouWantToSave)
$file = fopen('/home/vv/newFile.csv', 'w');
$ch = curl_init();
curl_setopt_array($ch, array(
	CURLOPT_HTTPGET => true,
	CURLOPT_HTTPHEADER => array(
		'Authorization: Bearer ' . $AccessToken),
	CURLOPT_URL => $request,
	CURLOPT_FILE => $file,
	CURLOPT_VERBOSE => 1
	));
curl_exec($ch);
fwrite($file, '');
fclose($file);
curl_close($ch);

// RESPONSE
< HTTP/1.1 200 OK
< Cache-Control: no-cache
< Pragma: no-cache
< Transfer-Encoding: chunked
< Content-Type: application/octet-stream
< Expires: -1
* Server Microsoft-IIS/8.0 is not blacklisted
< Server: Microsoft-IIS/8.0
< X-AspNet-Version: 4.0.30319
< X-UA-Compatible: IE=Edge,chrome=1
< Date: Mon, 26 Oct 2015 20:04:33 GMT 
    

Downloads a file by documentRevisionId.