Skip to content

Commit d53fd13

Browse files
authored
Merge pull request #2896 from microsoftgraph/2866-invoke-mggraphrequest-fails-to-return-a-number-of-resources
Updates ``Invoke-MgGraphRequest`` cmdlet to handle responses of ``text/plain`` content types.
2 parents 88cb77d + e612ca6 commit d53fd13

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

src/Authentication/Authentication/Cmdlets/InvokeMgGraphRequest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ internal async Task ProcessResponseAsync(HttpResponseMessage response)
453453
throw new ArgumentOutOfRangeException(nameof(OutputType));
454454
}
455455
break;
456+
case RestReturnType.PlainText:
457+
responseString = await response.Content.ReadAsStringAsync();
458+
WriteObject(responseString);
459+
break;
456460
case RestReturnType.OctetStream:
457461
if (OutputType == OutputType.HttpResponseMessage)
458462
WriteObject(response);

src/Authentication/Authentication/Helpers/ContentHelper.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ internal static RestReturnType CheckReturnType(this HttpResponseMessage response
2929
rt = RestReturnType.Image;
3030
else if (IsOctetStream(contentType))
3131
rt = RestReturnType.OctetStream;
32+
else if (IsPlainText(contentType))
33+
rt = RestReturnType.PlainText;
3234
return rt;
3335
}
3436

@@ -80,6 +82,8 @@ private static bool CheckIsOctetStream(string contentType)
8082
return isOctetStream;
8183
}
8284

85+
private static bool IsPlainText(string contentType) => contentType.Equals("text/plain", StringComparison.OrdinalIgnoreCase);
86+
8387
// used to split contentType arguments
8488
private static readonly char[] ContentTypeParamSeparator = { ';' };
8589

src/Authentication/Authentication/Models/RestReturnType.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public enum RestReturnType
2424
/// <summary>
2525
/// image/* (image/jpeg, image/png) return type
2626
/// </summary>
27-
Image = 4
27+
Image = 4,
28+
/// <summary>
29+
/// text/plain return type
30+
/// </summary>
31+
PlainText = 5
2832
}
2933
}

src/Authentication/Authentication/test/Invoke-MgGraphRequest.Tests.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ Describe 'Invoke-MgGraphRequest Command' -skip {
5454
It 'Should not throw when -InferOutputFilePath is specified' {
5555
{ Invoke-MgGraphRequest -OutputType PSObject -Uri "https://graph.microsoft.com/v1.0/reports/getTeamsUserActivityUserDetail(period='D7')" -InferOutputFileName } | Should -Not -Throw
5656
}
57+
It 'Should return plain text' {
58+
{ Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/v1.0/applications/`$count" } | Should -BeOfType [System.String]
59+
}
5760
}
5861

5962
Context 'Absolute and relative URIs' {

0 commit comments

Comments
 (0)