Menu

ProfileAPI

Stephan Zavrel

General information

The profile API allows you to add additional meta data (i.e. a profile) in JSON format to items which can be used for analysis in more sophisticated recommendation strategies.

HTTP functions

Other than all the older REST style easyrec APIs (actions, recommendations,rankings,...) which all use HTTP GET requests exclusively, the new JSON profile API uses the appropriate HTTP functions depending on the type of call, so please pay attention to this fact when reading the documentation below.

MIME Types

All API calls accept data sent in either application/json or application/x-www-form-urlencoded.

JSONPath

The API allows for storing of complete profiles as well as adding and retrieving specific JSON fields to/from already existing profiles. To address specific fields in a profile JSONPath notations are used. You can find a description of JSONPath here and specifics of the implementation used in easyrec at Jayway JSONPath. To give you an easier start we copied some path examples from the latter source.

JSONPath Operators

operator description
$ The root element to query. This starts all path expressions.
@ The current node being processed by a filter predicate
* Wildcard. Available anywhere a name or numeric are required.
.. Deep scan. Available anywhere a name is required.
.<name> Dot-notated child
['<name>' (, '<name>')] Bracket-notated child or children
[<number> (, <number>)] Array index or indexes
[start:end] Array slice operator
[?(<expression>)] Filter expression. Expression must evaluate to a boolean value.

Path Examples

Given the json

{
    "store": {
        "book": [
            {
                "category": "reference",
                "author": "Nigel Rees",
                "title": "Sayings of the Century",
                "price": 8.95
            },
            {
                "category": "fiction",
                "author": "Evelyn Waugh",
                "title": "Sword of Honour",
                "price": 12.99
            },
            {
                "category": "fiction",
                "author": "Herman Melville",
                "title": "Moby Dick",
                "isbn": "0-553-21311-3",
                "price": 8.99
            },
            {
                "category": "fiction",
                "author": "J. R. R. Tolkien",
                "title": "The Lord of the Rings",
                "isbn": "0-395-19395-8",
                "price": 22.99
            }
        ],
        "bicycle": {
            "color": "red",
            "price": 19.95
        }
    },
    "expensive": 10
    }
JsonPath Result
$.store.book[*].author The authors of all books
$..author All authors
$.store.* All things, both books and bicycles
$.store..price The price of everything
$..book[2] The third book
$..book[(@.length-1)] The last book
$..book[0,1] The first two books
$..book[:2] All books from index 0 (inclusive) until index 2 (exclusive)
$..book[1:2] All books from index 1 (inclusive) until index 2 (exclusive)
$..book[-2:] Last two books
$..book[2:] Book number two from tail
$..book[?(@.isbn)] All books with an ISBN number
$.store.book[?(@.price < 10)] All books in store cheaper than 10
$..book[?(@.price <= $['expensive'])] All books in store that are not "expensive"
$..book[?(@.author =~ /.*REES/i)] All books matching regex (ignore case)
$..* Give me every thing

API

Store

This method stores the given profile to the item defined by the tenantid,itemid and the itemtypeid. If there is already a profile it will be overwritten.

Sample Call

HTTP POST

{yourServerURL}/api/1.1/json/profile/store

Parameters

parameter occurrence description
apikey required The required API Key to access this service. (e.g. "8ab9dc3ffcdac576d0f298043a60517a")
tenantid required tenant id to identify your website. (e.g. "EASYREC_DEMO")

Response

Error Codes

Store Item with profile

This method creates a new item and stores the given profile for this item.

Sample Call

HTTP POST

{yourServerURL}/api/1.1/json/profile/storeitemwithprofile

Parameters

parameter occurrence description
apikey required The required API Key to access this service. (e.g. "8ab9dc3ffcdac576d0f298043a60517a")
tenantid required tenant id to identify your website. (e.g. "EASYREC_DEMO")

Response

Error Codes

Delete

This method deletes the profile of the item defined by the tenantid, itemid and the itemtypeid.

Sample Call

HTTP DELETE

{yourServerURL}/api/1.1/json/profile/delete?apikey=8ab9dc3ffcdac576d0f298043a60517a&itemid=42&itemtype=ITEM&tenantid=EASYREC_DEMO

Parameters

parameter occurrence description
apikey required The required API Key to access this service. (e.g. "8ab9dc3ffcdac576d0f298043a60517a")
tenantid required tenant id to identify your website. (e.g. "EASYREC_DEMO")

Response

Error Codes

Field delete

This method deletes a specific field of the profile which belongs to the item defined by the tenantid, itemid and the itemtypeid. The field can be addressed by a JSONPath expression.

Sample Call

HTTP DELETE

{yourServerURL}/api/1.1/json/profile/field/delete?apikey=8ab9dc3ffcdac576d0f298043a60517a&itemid=42&itemtype=ITEM&path=$.store.book.price&tenantid=EASYREC_DEMO

Parameters

parameter occurrence description
apikey required The required API Key to access this service. (e.g. "8ab9dc3ffcdac576d0f298043a60517a")
tenantid required tenant id to identify your website. (e.g. "EASYREC_DEMO")

Response

Error Codes

Load

This method returns the profile of the item defined by the tenantid, itemid and the itemtypeid

Sample Call

HTTP GET

{yourServerURL}/api/1.1/json/profile/load?apikey=8ab9dc3ffcdac576d0f298043a60517a&itemid=42&itemtype=ITEM&tenantid=EASYREC_DEMO

Parameters

parameter occurrence description
apikey required The required API Key to access this service. (e.g. "8ab9dc3ffcdac576d0f298043a60517a")
tenantid required tenant id to identify your website. (e.g. "EASYREC_DEMO")

Response

Error Codes

Field load

This method loads the values from a specific field of the profile which belongs to the item defined by the tenantid, itemid and the itemtypeid. The field can be addressed by a JSONPath expression.

Sample Call

HTTP GET

{yourServerURL}/api/1.1/json/profile/field/load?apikey=8ab9dc3ffcdac576d0f298043a60517a&itemid=42&itemtype=ITEM&path=$.store.book.price&tenantid=EASYREC_DEMO

Parameters

parameter occurrence description
apikey required The required API Key to access this service. (e.g. "8ab9dc3ffcdac576d0f298043a60517a")
tenantid required tenant id to identify your website. (e.g. "EASYREC_DEMO")

Response

Error Codes

Field store

This method stores a value into a specific field of the profile which belongs to the item defined by the tenantid, itemid and the itemtypeid. The field can be addressed by a JSONPath expression.

Sample Call

HTTP PUT

{yourServerURL}/api/1.1/json/profile/field/store

Parameters

parameter occurrence description
apikey required The required API Key to access this service. (e.g. "8ab9dc3ffcdac576d0f298043a60517a")
tenantid required tenant id to identify your website. (e.g. "EASYREC_DEMO")

Response

Error Codes

Field push

This method adds a value to a specific ARRAY field of the profile which belongs to the item defined by the tenantid, itemid and the itemtypeid. The field can be addressed by a JSONPath expression.

Sample Call

HTTP PUT

{yourServerURL}/api/1.1/json/profile/field/push

Parameters

parameter occurrence description
apikey required The required API Key to access this service. (e.g. "8ab9dc3ffcdac576d0f298043a60517a")
tenantid required tenant id to identify your website. (e.g. "EASYREC_DEMO")

Response

Error Codes


Related

Wiki: API

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.