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 Opportunity, Creating a New Opportunity, and Retrieving an Opportunity Contact

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": "/opportunities/CDRM_93472",
	"operation": "get"
},
{
	"id": "part2",
	"path": "/opportunities",
	"operation": "create",
	"payload": {
	"Name" : "Major Application Upgrade"
}
}
{
"id": "part3",
"path": "/opportunities/CDRM_3341580/child/OpportunityContact/300100092629555",
"operation": "get"
}
]
}

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


{
"parts": [
{
"id": "part1",
"path": "/opportunities/CDRM_93472",
"operation": "get"
"payload" : {
"BudgetAvailableDate": null,
"BudgetedFlag": false,
"PrimaryOrganizationId": 204,
"ChampionFlag": false,
"CreatedBy": "SALES_ADMIN",
"CreationDate": "2018-01-08T12:00:24.972+00:00",
"CurrencyCode": "USD",
"SalesMethodId": 300100073102472,
"SalesStageId": 300100073102473,
"CustomerAccountId": null,
"DealHorizonCode": null,
"DecisionLevelCode": null,
"Description": null,
"LastUpdateDate": "2018-01-08T12:24:05.310+00:00",
"LastUpdatedBy": "SALES_ADMIN",
"LastUpdateLogin": "6242B5ED93BE3EC9E0539EBDF20ABB8B",
"Name": "Big Data Analytics Servers",
"OptyId": 300100125332293,
"OptyNumber": "CDRM_93472",
},
},
{
"id": "part2",
"path": "/opportunities",
"operation": "create",
"payload" : {
BudgetAvailableDate: null
BudgetedFlag: false
PrimaryOrganizationId: 204
ChampionFlag: false
CreatedBy: "SALES_ADMIN"
CreationDate: "2015-06-04T03:08:27-07:00"
CurrencyCode: "USD"
SalesMethodId: 100000012430001
SalesStageId: 100000012430007
Name: "Major Application Upgrade"
OptyId: 300100111705686
OptyNumber: "CDRM_332708"
}
{
"id": "part3",
"path": "/opportunities/CDRM_3341580/child/OpportunityContact/300100092629555",
"operation": "get"
"payload" : {
AffinityLvlCd: null,
Comments: null,
ContactedFlg: "N",
PartyName: "Juan BELL",
OptyConId: 300100092629555,
PERPartyId: 100000018544431,
CreatorPartyId: 100010025532672,
CreatedBy: "MHoope",
CreationDate: "2016-11-16T05:15:38-08:00",
LastUpdateDate: "2016-11-16T05:15:43-08:00",
ContactPointId: 100000018544441,
FormattedAddress: "1625 19th Ave,SEATTLE, WA 98122",
FormattedPhoneNumber: "2065584951",
ContactPartyNumber: "100000018544430",
...
}
}
]
}

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.