Perform Batch Actions

You can combine multiple operations into a single HTTP request (batch actions) to improve performance. The request body is a JSON object with a field named parts, which is an array of objects. Each object in the array contains:

  • A unique ID
  • A relative path to the resource
  • An operation
  • (Optional) A payload

You can also use batch requests to perform custom actions. However, all custom actions may not be supported in batch requests. For the unsupported custom actions, the batch request displays this error: The action {ACTION_NAME} isn't enabled for batch execution.

Note:

If a single part in the payload for a batch request fails, then all the other parts also implicitly fail because batch actions are essentially all-or-none actions. If a certain part fails due to an error, then only the part containing the error is listed in the response. Parts without errors aren't listed in the response. However, none of the parts are processed.

The JSON schema of a batch action request is as follows:


{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "title": "Batch execution",
    "description": "Group multiple requests together ('part').",
    "definitions": {
        "Part": {
            "type": "object",
            "allOf": [
                {
                    "properties": {
                        "id": {
                            "type": "string",
                            "description": "An identification provided by the client to distinguish each part provided in the batch request."
                        },
                        "path": {
                            "type": "string",
                            "description": "Resource's location."
                        },
                        "operation": {
                            "type": "string",
                            "enum": [
                                "get",
                                "create",
                                "update",
                                "replace",
                                "delete"
                            ],
                            "description": "The operation that will be performed."
                        },
                        "preconditionSucceeded": {
                            "type": "boolean",
                            "description": "This attribute is set in the batch response only when ifMatch or ifNoneMatch are provided in the request. It will be 'true' if the precondition (ifMatch/ifNoneMatch) was satisfied, otherwise 'false'."
                        },
                        "payload": {
                            "oneOf": [
                                {
                                    "$ref": "resource-item.json",
                                    "description": "The payload that will be used in the operation. Example: a resource instance should be provided in order to execute a 'create'."
                                },
                                {
                                    "type": "null"
                                }
                            ]
                        }
                    },
                    "required": [
                        "id",
                        "path",
                        "operation"
                    ]
                }
            ],
            "anyOf": [
                {
                    "properties": {
                        "ifMatch": {
                            "type": "string",
                            "description": "This attribute is analogous to the If-Match header. It represents a precondition to execute this operation. The value can be null (same effect of 'If-Match: *') or an array of resource versions."
                        }
                    }
                },
                {
                    "properties": {
                        "ifNoneMatch": {
                            "type": "string",
                            "description": "This attribute is analogous to the If-None-Match header. It represents a precondition to execute this operation. The value can be null (same effect of 'If-None-Match: *') or an array of resource versions."
                        }
                    }
                }
            ],
            "description": "Represents a request."
        }
    },
    "properties": {
        "parts": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/Part"
            },
            "description": "Array that represents multiple requests."
        }
    },
    "required": [
        "parts"
    ]
}

Example: Retrieving an Existing Account, Creating a New Account, and Retrieving a Sales Team Member Details

This request retrieves an existing account, creates a new account, and retrieves a sales team member details:

curl \
https://servername.fa.us2.oraclecloud.com/crmRestApi/resources/11.13.18.05 \
-H 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \
-H 'Content-Type: application/vnd.oracle.adf.batch+json'
{
"parts": [
{
"id": "part1",
"path": "/accounts/100100003227292",
"operation": "get"
},
{
"id": "part2",
"path": "/accounts/100100003227294",
"operation": "create",
"payload": {
	"Address" : [ 
		{
		"AddressLine1" : "500 oracle parkway",
		"City" : "Redwood Shores",
		"State" : "CA",
		"Country" : "US"
		}
		]
	}
}
{
"id": "part3",
"path": "/accounts/100100003230718/child/SalesTeamMember/300100018233318",
"operation": "get"
}
]
}

The response body contains the result and uses the same media type as the request.


{
"parts": [
{
"id": "part1",
"path": "/accounts/100100003227292",
"operation": "get"
"payload" : {
	"PartyId" : 999997549785817,
	"PartyNumber" : "100100003227292",
	"SourceSystem" : null,
	"SourceSystemReferenceValue" : null,
	"OrganizationName" : "High Technology_102304669",
	"UniqueNameSuffix" : "(REDWOOD CITY, US)",
	"PartyUniqueName" : "High Technology_102304669 (REDWOOD CITY, US)",
	"Type" : "ZCA_CUSTOMER",
	"OwnerPartyId" : null,
	"OwnerPartyNumber" : null,
	"OwnerEmailAddress" : null,
	"OwnerName" : null,
	...
	}
},
},
{
"id": "part2",
"path": "/accounts/100100003227294",
"operation": "create",
"payload" : {
	"PartyId" : 300100046354520,
	"PartyNumber" : "100100003227294",
	"AddressId" : 300100046354531,
	"AddressNumber" : "CDRM_100005",
	"CreatedByModule" : "HZ_WS",
	"FormattedAddress" : "REDWOOD SHORES, CA",
	"FormattedMultilineAddress" : "REDWOOD SHORES, CA",
	"City" : "Redwood Shores",
	"Country" : "US",
	"State" : "CA",
	...
	}
}
{
"id": "part3",
"path": "/accounts/100100003230718/child/SalesTeamMember/300100018233318",
"operation": "get"
"payload" : {
	"TeamMemberId" : 300100046354524,
	"SalesProfileId" : 300100046354521,
	"ResourceId" : 100010025532672,
	"MemberFunctionCode" : null,
	"AccessLevelCode" : "300",
	"LockAssignmentFlag" : true,
	"AssignmentTypeCode" : "MANUAL",
	...
	}
}
]
}

Example: Retrieving an Existing Sales Territory and Updating Another Sales Territory

This request retrieves an existing sales territory and updates the details of another sales territory:

curl \
https://servername.fa.us2.oraclecloud.com/crmRestApi/resources/11.13.18.05 \
-H 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \
-H 'Content-Type: application/vnd.oracle.adf.batch+json'
{
"parts": [
{
"id": "part1",
"path": "/territories/100000015312131",
"operation": "get"
},
{
"id": "part2",
"path": "/territories/300100128873880",
"operation": "update",
"payload": {
	"Name":"Rest_Terr_Updated",
	"Description" : "Updating a Draft Territory"
	}
}
]
}

The response body contains the result and uses the same media type as the request.


{
"parts":[
{
"id":"part1",
"path":"/territories/100000015312131",
"operation":"get",
"payload" :{
	"EffectiveEndDate": "4713-01-31"
	"EffectiveStartDate": "2010-01-13"
	"Name": "APAC Sales QA Organization Type"
	"TerritoryVersionId": 100000015312131
	"OwnerResourceId": 100010032635399
	...
	}
}, 
{
"id" : "part2",
"path" : "/territories/300100128873880",
"operation" : "update",
"payload" : {
	"Description": "Updating a Draft Territory",
	"EffectiveEndDate": null,
	"EffectiveStartDate": null,
	"Name": "Rest_Terr_Updated",
	"TerritoryVersionId": 300100091635502,
	"OwnerResourceId": 100010025532672,
	...
	} 
}
]
}

Batch processes help you get tasks done more quickly and efficiently.