Skip to main content
Version: v2.0

Batch API overview

The Batch API lets you submit multiple REST requests in a single HTTP call. This is highly efficient for performing numerous operations while minimizing network overhead and reducing the number of round-trips to the ServiceNow instance.

Commonly used for:

  • Executing multiple unrelated requests, for example, creating an incident and updating a user.
  • Reducing latency when performing many small operations.
  • Ensuring a group of operations reach the server together.

Basic usage

Batching involves collecting multiple RequestInformation objects (from other APIs like Table or Attachment), wrapping them in a BatchRequestModel, and sending them via the Batch endpoint.

// 1. Prepare individual requests using ToRequestInformation methods
request1, err := client.Now().Table("incident").ToGetRequestInformation(context.Background(), nil)
if err != nil {
log.Fatal(err)
}
request2, err := client.Now().Table("sys_user").ToGetRequestInformation(context.Background(), nil)
if err != nil {
log.Fatal(err)
}

// 2. Create a batch request model and add the requests
body := batchapi.NewBatchRequestModel()

// 3. Execute the batch
response, err := client.Now().Batch().Post(context.Background(), body, nil)
if err != nil {
log.Fatal(err)
}

Available operations

Was this page helpful?