JavaScript Requires Chilkat v11.5.0+
JavaScript
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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
// Requires Chilkat 11.5.0 or later and a previously unlocked Chilkat bundle.
// See Global Unlock Sample.
// Guide: Box API Guide.
success = false;
// 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.
var curl = new CkHttpCurl();
curl.SetVar("access_token","BOX_ACCESS_TOKEN");
curl.ClearTargetOutput("*");
var authorizedCommand1 = new CkStringBuilder();
authorizedCommand1.SetString("curl -X GET \"https://api.box.com/2.0/users/me?fields=id,name,login\" -H \"Authorization: Bearer {{access_token}}\"");
var headerReplacement1 = authorizedCommand1.Replace("{{access_token}}",curl.GetVar("access_token"));
success = curl.DoYourThing(authorizedCommand1.GetAsString());
if ((success !== true) || (curl.StatusCode !== 200)) {
console.log("Box request failed. HTTP status: " + curl.StatusCode);
console.log("Failure reason: " + curl.FailReason);
console.log(curl.ResponseBodyStr);
return;
}
console.log(curl.ResponseBodyStr);