how to use AS-user in powershell
回答済みHi,
Anyone know how to use "AS-User" in powershell?
i tried to set it in header but it is giving me 403 error (using co-admin to get user's folder)
Anyone got sample?
-
,
You would have more luck posting this to the Developer Forum.
Bob
-
Hi Murtza,
Yes, i did both enable AS-User (by box) and checked on "Perform actions on behalf of users"
what error i got now is "Invoke-RestMethod : The remote server returned an error: (400) Bad Request"
this is my code below... anything i missed?
function GetUserfolder(){
$connecturl = Invoke-RestMethod "https://api.box.com/2.0/folders/0?fields=item_collection,name" -Method Get -Headers @{"Authorization" = "Bearer $accessToken" ; "as-user" = "userID"}
#echo $connecturl.entries.name
#echo $connecturl.entries.id}
*the token is working fine... i can view my own folder
-
Here is a project from GitHub that calls the Box API using Powershell. I don't think the as-user header feature is implemented in this project, but looking at some of the individual method implementations might be helpful.
-
Here is a working sample of a function to create a folder with as-user:
function New-BoxFolder($token, $foldername, $parentfolderid, $asuser) { #if no parentfolderid, set to 0... create at the root $uri = "https://api.box.com/2.0/folders" $headers = @{} if($asuser) { $headers.Add("Authorization","Bearer $token") $headers.Add("As-User","$asuser") } else { $headers.Add("Authorization","Bearer $token") } if(!$parentfolderid){$parentfolderid = "0"} $json = '{"name": "' + $foldername + '", "parent": {"id": "'+ $parentFolderID + '"}}' $return = Invoke-RestMethod -Uri $uri -Method Post -Headers $headers -Body $json -ContentType "application/x-www-form-urlencoded" $return } New-BoxFolder -token $token -name "Test Folder" -asuser 123456
サインインしてコメントを残してください。
コメント
8件のコメント