none
json payload for teams graph api Invoke-RestMethod

    Question

  • Dear all,

    i try to create create the required json payload for creating a MS teams via graph api as described here:

    https://docs.microsoft.com/en-us/graph/api/team-put-teams?view=graph-rest-beta

    However i try to create the json it's always a little bit differently compared to the documented requirement and therefore the Invoke-RestMethod fail:

    Invoke-RestMethod : The remote server returned an error: (400) Bad Request.

    Does someone please have a powersholl code example how to create this json?

    I try:

    $membersettings = @()
    $membersettings += @{allowCreateUpdateChannels= "true"}
    $messagesettings=@()
    $messagesettings += @{allowUserEditMessages= "true"}
    $messagesettings += @{allowUserDeleteMessages= "true"}
    $funSettings = @()
    $funSettings += @{allowGiphy= "true"}
    $funSettings += @{giphyContentRating= "strict"}



    $body = New-Object -TypeName PSOBject -Property @{
    membersettings = $membersettings
    messagesettings = $messagesettings
    funSettings =$funSettings
    }

    ConvertTo-Json -InputObject $body

    that results in the json: (which fails):

    {
        "funSettings":  [
                            {
                                "allowGiphy":  "true"
                            },
                            {
                                "giphyContentRating":  "strict"
                            }
                        ],
        "messagesettings":  [
                                {
                                    "allowUserEditMessages":  "true"
                                },
                                {
                                    "allowUserDeleteMessages":  "true"
                                }
                            ],
        "membersettings":  [
                               {
                                   "allowCreateUpdateChannels":  "true"
                               }
                           ]
    }

    Thank you!

    Friday, January 11, 2019 4:13 PM

All replies

  • The result you posted is valid JSON object formatting.  What is your full Invoke-Restmethod call?
    Friday, January 11, 2019 4:58 PM
  • Try this:

    $membersettings = @{allowCreateUpdateChannels= "true"}
    $messagesettings = @{allowUserEditMessages= "true"; allowUserDeleteMessages= "true"}
    $funSettings = @{allowGiphy = "true"; giphyContentRating = "strict"}


    --- Rich Matheisen MCSE&I, Exchange Ex-MVP (16 years)


    Friday, January 11, 2019 7:55 PM