microsoft-graph-toolkit icon indicating copy to clipboard operation
microsoft-graph-toolkit copied to clipboard

Support headers in mgt-get

Open beth-panx opened this issue 5 years ago • 8 comments

Proposal: Add support for headers in mgt-get

Description

To support api's such as List users beta

Rationale

There are times graph api supports passing of additional headers. Right now mgt-get doesn't have this as an option. Developer will need to overwrite the graph client to achieve this.

Preferred Solution

Add header attribute or property

beth-panx avatar Sep 22 '20 23:09 beth-panx

Hello beth-panx, thank you for opening an issue with us!

I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌

ghost avatar Sep 22 '20 23:09 ghost

@beth-panx @shweaver-MSFT I would like to use mgt-get to get the manager chain up to the root level https://docs.microsoft.com/en-us/graph/api/user-list-manager?view=graph-rest-1.0&tabs=http#example-2-get-manager-chain-up-to-the-root-level, and that requires ConsistencyLevel: eventual be sent in the request headers. This is a feature I want to see!

MrCodeWeaver avatar Jan 19 '21 14:01 MrCodeWeaver

Agree, this features would make the component much better. What do you think about adding the header property like so:

<mgt-get resource="bla" headers="key:value, key:value" />

I believe this should be fairly straightforward to implement?

nmetulev avatar Jan 19 '21 22:01 nmetulev

That would be fine!

MrCodeWeaver avatar Jan 20 '21 12:01 MrCodeWeaver

Another reference: https://stackoverflow.com/questions/67766620/microsoft-graph-toolkit-mgt-how-do-i-modify-add-request-headers-for-the-mgt

nmetulev avatar Jun 01 '21 16:06 nmetulev

I am not an expert in this, so apologies if this isn't what you are asking about. I found that if you are using the providers built into the toolkit, you can simply do something like this to add request headers to all mgt-get component requests without having to re-initialize the graph client and re-create the middleware chain:

Providers.globalProvider.graph.client.config.fetchOptions = {headers: {'Prefer': 'IdType="ImmutableId"'}}

(obviously change the request headers to whatever you want)

I should also note, you can even do this after the provider has been initialized. Any subsequent calls after you set the fetchOptions will include the headers in the request.

Also, if you are loading the provider via a HTML provider component tag like this for example: <script src="https://unpkg.com/@microsoft/mgt@2/dist/bundle/mgt-loader.js"></script> <mgt-msal2-provider client-id="YOUR_CLIENT_ID"></mgt-msal2-provider>

You can access the globalProvider object like this:

mgt.Providers.globalProvider.graph.client.config.fetchOptions = {headers: {'Prefer': 'IdType="ImmutableId"'}}

anthem89 avatar Feb 18 '23 19:02 anthem89

You are absolutely right. This works, but will impact all future calls. I think a more sustainable solution would be a way to provide headers on the component itself, but it's a great workaround while we figure out a good way to bring this feature.

FYI @gavinbarron

sebastienlevert avatar Mar 03 '23 16:03 sebastienlevert

Related to #1723

sebastienlevert avatar Jan 30 '24 04:01 sebastienlevert