Xpace Post Documents

Insert Document

To add new document.

  • URL

              https://api.xbuffer.net/client/<..user_name..>/<..project_name..>/
            
  • Methods & Params

    This method is to create new document in a specific collection. It also adds new objects inside an existing documents.

    Request Method:

    POST

    Required Params:

    • appid key must be presented to access your data. Each project has it's own unique id for different platforms such as "web", "iOS", etc... You must provide the platform key after the appid by seperate them by a colon (:). You can get the appid from your account's control panel. You can reset one or all keys but you have to update your requests by the new generated keys.
    • type key must be provided to determain what type of data is needed. Current values are data for requesting text data and media for requesting files and images.
    • request key must be provided to insert data to a specific collection.
    • data key must has a JSON object value. This is the data that is going to be created as a new document.
    headers: { ... 
    'Content-Type': 'application/json'
    ... }

    body: { ...
    appid=[string:string]
    type=[string]
    request=[string]
    data=[json]
    ... }

    Optional Params:

    • Authorization header is need if the data needed is restricted. Read more about authorization by clicking here
    • id key is important if you want to insert new value to specific field or array inside existing object.
    • record key is important if you want to insert new value to specific field or array inside existing object. You must provide the id key to be able to use it.
    headers: { ... 
    'Authorization': 'Bearer <...token...>'
    ... }
    body: { ...
    id=[string]
    record=[string]
    ... }
  • Success Response:

    If the request was accepted and the document was created successfully, you'll get the id of the inserted document.

    Response Code: 200
    Content:
    { 
    "success": true
    "data": {
    "Affected-ID: ...."
    }
    }
  • Error Response:

    In case of error response, you'll get a response error code, internal error code and a message explianing the error type.

    Response Code: 400, 401 or 406
    Content:
    { 
    "success": false
    "data": {
    "Code: [XBGRL0000]"
    "Message: ...."
    }
    }
  • JavaScript Example to create new documents using jQuery :

    // Object to insert
    var obj = { 
      "user": {
        "profile": {
          "name": "user name",
          "email": "user email"
        }
      }
    }
    
    function send() {
      var url = "https://api.xbuffer.net/client/<..user_name..>/<..project_name..>/"
      var parameters = {
        appid: 'abs23...3cb:web',
        type: 'data',
        request: 'settings',
        data: obj
      }
    
      $.ajax({
        url: url,
        type: 'post',
        dataType: 'json',
        success: function (data) {
          console.log(data)
        },
        data: parameters
      });
    }
    
    // Result
    {
      "success": true,
      "data": {  
        "Affected-ID: ...." 
      } 
    }
            
  • JavaScript Example to insert new object inside existing document using jQuery :

    // Object in databse
    {
      _id: "...",
      user: {
        profile: {
          name: "user name",
          email: "user email"
        }
      }
    }
    
    // The result of the object in database we want to acheive
    {
      _id: "...",
      user: {
        profile: {
          name: "user name",
          email: "user email",
          settings: {
            autoLogin: true
          }
        }
      }
    }
    
    // Parcial object we want to insert
    var obj = {
      "settings": {
        "autoLogin": true
      }
    }
    
    function send() {
      var url = "https://api.xbuffer.net/client/<..user_name..>/<..project_name..>/"
      var parameters = {
        appid: 'abs23...3cb:web',
        type: 'data',
        request: 'settings',
        id: 'abd123',
        record: 'user-profile',
        data: obj
      }
    
      $.ajax({
        url: url,
        type: 'get',
        dataType: 'json',
        success: function (data) {
          console.log(data)
        },
        data: parameters
      });
    }
    
    // Result
    {
      "success": true,
      "data": {  
        "Affected-ID: ...." 
      } 
    }
            
  • iOS Example using Almofire :

              ... soon ...
            
  • Android Example:

              ... soon ...
            

Upload Files

To upload files and/or images.

  • URL

              https://api.xbuffer.net/client/<..user_name..>/<..project_name..>/
            
  • Methods & Params

    This method is to request a file or an image. If the file requested is an image, you can pass another parameter to get specific size if the image was resized during upload. Size parameter will be ignored if the file type is not an image.

    Request Method:

    POST

    Required Params:

    • appid key must be presented to access your data. Each project has it's own unique id for different platforms such as "web", "iOS", etc... You must provide the platform key after the appid by seperate them by a colon (:). You can get the appid from your account's control panel. You can reset one or all keys but you have to update your requests by the new generated keys.
    • files key must has at least one file and up to 10 files maximum per request.
    • request key is the destination folder for the uploaded file.
    headers: { ... 
    'Content-Type': 'multipart/form-data'
    ... }

    body: { ...
    appid=[string:string]
    files=[FILES]
    request=[string]
    ... }

    Optional Params:

    • Authorization header is need if the data needed is restricted. Read more about authorization by clicking here
    • resize key is useful to resize your images based on the sizes you set in your account's control panel.
    headers: { ... 
    'Authorization': 'Bearer <...token...>'
    ... }

    body: { ...
    resize=[boolean]
    ... }
  • Success Response:

    If the request was accepted and there were results for your request, you'll be getting two array. The error arrya will let you know the files that were not uploaded successfully. The second array is the files with theier path and were uploaded successfully.

    Response Code: 200
    Content:
    { 
     "success": true 
     "data": {  
        "errors": [],
        "files": []
      } 
    }
            
  • Error Response:

    In case of error response, you'll get a response error code, internal error code and a message explianing the error type.

    Response Code: 400, 401 or 406
    Content:
    { 
    "success": false
    "data": {
    "Code: [XBGRL0000]"
    "Message: ...."
    }
    }
  • JavaScript Example to create new documents using jQuery :

    // Prepare your files before uploading
    var url = "https://api.xbuffer.net/client/<..user_name..>/<..project_name..>/"
    var sendData = new FormData()
    sendData.append('appid', 'abs23...3cb:web')
    sendData.append('request', 'my_folder/inside_folder')
    sendData.append('resize', true)
    for(let i = 0; i < files.length; i++) {
      sendData.append('files', files[i])
    }
    
    function send() {
      $.ajax({
        url: url,
        type: 'post',
        contentType: false,
        processData: false,
        data: sendData
        success: function (data) {
          console.log(data)
        },
      });
    }
    
    // Result
    {
      "success": true,
      "data": {  
        "errors": [],
        "files": [
          "my_folder/inside_folder/file01.jpg",
          "my_folder/inside_folder/file02.jpg",
        ]
      } 
    }