Put Box CLI result into Powershell variable

回答済み
新規投稿

コメント

2件のコメント

  • 正式なコメント
    Alex Novotny

    Hey Scott! 

    Thanks for the question. 

    This is happening because Box is returning a 204. There are a couple things you can do! 

    If you want to see the 204 response code - you can use this syntax in a powershell script vs calling the CLI within a powershell script. 

    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("Authorization", "Bearer <token>")
    try {
    $response = Invoke-RestMethod 'https://api.box.com/2.0/collaborations/<collab_id>' -Method 'DELETE' -Headers $headers
    } catch {
    # Dig into the exception to get the Response details.
    # Note that value__ is not a typo.
    Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
    Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
    }

    If you want to use the CLI in the command still, you could do something like this:

    $id="<collab_id>"
    $collabResponse = "$(box collaborations:delete $id 2>&1)" | Tee-Object -Variable collabResponse
    Write-Host "Response: $collabResponse"

    Thanks, 

    Alex, Box Developer Advocate

    コメントアクション パーマリンク
  • Scott Best

    That's perfect!  Just what I needed to know.  Thank you!

    0
    コメントアクション パーマリンク

サインインしてコメントを残してください。