You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

Common Methods

/object/create

To create a new object.

/object/delete

To delete an object.

/object/get

To retrieve the object's attributes.

/object/set

To set the object's attributes.

/object/search

To retrieve a collection of objects.


Where "object" is the name of the object

/object/create

To create a new object. On success, the method always returns the internal object id of the newly created object

Parameters
{
    "attrs":{list of attribute value pairs}
}
Response
{
    "result":{"id":the id of the newly created object}
}


Examples:
Method:/user/create

Parameters
{
    "attrs":
    {
        "domain.id":2,
         "name":"John Smith",
         "email":"js@acme.com"
    }
}
Response
{
    "error":0,
    "result":{"id":"1234567890abcd"}
}


-------------------------------------------------------------------
Method:/token/create

Parameters
{
    "attrs":
    {
        "user.id":"user id",
        "product.id":"product id"
    }
}
Response
{
    "error":0,
    "result":{"id":"1234567890abcd"}
}


/object/delete

To delete an object. The request parameter MUST be the internal id of the object to be deleted. On success the method returns error 0.
Parameters: {"id":the id of the object to be deleted}
Response: {"error":0}
Example:
Method:/user/delete

Parameters
{
    "id":"1234567890abcd"
}
Response
{
    "error":0
}


/object/get

To retrieve the object's attributes. The request must provide an array of attributes that are to be retrieved. On success the method returns a list of attribute value pairs. 

Parameters
{
    "match":[array of expressions],
    "return":[array of attribute names]
}
Response
{
    "result":{list of attribute pairs}
}

See /object/search for the description of match expression and conditions.

+Example:+

Parameters
{
    "match":
    [
         ["id","=","userid"]
    ],
    "return":["name","email","phone"]
}
Response
{
    "error":0,
    "result":
    {
        "name":"JohnSmith",
        "email":"js@acme.com",
        "phone":"442088654321"
    }
}

Notes: To return all simple type attributes, use "*" in the return array. (Object and collection attribute has to be specified explicitly)


/object/set

To set the object's attributes. The request must provide a list of attributes and values that are to be set. On success the method returns error 0.

Parameters
{
    "id":"the id of the object to be edited",
    "attrs":{list of attribute pairs}
}


Response
{
    "error":0
}


Example:
Method:/user/set

Parameters
{
    "id":"user id",
    "attrs":
    {
        "name":"John Smith",
        "email":"js@acme.com"
    }
}


Response
{
    "error":0
}

/object/search

To retrieve a collection of objects. The request must provide a search query which consists of the following parts:

  • Match : Match Rule
  • Return: Return attributes
  • Sort: Sort
  • Order: Order
  • Max: Maximum number of records to return
  • Offset: Offset

On success the method returns an array of object IDs.
A match rule consists of an array of expressions , and all expression should result in true.
A match expression is an array of 3 elements:

  • the name of the attribute
  • the operator
  • the value to be matched


For example:
["id","=", 2]
Matching operators supported:
String operators:
= equals to
like like
examples:
["firstName","=", "john"]
["email","like", "j%acme.com"]
Integer operators:
= equals to
< less than
> greater than
examples:
["age","=", 45]
["weight","<", 110]
["size",">", 42]
Date operators:
= equals to
< before
> after
examples:
["lastModified","=", "2009-08-20T00:00:00Z"]
["created","<", "2009-01-12T12:00:00Z"]
["deleted",">", "2008-08-21T08:00:00Z"]
Notes: all date value should be in ISO 8601 format.
Parameters:
{
"match":{list of attributes to be matched}
"return":[array of attributes to be returned]
"sort": attribute to be sorted by
"order":"asc" | "desc"
"max": the maximum numbers of records to return
"offset": the offset
}
Response: {"result":[array of list of attributes]}
Example
Method:/user/search
Parameters:
{
"match":
[
["domain.id", "=", 2],
["lastname", "=", "smith"],
["email", "like", "[%@acme.com (mailto:%25@acme.com)]"]
],
"return":["firstname", "lastname", "email", "phone"],
"sort":"lastname",
"order":"asc",
"max": 20,
"offset": 10
}
Response:
{
"error":0,
"result":
{
"total": 20,
"rows":
[
{
"firstname":"John",
"lastname":"Smith",
"email":"js@acme.com",
"phone":"447974321234",
},
{
"firstname":"David",
"lastname":"Smith",
"email":"ds@acme.com",
"phone":"447974234975",
}
]
}
}
// a failed response
{
"error":101,
"message":"user not found"
}
-------------------------------------------------------------------
Method:/token/search
Parameters:
{
"match":
[
["user.id", "=", 2]
["category", "=", "OTP"]
],
"return":["serial"],
"sort":["serial"]
}
Response:
{
"result":
{
"total":4,
"rows":
[
{"serial":"77004155"},
{"serial":"77004245"},
{"serial":"77004266"},
{"serial":"77004321"},
]
}
}

  • No labels