Initiating a REST Call with Transaction Context
You can use the context of a single transaction to execute multiple DML actions on objects which may or may not be inter-dependent through database or application relations. The affected objects need not be necessarily have logical relationships. The single transactional context enables you to commit or rollback one, multiple, or all of the associated DML actions in a single REST call. OneData also executes any hooks (excluding Integration Server hooks) associated with the DML actions in the transaction context.
Before completing the REST call with the transaction context with a commit or rollback action, you can issue any number of continuous REST calls on the objects in the transaction context.
Note:
In a transaction context, if the value of partialcommit parameter is set to true, OneData ignores it and only applies the value false.
1. Create a POST request to initiate the transaction with the format:
http://<appsservername>:<port>/<contextRoot>/rest/<repositoryId>/<projectName>/TX/startTransaction
2. Specify the body of the POST request in the format:
{"svcLogLevel":"<level>"}
Note:
Currently, OneData only supports the svcLogLevel parameter, and the input attributes you use in this parameter override any attributes OneData receives from other URL parameters, or the ones defined in interchange mapping. svcLogLevel is not mandatory. If you choose not to use this parameter, OneData uses attributes in the URL parameter or interchange mapping.
3. Submit the request.
You receive a JSON string as the response with the transaction ID.
Example: {"transactionId":"node111_1434365030000"}
In all subsequent REST calls affecting the DML actions or objects in this transaction, use transactionId as the header key and specify its value as the value returned by the startTransaction request. If any event occurs to interrupt the completion of the REST calls (for example, the OneData server crashes), reinitiate them.
Note:
You can only use one startTransaction in a REST call. Also, if you initiate a REST call without the transactionId, it automatically becomes an independent transaction.
Post-requisites:
Issue an endTransaction request with a suitable value for action in order to commit or rollback a transaction.
Important:
Do not keep a transaction context open for too long. If a transaction context remains open for a long duration, you run the risk of losing all transactions in the context because the connection objects were exhausted or closed.
Related Topics: