Skip to content

Bug: Invoke-GraphRequest fails with BadRequest for PUT Requests#486

Merged
georgend merged 1 commit intodevfrom
bug/putRequests
Dec 10, 2020
Merged

Bug: Invoke-GraphRequest fails with BadRequest for PUT Requests#486
georgend merged 1 commit intodevfrom
bug/putRequests

Conversation

@georgend
Copy link
Contributor

@georgend georgend commented Dec 9, 2020

Original Issue

else if (Method == GraphRequestMethod.POST)
{
GraphRequestSession.ContentHeaders.TryGetValue(HttpKnownHeaderNames.ContentType, out var contentType);
if (string.IsNullOrWhiteSpace(contentType))
{
// Assume application/json if not set by user
GraphRequestSession.ContentHeaders[HttpKnownHeaderNames.ContentType] =
CoreConstants.MimeTypeNames.Application.Json;
}

Line above only defaulted the Content-Type to application/json for POST only.

Fix
Set default Content-Type header to application/json when user has not specified -ContentType for PUT,POST,PATCH requests.

Fixes #483

… specified `-ContentType` for PUT,POST,PATCH.
@georgend georgend requested a review from peombwa December 9, 2020 23:37
@georgend georgend self-assigned this Dec 9, 2020
@georgend georgend added this to the 1.3.0 milestone Dec 9, 2020
@georgend georgend added the Bug label Dec 9, 2020
@georgend georgend merged commit 437e8bf into dev Dec 10, 2020
@peombwa peombwa deleted the bug/putRequests branch December 11, 2020 19:53
@peombwa peombwa mentioned this pull request Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extend Invoke-MgGraphRequest to handle PUT body / Unauthorized during build

2 participants