API documentation

Plug your app !

Preamble

This paper aims to describe the use of the API allowing third-party applications with interact with the wagapi platform for storage, classification, access and sharing of data.

Requirements

Using the API requires a key for access to the API, which will be called api_key or simply key in the following lines. You can generate your unique key through the settings panel of your wagapi account (accessible from the top of this page). To access a specific account, user name and password of the account are also required for the application to authenticate.

General concepts

Authentication

Authentication is based on the use of an authentication token, the user identifier, in this case its API identifier (or API key) and the account ID being accessed. The call /access/account detailed below is a simple method that allows a third-party application to access an account based on the username and password of the account. If successful, the method a token and the account ID. Token and the API username must then be systematically inserted into the subsequent calls:

  • either in the headers, respectively associated with the header "auth_token" and "key"
  • either in GET or POST variables, depending on the method used, respectively associated with the variables "auth_token" and "key"
  • The account ID is automatically inserted into the URI. Its place is specified in the detailed description of the calls in the account_id variable.

    Call

    The nature of the call is contained in the url. Parameters are passed in the variable data, regardless of the method used, which has the following form:

    		{
    			input1: {}, [] or string of input variables (depending on the call)
    			input2: {}, [] or string of input variables (depending on the call)
    			input3: {}, [] or string of input variables (depending on the call)
    			....
    		}
    		

    The content of data is actually an associative array, whose indices are strings. According to the programming language, it is an array or an object. In the following, the parameters will refer to data fields. Before being passed as a parameter via POST or GET variable data are to be encoded in JSON format. It may be necessary, for example to use JSON.stringify () in javascript or json_encode () in PHP.

    Answers

    If successful, the response http calls will be systematically of type 200 and in json format. It must therefore be decoded. It will be structured, after decoding, as follows:

    		{
    			output1: {}, [] or string of input variables (depending on the call),
    			output2: {}, [] or string of input variables (depending on the call)
    			....
    		}
    		
    In case of failure, the answer will be typically of type 400-404, and an error message will be included in the response body.

    Referencing documents

    Each document of a user account is identified by a unique identifier. Calls that target documents must necessarily reference the identifiers of one or more documents. These identifiers are passed as an array of values, usually stored in a variable named index.

    			var index = [id_doc_1, id_doc_2 ...] / / javascript
    			$index = array (id_doc_1, id_doc2, ...) / / php
    		

    Tags and paths

    Data classification in Wagapi is not based on the use of a hierarchical tree but relies on the characterization by keywords or tags. Whenever it comes to the path,, it is in fact a list of keywords that could be likened to a series of subdirectories. For instance:

    path: [tags1, tags2, tags3]
    corresponds to a location together the three key words which a tree is equivalent to the classical path /tag1/tag2/tag3/, with the difference that the order of the tags does not matter. And locations are equivalent, which provides great flexibility in the classification of the information.
    [Tags1, tags2, tags3] <=> [tags1, tags3, tags2] <=> [tags3, tags2, tags1] <=> ...
    The name under which a document is saved (without extension) is itself a tag.

    Character Encoding

    All strings sent to the server must be encoded in UTF8.

    Detailed description of available function calls

    Examples in javascript and PHP are available here .

    /access/account

    Description
    Authentication and obtaining a session token
    URL structure
    https://www.wagapi.com/wgp/api/access/account
    Methods:
    GET, POST
    Parameters
    key
    string
    Key to access the API application
    user
    string
    User account ID
    password
    string
    Password of the user account
    Returns
    auth_validity
    Int.
    Validity of the session token (in seconds)
    auth_token
    string
    Token sessions
    account_id
    string
    Account ID
    The session token typically has a duration of 24 hours. It is to include, as well as the key for authentication in all subsequent calls.
    //Using javascript and jQuery
    $('#montext').on('click', function(event){
    var call = "/access/account";
    var request = [	
    		'user=dupont',
    		'password=32KJHJ2JH',
    		'key=7DHLKELKKJ'
    	].join('&');
    $.ajax({
    	type: "GET",
    	url : "https://www.wagapi.com/wgp/api" + call,
    	data: request,
    	dataType: "JSON",
    	success: function(data){
    		$('#montext').html(
    			['Jeton de session:'+data['auth_token'],
    			'Identifiant du compte utilisateur'+data['account_id']
    			].join('</br>');
    		);
    	},
    	statusCode: {
    		401: function() {
    					$('#montext').html("Identifiants erronés");
    				},
    		403: function() {
    					$('#montext').html("Accès refusé");
    				}							
    	});				
    
    });			
    

    /access/upload

    Description
    Obtaining an address of temporary storage
    URL structure
    https://www.wagapi.com/wgp/api/<account_id>/access/upload
    Methods:
    GET, POST
    Parameters
    validity
    Int.
    Optional parameter specifying the duration of the url in seconds (default 360 seconds or 5 minutes)
    Returns
    path
    string
    Url to upload documents based on the call /upload
    validity
    Int.
    Validity of the url
    The URL can be requested several times, including for simultaneous uploads during the period of validity

    /upload (POST)

    Description
    Upload one or more documents by POST method. Calling this method requires the prior temporary access to the upload method / access / upload. This call is not based on the use of variable data, but only on the POST variable name. It is possible to send multiple documents with a single call. The result is in json format.
    URL structure
    https://www.wagapi.com/wgp/api/<account_id>/upload
    Methods:
    Post
    Parameters
    name
    string
    It is imperative to inform the POST variable name and its value to files []
    Returns
    ld:
    string
    Id of the added file. Any designation used for direct file subsequent calls to the API.
    name
    string
    Filename
    size
    string
    File size in bytes
    Type (*)
    string
    MIME type
    error
    string
    If non-empty, indicating the problem.
    checksum
    string
    md5 file
    The result is an array containing an entry for each file sent. Each entry is an object containing the previous fields.

    /upload (PUT)

    Description
    Upload a document PUT method. Calling this method requires the prior temporary access to the upload method / access / upload
    URL structure
    https://www.wagapi.com/wgp/api/<account_id>/upload/<temporary_access>/<file_name[urlencoded]>
    Methods:
    PUT
    Parameters
    temporary_access
    string
    An authenticated user can provide his session token as the name of the temporary directory. To upload a document without using the session token must have gained access préalabement temporary upload by the method / access / upload.
    Nom du fichier
    string
    file_name matches the full name of the document with its extension and must be a url encoding.
    Returns
    ld:
    string
    Id of the added file. Any designation used for direct file subsequent calls to the API.
    name
    string
    Filename
    size
    string
    File size in bytes
    Type (*)
    string
    MIME type (non-informed in the case of the PUT method)
    error
    string
    If non-empty, indicating the problem.
    checksum
    string
    md5 file
    The result is an array containing an entry for each file sent. Each entry is an object containing the previous fields.
    //Using PHP en CURL
    //Variable $upload_path is returned by the call /access/upload
    //or can be derived from a session authentication token (cf. documentation)
    $upload_path = "https://www.wagapi.com/wgp/api/upload/7c37b7g507bd901b335f/";
    $localfile = urlencode("math.txt");
    $url = $upload_path.$localfile; 
    $fp = fopen ($localfile, "r"); 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_VERBOSE, 1); 
    //curl_setopt($ch, CURLOPT_USERPWD, 'user:password'); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_PUT, 1); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_INFILE, $fp); 
    curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile)); 
    $http_result = curl_exec($ch); 
    $error = curl_error($ch); 
    $http_code = curl_getinfo($ch ,CURLINFO_HTTP_CODE); 
    curl_close($ch); 
    fclose($fp); 			
    

    /delete/docs

    Description
    Permanently removes the specified documents
    URL structure
    https://www.wagapi.com/wgp/api/<account_id>/delete/docs
    Methods:
    Post
    Parameters
    ids
    array
    Contains the ids of elements to delete the form of a table entry
    Returns
    quota_allowed
    Int.
    Total space allocated in bytes
    quota_used
    Int.
    Used space in bytes

    /download/doc

    Description
    Triggers the download of the file specified by its id. This function requires passing parameters directly in the URL
    URL structure
    https://www.wagapi.com/wgp/api/<account_id>/download/ doc/<auth_token>/<id>
    Methods:
    GET
    Parameters
    ld:
    string
    Id download document
    auth_token
    string
    Token
    Downloading the document referred to is initiated with a header of Content-type: application / octet-stream

    /list/docs/from/path

    Description
    List the documents referenced in the selected location
    URL structure
    https://www.wagapi.com/wgp/api/<account_id>/list/docs/from/path
    Methods:
    GET
    Parameters
    path
    array
    Table listing the tags up the path to the location
    Returns
    index
    array
    Id list of documents identifying
    files
    array
    List of associative arrays containing the properties of the documents listed in index, ie ['id'], ['name'] ['size'] ['extension'], ['date_in']
    //With javascript and jQuery
    $('#somedocslist').on('click', function(event){
    	var url_base = "https://www.wagapi.com/wgp/api"
    	var call="/list/docs/from/path";
    	var request = {path:['2012','Annecy']};
    	$.ajax({
    		type: "GET",
    		url: url_base+'/'+account_id+call,				
    		data:'data='+JSON.stringify(request),
    		dataType: "JSON",
    		beforeSend: function(xhr){
    						xhr.setRequestHeader('auth_token', 7c3jm06507ca725450b3);
    						xhr.setRequestHeader('key', '7DHLKELKKJ');
    					},				
    		success: function(data){
    				$('#somedocslist').html(data['index'].join(','));
    					}
    	});				
    
    });			
    

    /link/docs

    Description
    Creates a temporary or permanent link to each document listed available without authentication
    URL structure
    https://www.wagapi.com/wgp/api/<account_id>/link/doc
    Methods:
    GET
    Parameters
    index
    array
    Table listing the ids of the various documents targeted
    validity
    Int.
    validity requested in seconds [0 corresponds to an infinite lifetime]
    Returns
    index
    array
    Table listing the ids of the various documents targeted
    links
    array
    Array containing the generated link for each document
    collectionLink
    string
    Link to a page gathering all documents
    Tables and index links are ordered in the same way

    /add/docs/to/path

    Description
    Adds one or more documents to the designated location, each directory in the path forming a tag
    URL structure
    https://www.wagapi.com/wgp/api/<account_id>/add/docs/to/path
    Methods:
    GET, POST
    Parameters
    index
    array
    Table listing the ids of the various documents targeted
    path
    array
    Table listing the tags up the path to the location. Tags are case insensitive.

    /rem/docs/from/path

    Description
    Removes one or more documents to the designated location, each directory in the path forming a tag
    URL structure
    https://www.wagapi.com/wgp/api/<account_id>/rem/docs/from/path
    Methods:
    GET, POST
    Parameters
    index
    array
    Table listing the ids of the various documents targeted
    path
    array
    Table listing the tags up the path to the location. Tags are case insensitive.

    /list/tags/from/path

    Description
    List directories / tags existing in the designated location, each directory in the path forming a tag
    URL structure
    https://www.wagapi.com/wgp/api/<account_id>/list/tags/from/path
    Methods:
    GET, POST
    Parameters
    path
    array
    Table listing the tags up the path to the location. Tags are case insensitive.
    Returns
    tags
    array
    Table listing the tags referenced

    /list/tags/all

    Description
    List directories / tags existing in the designated location, each directory in the path forming a tag
    URL structure
    https://www.wagapi.com/wgp/api/ <account_id> / list / tags / from / path
    Methods:
    GET, POST
    Returns
    tags
    array
    Table listing the tags referenced

    /find/file

    Description
    Retrieves a document on the basis of its name, its size and MD5 (checksum)
    URL structure
    https://www.wagapi.com/wgp/api/<account_id>/find/file
    Methods:
    GET, POST
    Parameters
    name
    string
    Filename
    size
    string
    File size in bytes
    checksum
    string
    md5 file
    Returns
    ld:
    string
    Id of the file identified corresponding
    name
    string
    Filename
    size
    string
    File size in bytes
    error
    string
    If non-empty, indicating the problem.
    checksum
    string
    md5 file
    Parameters and the result, if there is one, correspond to objects whose fields are described above and are placed in the variable data