Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v11.5.0+

Box: Identify the User Behind an Access Token

See more Box Examples

Identify the account whose permissions and root folder the token uses. Start here when an app cannot see files visible in a personal Box account.

See the Box API guide for setup and the complete workflow.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Curl
oleobject loo_AuthorizedCommand1
long li_HeaderReplacement1

li_Success = 0

//  Requires Chilkat 11.5.0 or later and a previously unlocked Chilkat bundle.
//  See Global Unlock Sample.
//  Guide: Box API Guide.

li_Success = 0

//  Supply an unexpired token obtained with one of the Box authentication examples.
//  A token represents a particular user or service account. IDs must be accessible to it.
loo_Curl = create oleobject
li_rc = loo_Curl.ConnectToNewObject("Chilkat.HttpCurl")
if li_rc < 0 then
    destroy loo_Curl
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Curl.SetVar("access_token","BOX_ACCESS_TOKEN")

loo_Curl.ClearTargetOutput("*")
loo_AuthorizedCommand1 = create oleobject
li_rc = loo_AuthorizedCommand1.ConnectToNewObject("Chilkat.StringBuilder")

loo_AuthorizedCommand1.SetString("curl -X GET ~"https://api.box.com/2.0/users/me?fields=id,name,login~" -H ~"Authorization: Bearer {{access_token}}~"")
li_HeaderReplacement1 = loo_AuthorizedCommand1.Replace("{{access_token}}",loo_Curl.GetVar("access_token"))
li_Success = loo_Curl.DoYourThing(loo_AuthorizedCommand1.GetAsString())
if (li_Success <> 1) OR (loo_Curl.StatusCode <> 200) then
    Write-Debug "Box request failed. HTTP status: " + string(loo_Curl.StatusCode)
    Write-Debug "Failure reason: " + string(loo_Curl.FailReason)
    Write-Debug loo_Curl.ResponseBodyStr
    destroy loo_Curl
    destroy loo_AuthorizedCommand1
    return
end if

Write-Debug loo_Curl.ResponseBodyStr


destroy loo_Curl
destroy loo_AuthorizedCommand1