Skip to content

Commit

Permalink
Merge pull request #2896 from microsoftgraph/2866-invoke-mggraphreque…
Browse files Browse the repository at this point in the history
…st-fails-to-return-a-number-of-resources

Updates ``Invoke-MgGraphRequest`` cmdlet to handle responses of ``text/plain`` content types.
  • Loading branch information
timayabi2020 authored Aug 12, 2024
2 parents 88cb77d + e612ca6 commit d53fd13
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ internal async Task ProcessResponseAsync(HttpResponseMessage response)
throw new ArgumentOutOfRangeException(nameof(OutputType));
}
break;
case RestReturnType.PlainText:
responseString = await response.Content.ReadAsStringAsync();
WriteObject(responseString);
break;
case RestReturnType.OctetStream:
if (OutputType == OutputType.HttpResponseMessage)
WriteObject(response);
Expand Down
4 changes: 4 additions & 0 deletions src/Authentication/Authentication/Helpers/ContentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ internal static RestReturnType CheckReturnType(this HttpResponseMessage response
rt = RestReturnType.Image;
else if (IsOctetStream(contentType))
rt = RestReturnType.OctetStream;
else if (IsPlainText(contentType))
rt = RestReturnType.PlainText;
return rt;
}

Expand Down Expand Up @@ -80,6 +82,8 @@ private static bool CheckIsOctetStream(string contentType)
return isOctetStream;
}

private static bool IsPlainText(string contentType) => contentType.Equals("text/plain", StringComparison.OrdinalIgnoreCase);

// used to split contentType arguments
private static readonly char[] ContentTypeParamSeparator = { ';' };

Expand Down
6 changes: 5 additions & 1 deletion src/Authentication/Authentication/Models/RestReturnType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public enum RestReturnType
/// <summary>
/// image/* (image/jpeg, image/png) return type
/// </summary>
Image = 4
Image = 4,
/// <summary>
/// text/plain return type
/// </summary>
PlainText = 5
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Describe 'Invoke-MgGraphRequest Command' -skip {
It 'Should not throw when -InferOutputFilePath is specified' {
{ Invoke-MgGraphRequest -OutputType PSObject -Uri "https://graph.microsoft.com/v1.0/reports/getTeamsUserActivityUserDetail(period='D7')" -InferOutputFileName } | Should -Not -Throw
}
It 'Should return plain text' {
{ Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/applications/`$count" } | Should -BeOfType [System.String]
}
}

Context 'Absolute and relative URIs' {
Expand Down

0 comments on commit d53fd13

Please sign in to comment.