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

Box: Get a Service Account Token with Client Credentials

See more Box Examples

Obtain a Box service-account token using the client credentials grant. Configure and authorize a Server app first. Load credentials from protected application configuration; do not ship a client secret in a public client.

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

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

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

success = 0

set curl = Server.CreateObject("Chilkat.HttpCurl")
curl.SetVar "client_id","BOX_CLIENT_ID"
curl.SetVar "client_secret","BOX_CLIENT_SECRET"
curl.SetVar "enterprise_id","BOX_ENTERPRISE_ID"
'  enterprise identifies the app's service account. This is not an admin-user token.
curl.ClearTargetOutput "*"
curl.ClearVar "access_token"
curl.AddTargetOutput "access_token","access_token"
success = curl.DoYourThing("curl -X POST ""https://api.box.com/oauth2/token"" --data-urlencode ""grant_type=client_credentials"" --data-urlencode ""client_id={{client_id}}"" --data-urlencode ""client_secret={{client_secret}}"" --data-urlencode ""box_subject_type=enterprise"" --data-urlencode ""box_subject_id={{enterprise_id}}""")
If ((success <> 1) Or (curl.StatusCode <> 200)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Box request failed. HTTP status: " & curl.StatusCode) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "Failure reason: " & curl.FailReason) & "</pre>"
    Response.End
End If

If (curl.VarDefined("!") <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Expected response fields are missing.") & "</pre>"
    Response.End
End If

'  Keep this token in protected application memory; reacquire it when it expires.
'  Do not print tokens or the complete token response.
Response.Write "<pre>" & Server.HTMLEncode( "Service-account access token obtained.") & "</pre>"
curl.ClearTargetOutput "*"
set authorizedCommand1 = Server.CreateObject("Chilkat.StringBuilder")
success = authorizedCommand1.SetString("curl -X GET ""https://api.box.com/2.0/users/me?fields=id,name,login"" -H ""Authorization: Bearer {{access_token}}""")
headerReplacement1 = authorizedCommand1.Replace("{{access_token}}",curl.GetVar("access_token"))
success = curl.DoYourThing(authorizedCommand1.GetAsString())
If ((success <> 1) Or (curl.StatusCode <> 200)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Box request failed. HTTP status: " & curl.StatusCode) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "Failure reason: " & curl.FailReason) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( curl.ResponseBodyStr) & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( curl.ResponseBodyStr) & "</pre>"

%>
</body>
</html>