Xpace Put Documents

Update Document

To update a document or existing object inside a document.

  • URL

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

    This method is to update a document or part of it. You can replace the whole document or an object nested inside existing document.

    Request Method:

    PUT

    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 update data to a specific collection.
    • id key is important if you want to update a value inside specific field or array.
    • data key can have a JSON object value or any data type value like string and numbers. This is the data that is going to be replacing an existing one.
    headers: { ... 
    'Content-Type': 'application/json'
    ... }

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

    Optional Params:

    • Authorization header is need if the data needed is restricted. Read more about authorization by clicking here
    • record key is important if you want to update a value in specific field or array inside existing object. You must provide the id key to be able to use it.
    headers: { ... 
    'Authorization': 'Bearer <...token...>'
    ... }
    body: { ...
    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": "Document has been updated"
    }
  • 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 update an object inside existing document using jQuery :

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

              ... soon ...
            
  • Android Example:

              ... soon ...