{ "basePath": "/", "swaggerVersion": "1.1", "apiVersion": "0.1", "apis": [ { "operations": [ { "errorResponses": [ { "reason": "If the transaction is fully executed and committed on the server, HTTP 200 will be returned.

", "code": "200" }, { "reason": "If the transaction specification is either missing or malformed, the server will respond with HTTP 400.

", "code": "400" }, { "reason": "If the transaction specification contains an unknown collection, the server will respond with HTTP 404.

", "code": "404" }, { "reason": "Exceptions thrown by users will make the server respond with a return code of HTTP 500

", "code": "500" } ], "parameters": [ { "dataType": "String", "paramType": "body", "required": true, "name": "body", "description": "Contains the collections and action.

" } ], "notes": "

The transaction description must be passed in the body of the POST request.

The following attributes must be specified inside the JSON object:

The following optional attributes may also be specified in the request:

If the transaction is fully executed and committed on the server, HTTP 200 will be returned. Additionally, the return value of the code defined in action will be returned in the result attribute.

For successfully committed transactions, the returned JSON object has the following properties:

If the transaction specification is either missing or malformed, the server will respond with HTTP 400.

The body of the response will then contain a JSON object with additional error details. The object has the following attributes:

If a transaction fails to commit, either by an exception thrown in the action code, or by an internal error, the server will respond with an error. Any other errors will be returned with any of the return codes HTTP 400, HTTP 409, or HTTP 500.

", "summary": " Execute transaction", "httpMethod": "POST", "examples": "

Executing a transaction on a single collection:



shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/transaction <<EOF\n{ \n  \"collections\" : { \n    \"write\" : \"products\" \n  }, \n  \"action\" : \"function () { var db = require('internal').db; db.products.save({});  return db.products.count(); }\" \n}\nEOF\n\nHTTP/1.1 200 OK\ncontent-type: application/json; charset=utf-8\n\n{ \n  \"result\" : 1, \n  \"error\" : false, \n  \"code\" : 200 \n}\n



Executing a transaction using multiple collections:



shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/transaction <<EOF\n{ \n  \"collections\" : { \n    \"write\" : [ \n      \"products\", \n      \"materials\" \n    ] \n  }, \n  \"action\" : \"function () {var db = require('internal').db;db.products.save({});db.materials.save({});return 'worked!';}\" \n}\nEOF\n\nHTTP/1.1 200 OK\ncontent-type: application/json; charset=utf-8\n\n{ \n  \"result\" : \"worked!\", \n  \"error\" : false, \n  \"code\" : 200 \n}\n



Aborting a transaction due to an internal error:



shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/transaction <<EOF\n{ \n  \"collections\" : { \n    \"write\" : \"products\" \n  }, \n  \"action\" : \"function () {var db = require('internal').db;db.products.save({ _key: 'abc'});db.products.save({ _key: 'abc'});}\" \n}\nEOF\n\nHTTP/1.1 400 Bad Request\ncontent-type: application/json; charset=utf-8\n\n{ \n  \"exception\" : \"[ArangoError 1210: unique constraint violated]\", \n  \"stacktrace\" : [ \n    \"[ArangoError 1210: unique constraint violated]\", \n    \"  at Error (native)\", \n    \"  at eval (<anonymous>:1:99)\", \n    \"  at eval (<anonymous>:1:122)\", \n    \"  at post_api_transaction (js/actions/api-transaction.js:268:16)\", \n    \"  at Function.actions.defineHttp.callback (js/actions/api-transaction.js:288:11)\", \n    \"\" \n  ], \n  \"error\" : true, \n  \"code\" : 400, \n  \"errorNum\" : 1210, \n  \"errorMessage\" : \"unique constraint violated\" \n}\n



Aborting a transaction by explicitly throwing an exception:



shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/transaction <<EOF\n{ \n  \"collections\" : { \n    \"read\" : \"products\" \n  }, \n  \"action\" : \"function () { throw 'doh!'; }\" \n}\nEOF\n\nHTTP/1.1 500 Internal Error\ncontent-type: application/json; charset=utf-8\n\n{ \n  \"exception\" : \"doh!\", \n  \"error\" : true, \n  \"code\" : 500, \n  \"errorNum\" : 500, \n  \"errorMessage\" : \"An error has occurred during execution: doh!\" \n}\n



Referring to a non-existing collection:



shell> curl -X POST --data-binary @- --dump - http://localhost:8529/_api/transaction <<EOF\n{ \n  \"collections\" : { \n    \"read\" : \"products\" \n  }, \n  \"action\" : \"function () { return true; }\" \n}\nEOF\n\nHTTP/1.1 404 Not Found\ncontent-type: application/json; charset=utf-8\n\n{ \n  \"exception\" : \"[ArangoError 1203: collection not found]\", \n  \"stacktrace\" : [ \n    \"[ArangoError 1203: collection not found]\", \n    \"  at Error (native)\", \n    \"  at post_api_transaction (js/actions/api-transaction.js:268:16)\", \n    \"  at Function.actions.defineHttp.callback (js/actions/api-transaction.js:288:11)\", \n    \"\" \n  ], \n  \"error\" : true, \n  \"code\" : 404, \n  \"errorNum\" : 1203, \n  \"errorMessage\" : \"collection not found\" \n}\n



", "nickname": "ExecuteTransaction" } ], "path": "/_api/transaction" } ] }