2

I'm calling a Microsoft graph API to create a team. The response is a 202 with a Location header where I can get an async operation details.

How to get a response headers using @microsoft/microsoft-graph-client module?

A similar post using C# doesn't apply here. This one also.

Here is my code with an attempt to get a raw response:

  const client = Client.init({
    authProvider: (done: any) => {
      done(null, accessToken);
    },
  });

  const response = client
    .api(`/teams`)
    .post(team, (error, response, responseRaw) => {
      console.log(error); // null
      console.log(response); // <empty string>
      console.log(responseRaw); // undefined
    });
zolv
  • 1,720
  • 2
  • 19
  • 36

1 Answers1

5

To get the raw response set the responseType of a request to ResponseType.RAW

const response = client
    .api(`/teams`)
    .responseType(ResponseType.RAW)
    .post(team), (error, responseRaw) => {
      console.log(error);
      console.log(responseRaw); // responseRaw.status
    });

Documentation

Then You can get a Location header like this:

const location = response.headers.get('Location');
zolv
  • 1,720
  • 2
  • 19
  • 36
user2250152
  • 14,658
  • 4
  • 33
  • 57