How to use the @microsoft/microsoft-graph-client.BatchRequestContent function in @microsoft/microsoft-graph-client

To help you get started, we’ve selected a few @microsoft/microsoft-graph-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoftgraph / microsoft-graph-toolkit / src / utils / Batch.ts View on Github external
public async execute(): Promise {
    const responses = {};
    if (!this.requests.size) {
      return responses;
    }
    const batchRequestContent = new BatchRequestContent();
    for (const request of this.requests) {
      batchRequestContent.addRequest({
        id: request[0],
        request: new Request(Batch.baseUrl + request[1].resource, {
          method: request[1].method
        })
      });
    }
    let batchRequest = this.client.api('$batch').version('beta');
    if (this.scopes.length) {
      batchRequest = batchRequest.middlewareOptions(prepScopes(...this.scopes));
    }
    const batchResponse = await batchRequest.post(await batchRequestContent.getContent());
    for (const response of batchResponse.responses) {
      if (response.status !== 200) {
        response[response.id] = null;