Only POST and not GET is allowed.
Requests are posted to:
http(s)://service.avail.net/2009-02-13/dynamic/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/services/jsonrpc-1.x/
The X:es are replaced by your customer id.
POST is limited to 32768 bytes of content-length.
The supported encoding is UTF-8.
For the sake of brevity, only 1.1 is described.
Version - Denotes the version of JSON-RPC. If version is not stated, 1.0 is assumed. If version is stated, it must be 1.1.
Id - Is an optional request-identifier that can be used in batched or asynchronous requests to determine which call a response belongs to.
The compressed responses are supported through the use of header: Accept-Encoding: gzip.
The properties can be in any order.
Named Parameters
When the parameters are named, they do not have to be in the order specified in the API.
Syntax:
{"method": "Method Name", "params": {"Argument Name 1": "Argument Value 1", "Argument Name N": "Argument Value N"}, "version": "1.1", "id": "id"}
Example:
{"method": "saveSearch", "params": {"SearchPhrase": "harry potter", "ProductID": "12345"}, "version": "1.1"}
Unnamed Parameters
With unnamed parameters the order determine which parameter is which.
Syntax:
{"method": "Method Name", "params": ["Argument Value 1", "Argument Value N"], "version": "1.1", "id": "id"}
Example:
{"method": "saveSearch", "params": ["harry potter", "12345"], "version": "1.1"}
Batched Requests
With batched requests it is possible to invoked multiple methods with the same call.
Batched request are used to improve performance.
Batched requests are done as in JSON-RPC 2.0.
The batched requests can be made with both named and unnamed parameters.
Syntax:
[Request1,RequestN]
Example:
[{"method": "saveSearch", "params": ["harry potter", "12345"], "version": "1.1", "id": "2"},{"method": "saveSearch", "params": ["poker book", "6789"], "version": "1.1", "id": "7"}]
The order of the returned properties is arbitrary. If
id is not passes as an input argument
"id": "null" is returned. If there is no error 1.1 does not return an error object, but 1.0 returns
"error": null.
Syntax:
{"result": {"Result Name 1": "Result Value 1", "Result Name N": "Result Value N"}, "version": "1.1", "id": "id"}
Example:
{"result": {"values": ["1234", "4566"], "trackingcode": "tabcdefg"}, "version": "1.1", "id": "55"}
Batched Requests Responses
Syntax:
[Response,Respons2]
Example:
[{"result": {"values": ["1234", "4566"], "trackingcode": "tabcdefg"}, "id": "3", "version": "1.1"}, {"result": {"values": ["9876", "4321"], "trackingcode": "tabcdefg"}, "id": "4", "version": "1.1"}]
Errors
Syntax:
{"error": "Error Message", "version": "1.1", "id": "id"}
Example:
{"error": "something went wrong!", "version": "1.1", "id": "77"}
For testing and debugging purposes, request can be sent as GET requests.
For GET requests Avail uses the POST-syntax and does not follow the specifications. GET requests are limited to about 32768 bytes (depends on what browser, proxy or web application framework you are using).
Do not use GET for implementation as these are prone to change without prior warning.
GET requests allows you to test your calls using a browser.
To test the calls below, replace the X:s with your customer id and append the call to:
http://service.avail.net/2009-02-13/dynamic/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/services/jsonrpc-1.x/
For example:
http://service.avail.net/2009-02-13/dynamic/11111111-2222-3333-4444-555555555555/services/jsonrpc-1.x/{"params": ["sess1", "harry potter", "GETPREDEXT_DEFAULT"], "method": "getSearchPredictions", "id": "123"}
Call that returns status
Call
{"method": "registerSession", "params": {"SessionID": "sess2"}, "id": "123"}
Response
{"id": "123", "error": null, "result": {"values": ["Registered SessionId."]}}
Call that returns predictions
Call
{"version": "1.1", "params": {"SessionID": "mySessionId123", "Input": ["Phrase:Harry Potter","ProductId:1234","ProductIds:0818406593,1416927190","UserId:travel1"], "TemplateName": "FirstPage"}, "method": "getRecommendations", "id": "123"}
Response
{"id": "123", "version": "1.1", "result": {"trackingcode": "7974624b", "values": [["1580421660"],["0446695629"],["158042080X"],["1416903674"],["1580422039"]]}}
Call that returns predictions with meta data
Call
{"version": "1.1", "params": {"ColumnNames": ["ProductID", "Title"], "SessionID": "mySessionId124", "Input": ["Phrase:Harry Potter","ProductId:1234","ProductIds:0818406593,1416927190","UserId:travel1"], "TemplateName": "FirstPage"}, "method": "getRecommendations", "id": "123"}
Response
{"id": "123", "version": "1.1", "result": {"trackingcode": "bacda2b2", "values": [["1580421660", "How to Win the Championship: Hold'em Strategies for the Final Table"], ["0446695629", "The Book of Bluffs: How to Bluff and Win at Poker"]]}}
Call that logs the event that a user makes a purchase.
Call
{"version": "1.1", "params": {"SessionID": "sess321", "UserID": "user321", "ProductIDs": ["1400040361", "0312346069"], "Prices": ["15.00", "9.00"], "OrderID": "304711248", "Currency": "SEK"}, "method": "logPurchase", "id": "123"}
Response
{"id": "123", "version": "1.1", "result": {"values": ["Purchase logged."]}}
Call with dynamic parameter
Call
{"version": "1.1", "params": {"SessionID": "mySessionId125", "Input": ["Phrase:Harry Potter","ProductId:1234567890","ProductIds:1234567890,1234567888","UserId:travel1"], "TemplateName": "GETPREDEXT_DEFAULT", "DynamicParameters":["replace orcat in subtemplate 1 with c1"]}, "method": "getRecommendations", "id": "124"}
Response
{"id": "123", "error": null, "result": {"trackingcode": "7829b3be", "values": [["1416914285"],["1400040361"],["0312346069"],["1557987904"],["1552093697"]]}}