aofi
aofi

Reputation: 1

Making curl API calls with powershell

I'm having trouble getting specific API calls to work in powershell using Invoke-restmethod. Specifically passing the -d "\"\\RootFolder\New folder\"" variable. Example of the Curl API command for moving device groups:

curl -X PUT --header "Content-Type: application/json" --header "Accept: application/json" --header "Authorization: Bearer Very long token" -d "\"\\\\RootFolder\\New folder\"" "https://SOTIServer.com:443/MobiControl/api/devicegroups/%255C%255CRootfolder%255COld%2520folder%255CSourceFolder/path"

The Powershell call that I have so far, that doesn't work:

$folderX="SourceFolder"

function MoveDir ([string]$Name, [string]$Token)
{
    $Path = "%255C%255CRootfolder%255COld%2520folder%255C" + $folderX
    $body = "\\\\RootFolder\\New Folder"
    $body = $body | ConvertTo-Json
    $MCFQDN = "https://SOTIServer.com:443"

    $Header2 = @{}
    $Header2["Authorization"] = "Bearer " + $Token

    try
    {
        $response2 = Invoke-restmethod -Uri https://$MCFQDN/mobicontrol/api/devicegroups/$Path/path -ContentType "application/json" -Method PUT -Body $body -Headers $Header2
    }
    catch
    {
        $($_.Exception.Message)
    }
}

Upvotes: 0

Views: 302

Answers (0)

Related Questions