Skip to main content

retrieve-request

You can pass retrieve requests directly to the batch() function. Once you execute a batch request you get a list of BatchResponse. A BatchResponse that corresponds with a retrieve request can either be a ReadResponse or an ErrorResponse.

In the example below, you map each given address ID to a GetByKeyRequestBuilder. These retrieve requests are combined into one batch request and executed against a destination.

The example below is based on the Bills of Material service, which contains a function import called getPdf(). This service is an OData v2 service, but the syntax is the same for OData v2 and v4.

const {
billingDocumentApi,
operations: { getPdf }
} = billingDocumentService();

async function batchExample(documentIds: string[]) {
const getByKeyRequests = documentIds.map(billingDocument =>
billingDocumentApi.requestBuilder().getByKey(billingDocument)
);
const functionImportRequests = documentIds.map(billingDocument =>
getPdf({ billingDocument })
);

// Execute batch request combining multiple retrieve requests
const batchResponses = await batch(
...getByKeyRequests,
...functionImportRequests
);
}