The methods described here allows RANDOM.ORG account holders to delegate use of services to other RANDOM.ORG account holders.
A ‘delegation’ is a relationship between two RANDOM.ORG accounts in which one (the delegator) gives another (the delegate) access to use a particular service (e.g., the Third-Party Draw Service) on behalf of the delegator. The delegator can later remove the delegation if it wishes.
The URL for invoking the Delegation API is: https://api.random.org/json-rpc/2/invoke
addDelegation
(method)
This method creates a delegation of a particular service
between two RANDOM.ORG account holders. Your
client must set the method
property of its JSON-RPC
request object to addDelegation
.
The following parameters are mandatory and should be specified
in the params
array of the JSON-RPC request:
credentials
serviceId
delegateId
The following parameters are optional and can be included in
the params
object of your JSON-RPC request if you
want functionality that is different from the default:
notifyDelegate
(default value true
)true
, RANDOM.ORG will attempt
to issue a notification. No error message is reported to the
delegator if the notification fails or if no method for
notification is configured for the delegate in question.
If the delegation was created successfully,
RANDOM.ORG returns a JSON-RPC response with the
result
property containing an object with the following
named values:
delegationKey
For a successful response, the error
property is
null
.
If a delegation for the service in question already exists
between the two parties, a successful response is returned with
the existing delegationKey
associated with that delegation.
Adding an existing delegation in this manner will trigger a
notification to the delegate if notifyDelegate
was set
to true
in the request and the delegate has a
requested such notifications.
If an error occurred, RANDOM.ORG returns a
JSON-RPC response in which the result
property is
null
and the error
property contains an
error object as described in Error Codes and Messages.
The following requests a delegation to be created between two RANDOM.ORG accounts in which the delegator (whose credentials are included in the request) gives the delegate (who has numeric account identifer 1012) the right to use the Third-Party Draw Service (which has service identifier 2) on their behalf.
{ "jsonrpc": "2.0", "method": "addDelegation", "params": { "credentials": { "login": "test", "password": "secret" }, "serviceId": 2, "delegateId": 1012 }, "id": 42 }
The service responds with the following:
{ "jsonrpc": "2.0", "result": { "delegationKey": "b900f8ec-3812-4258-a659-ee2fcae431f0" }, "error": null, "id": 42 }
(to appear)
removeDelegation
(method)
This method allows a delegator to remove a delegation, effectively
revoking rights previously granted with
the addDelegation
method.
The following parameters are mandatory and should be specified
in the params
array of the JSON-RPC request:
credentials
delegationKey
The following parameters are optional and can be included in
the params
object of your JSON-RPC request if you
want functionality that is different from the default:
notifyDelegate
(default value true
)true
, RANDOM.ORG will attempt
to issue a notification. No error message is reported to the
delegator if the notification fails or if no method for
notification is configured for the delegate in question.
If the delegation was removed successfully, RANDOM.ORG returns a JSON-RPC response with the
result
property containing an empty object.
For a successful response, the error
property is
null
.
If an error occurred, RANDOM.ORG returns a
JSON-RPC response in which the result
property is
null
and the error
property contains an
error object as described in Error Codes and Messages.
The following requests removal of a delegation previously created between the two RANDOM.ORG account holders mentioned in the example above.
{ "jsonrpc": "2.0", "method": "removeDelegation", "params": { "credentials": { "login": "test", "password": "secret" } "delegationKey": "b900f8ec-3812-4258-a659-ee2fcae431f0" }, "id": 42 }
The service responds with the following:
{ "jsonrpc": "2.0", "result": {}, "error": null, "id": 42 }
(to appear)
listDelegations
(method)This method lets the caller list all delegations in which they act as delegator or delegate.
The following parameters are mandatory and should be specified
in the params
array of the JSON-RPC request:
credentials
There are no optional parameters.
If the operation completed successfully,
RANDOM.ORG returns a JSON-RPC response with the
result
property containing an object with the following
named values:
delegations
serviceId
delegatorId
delegateId
delegationKey
For a successful response, the error
property is
null
.
If an error occurred, RANDOM.ORG returns a
JSON-RPC response in which the result
property is
null
and the error
property contains an
error object as described in Error Codes and Messages.
The following requests a list of all delegations that relate to a particular RANDOM.ORG trial account:
{ "jsonrpc": "2.0", "method": "listDelegations", "params": { "credentials": { "login": "test", "password": "secret" } }, "id": 42 }
The service responds with the following:
{ "jsonrpc": "2.0", "result": { "delegations": [ { "serviceId": 2, "delegatorId": 3, "delegateId": 1012, "delegationKey": "b900f8ec-3812-4258-a659-ee2fcae431f0" }, { "serviceId": 2, "delegatorId": 3, "delegateId": 5136, "delegationKey": "dc3faf78-bae1-4b42-a2a8-a54a39237afb" } ], "delegators": [] }, "error": null, "id": 42 }
The response shows that two delegations exist in which the caller participates. (The caller in the example has numeric ID 3, which is a trial account that belongs to RANDOM.ORG.) In both instances, it is the Third-Party Draw Service that is being delegated to other users, allowing those users to use the service on behalf of the trial account.
(to appear)
setNotificationHandler
(method)
This method allows a RANDOM.ORG account holder
to register a handler that will be used to deliver notifications
about the creation and deletion of delegations in which the
account holder is delegate. The client must set
the method
property of its JSON-RPC request object
to setNotificationHandler
.
The following parameters are mandatory and must be specified
in the params
array of the JSON-RPC request:
credentials
handlerUrl
null
for this parameter to delete any
existing handler.
handlerSecret
There are no optional parameters.
If the handler was set correctly,
RANDOM.ORG returns a JSON-RPC response with the
result
property containing an empty object.
For a successful response, the error
property is
null
.
If an error occurred, RANDOM.ORG returns a
JSON-RPC response in which the result
property is
null
and the error
property contains
an error object as described in Error
Codes and Messages.
The following sets a notification handler for the account in question.
{ "jsonrpc": "2.0", "method": "setNotificationHandler", "params": { "credentials": { "login": "test", "password": "secret" }, "handlerUrl": "https://api.example.com/rdo-notify/invoke", "handlerSecret": "insert-very-hard-to-guess-string-here" }, "id": 42 }
The service responds with the following:
{ "jsonrpc": "2.0", "result": {}, "error": null, "id": 42 }
The following deletes any notification handler for the account in question. If no handler exists, this call has no effect.
{ "jsonrpc": "2.0", "method": "setNotificationHandler", "params": { "credentials": { "login": "test", "password": "secret" }, "handlerUrl": null, "handlerSecret": null }, "id": 42 }
The service responds with the following:
{ "jsonrpc": "2.0", "result": {}, "error": null, "id": 42 }
delegationAdded
(notification)
This method must be exposed by a RANDOM.ORG account holder who wishes to receive notifications about the
addition of delegations where the account holder is
delegate. Upon such a change in delegation, RANDOM.ORG will invoke the client's registered notification handler to
deliver the notification. RANDOM.ORG will set
the method
property of its JSON-RPC request object
to delegationAdded
.
The following parameters are mandatory and will be specified
in the params
array of the JSON-RPC request issued by RANDOM.ORG:
serviceId
delegatorId
delegateId
delegationKey
handlerSecret
There are no optional parameters.
If notification was delivered successfully, the notification handler should return a JSON-RPC response with the
result
property containing an empty object.
For a successful response, the error
property should be set to
null
.
If an error occurred, the notification handler should return a
JSON-RPC response in which the result
property is
null
and the error
property contains a
textual description of what went wrong. RANDOM.ORG may then try to deliver the notification again later on.
The following is a request issued by RANDOM.ORG after the creation of a delegation in which the delegator (who has numeric account identifier 3) gives the delegate (who has numeric account identifer 1012) the right to use the Third-Party Draw Service (which has service identifier 2) on their behalf.
{ "jsonrpc": "2.0", "method": "delegationAdded", "params": { "serviceId": 2, "delegatorId": 3, "delegateId": 1012, "delegationKey": "b900f8ec-3812-4258-a659-ee2fcae431f0", "handlerSecret": "insert-very-hard-to-guess-string-here" }, "id": 42 }
To indicate successful acceptance of the notification, the notification handler should respond with the following:
{ "jsonrpc": "2.0", "result": {}, "error": null, "id": 42 }
Because this is a response that indicates successful delivery of the notification, RANDOM.ORG will not retry the delivery again later.
The following is the same request as in the previous example. However, in this case, we assume the notification handler is not able to accept the notification:
{ "jsonrpc": "2.0", "method": "delegationAdded", "params": { "serviceId": 2, "delegatorId": 3, "delegateId": 1012, "delegationKey": "b900f8ec-3812-4258-a659-ee2fcae431f0", "handlerSecret": "insert-very-hard-to-guess-string-here" }, "id": 42 }
To indicate unsuccessful acceptance of the notification, the notification handler should respond with the following:
{ "jsonrpc": "2.0", "result": null, "error": "Unknown error; please retry later.", "id": 42 }
Because this is a response that indicates failed delivery of the notification, RANDOM.ORG may retry the notification again later.
delegationRemoved
(notification)
This method must be exposed by a RANDOM.ORG account holder who wishes to receive notifications about the
removal of delegations where the account holder is
delegate. Upon such a change in delegation, RANDOM.ORG will
invoke the client's registered notification handler to
deliver the notification. RANDOM.ORG will set
the method
property of its JSON-RPC request object
to delegationRemoved
.
The following parameters are mandatory and will be specified
in the params
array of the JSON-RPC request issued by RANDOM.ORG:
serviceId
delegatorId
delegateId
delegationKey
handlerSecret
There are no optional parameters.
If notification was delivered successfully, the notification handler should return a JSON-RPC response with the
result
property containing an empty object.
For a successful response, the error
property should be set to
null
.
If an error occurred, the notification handler should return a
JSON-RPC response in which the result
property is
null
and the error
property contains a
textual description of what went wrong. RANDOM.ORG may then try to deliver the notification again later on.
The following is a request issued by RANDOM.ORG after the creation of a delegation in which the delegator (who has numeric account identifier 3) gives the delegate (who has numeric account identifer 1012) the right to use the Third-Party Draw Service (which has service identifier 2) on their behalf.
{ "jsonrpc": "2.0", "method": "delegationRemoved", "params": { "serviceId": 2, "delegatorId": 3, "delegateId": 1012, "delegationKey": "b900f8ec-3812-4258-a659-ee2fcae431f0", "handlerSecret": "insert-very-hard-to-guess-string-here" }, "id": 42 }
To indicate successful acceptance of the notification, the notification handler should respond with the following:
{ "jsonrpc": "2.0", "result": {}, "error": null, "id": 42 }
Because this is a response that indicates successful delivery of the notification, RANDOM.ORG will not retry the delivery again later.
The following is the same request as in the previous example. However, in this case, we assume the notification handler is not able to accept the notification:
{ "jsonrpc": "2.0", "method": "delegationRemoved", "params": { "serviceId": 2, "delegatorId": 3, "delegateId": 1012, "delegationKey": "b900f8ec-3812-4258-a659-ee2fcae431f0", "handlerSecret": "insert-very-hard-to-guess-string-here" }, "id": 42 }
To indicate unsuccessful acceptance of the notification, the notification handler should respond with the following:
{ "jsonrpc": "2.0", "result": null, "error": "Unknown error; please retry later.", "id": 42 }
Because this is a response that indicates failed delivery of the notification, RANDOM.ORG may retry the notification again later.