Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-MSGraphRequest not converting content correctly. #54

Open
stephenc01 opened this issue Jul 27, 2019 · 5 comments
Open

Invoke-MSGraphRequest not converting content correctly. #54

stephenc01 opened this issue Jul 27, 2019 · 5 comments

Comments

@stephenc01
Copy link

Hey,

Its my understanding that Content will accept, Hash, Object, or a String.

The command i am using is:
Invoke-MSGraphRequest -Url $URL -HttpMethod PATCH -Content $IOSF -Debug -Verbose

If i pass a HASH i get this(Not Complete)
{"contentFilterSettings":{"CliXml":"<Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/powershell/2004/04\">\r\n <Obj RefId="0">\r\n <TN RefId="0">\r\n
System.Management.Automation.PSCustomObject\r\n

If I pass an object, the body is empty
$IOSF = $IOSF | ConvertTo-Json | ConvertFrom-Json ##Convert hash to object

If i pass a string(Not Complete)
$IOSF = $IOSF | ConvertTo-Json
"{\r\n "contentFilterSettings": {\r\n "@odata.type": "#microsoft.graph.iosWebContentFilterAutoFilter",\r\n
"allowedUrls": [\r\n\r\n ],\r\n "blockedUrls": [\r\n
"https://facebook.com",\r\n "http://facebook.com",\r\n
"https://instagram.com",\r\n "http://instagram.com",\r\n
"https://mail.google.com",\r\n "http://mail.google.com",\r\n
"https://twitter.com",\r\n

How i was able to get it to work
$($($IOSF | ConvertTo-Json) -replace "rn","" -replace " ","")

PS Version: 5.1.17763.503
Module Version: 6.1902.1.10

@cconrado
Copy link

cconrado commented Apr 1, 2020

happening to me too

@davefalkus
Copy link
Collaborator

davefalkus commented Apr 1, 2020

@cconrado if your input is in json format try this i.e. add ".toString() to the Content, it should work:

$IOSF = $IOSF | ConvertTo-Json

Invoke-MSGraphRequest -Url $URL -HttpMethod PATCH -Content $IOSF.toString()

@cconrado
Copy link

cconrado commented Apr 1, 2020

@davefalkus I got it to working using this

$json = @"
{
scriptContent: "$B64File",
description: "Sample"
}
"@

I didn't need to convert.

@davefalkus
Copy link
Collaborator

@cconrado if you declare the json as you have your correct you don't need to convert it to string, but if you have a PS object which you convert to json, then the carriage return and new line /r/n are added which the commandlet can't parse, so the tostring() can be used to work around it.

@cconrado
Copy link

cconrado commented Apr 2, 2020

@davefalkus good tip thanks for that. Learning more everyday :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants