Xojo Plugin Requires Chilkat v11.7.0+
Xojo Plugin
Box: Set Up Reusable HttpCurl Requests and Outputs
See more Box Examples
Register searchFolder and searchFile once, with deferred folder_name and file_name output rules. This review example resolves a folder directly under root and a file directly inside it. The download operation requires exactly one search result at each step and validates exact names and parent IDs. Registration and ExaminePlan send no requests. Other Box examples still have their existing standalone setups.
See the Box API guide for setup and the complete workflow.
Chilkat Xojo Plugin Downloads
Dim success As Boolean
success = False
// Requires Chilkat 11.7.0 or later and a previously unlocked Chilkat bundle.
// See Global Unlock Sample.
// Guide: Box API Guide.
success = False
// BEGIN ONE-TIME SETUP
// Requires Chilkat 11.7.0. Registration sends no requests.
// Run this once and keep the SAME HttpCurl object for later downloads.
// This focused setup searches for a root folder and a file directly inside it.
Dim curl As New Chilkat.HttpCurl
curl.SetVar "access_token","BOX_ACCESS_TOKEN"
Dim setupCommand As New Chilkat.StringBuilder
Dim setupReplacements As Int32
// searchFolder: Box searches names; quotes request a phrase match.
success = setupCommand.SetString("curl -X GET ""https://api.box.com/2.0/search?query={{folder_query}}&type=folder&content_types=name&fields=id,type,name,parent&limit=2"" -H ""Authorization: Bearer ACCESS_TOKEN""")
setupReplacements = setupCommand.Replace("ACCESS_TOKEN",curl.GetVar("access_token"))
success = curl.AddFunction("searchFolder",setupCommand.GetAsString())
If (success <> True) Then
System.DebugLog(curl.LastErrorText)
Return
End If
// Deferred selection: folder_name need not be set during setup.
success = curl.AddOutput2("searchFolder","entries","name","{{folder_name}}",True,"id","folder_id")
If (success <> True) Then
System.DebugLog(curl.LastErrorText)
Return
End If
success = curl.AddOutput2("searchFolder","entries","name","{{folder_name}}",True,"name","folder_result_name")
If (success <> True) Then
System.DebugLog(curl.LastErrorText)
Return
End If
success = curl.AddOutput2("searchFolder","entries","name","{{folder_name}}",True,"parent.id","folder_parent_id")
If (success <> True) Then
System.DebugLog(curl.LastErrorText)
Return
End If
success = curl.AddOutput("searchFolder","total_count","folder_search_count")
If (success <> True) Then
System.DebugLog(curl.LastErrorText)
Return
End If
// searchFile: Box searches names; quotes request a phrase match.
success = setupCommand.SetString("curl -X GET ""https://api.box.com/2.0/search?query={{file_query}}&type=file&content_types=name&fields=id,type,name,parent&limit=2&ancestor_folder_ids={{folder_id}}"" -H ""Authorization: Bearer ACCESS_TOKEN""")
setupReplacements = setupCommand.Replace("ACCESS_TOKEN",curl.GetVar("access_token"))
success = curl.AddFunction("searchFile",setupCommand.GetAsString())
If (success <> True) Then
System.DebugLog(curl.LastErrorText)
Return
End If
// Deferred selection: file_name need not be set during setup.
success = curl.AddOutput2("searchFile","entries","name","{{file_name}}",True,"id","file_id")
If (success <> True) Then
System.DebugLog(curl.LastErrorText)
Return
End If
success = curl.AddOutput2("searchFile","entries","name","{{file_name}}",True,"name","file_result_name")
If (success <> True) Then
System.DebugLog(curl.LastErrorText)
Return
End If
success = curl.AddOutput2("searchFile","entries","name","{{file_name}}",True,"parent.id","file_parent_id")
If (success <> True) Then
System.DebugLog(curl.LastErrorText)
Return
End If
success = curl.AddOutput("searchFile","total_count","file_search_count")
If (success <> True) Then
System.DebugLog(curl.LastErrorText)
Return
End If
// END ONE-TIME SETUP
// Search is indexed: newly uploaded/renamed items may not appear immediately.
// Search matches phrases, not exact strings, and ancestor filtering includes
// subfolders. The operation validates counts, exact names, and immediate parents.
// limit=2 is enough to demonstrate an ambiguous search; total_count covers all
// results, not just this page. This introductory example requires exactly one
// search result at each step and does not select among multiple candidates.
// BEGIN OPERATION -- use the previously configured object.
// Human-readable inputs. No resource IDs are supplied by the caller.
Dim folderName As String
folderName = "images"
Dim fileName As String
fileName = "penguins.jpg"
// Encode the quoted search queries separately from the literal output filters.
// In this build, URL variable substitution does not encode '&' in a name.
Dim queryText As New Chilkat.StringBuilder
success = queryText.SetString("""")
success = queryText.Append(folderName)
success = queryText.Append("""")
curl.SetVar "folder_query",queryText.GetEncoded("url","utf-8")
success = queryText.SetString("""")
success = queryText.Append(fileName)
success = queryText.Append("""")
curl.SetVar "file_query",queryText.GetEncoded("url","utf-8")
If (curl.GetVar("folder_name") <> folderName) Then
curl.ClearVar "folder_id"
curl.ClearVar "folder_result_name"
curl.ClearVar "folder_parent_id"
curl.ClearVar "folder_search_count"
curl.ClearVar "file_id"
curl.ClearVar "file_result_name"
curl.ClearVar "file_parent_id"
curl.ClearVar "file_search_count"
curl.SetVar "folder_name",folderName
End If
If (curl.GetVar("file_name") <> fileName) Then
curl.ClearVar "file_id"
curl.ClearVar "file_result_name"
curl.ClearVar "file_parent_id"
curl.ClearVar "file_search_count"
curl.SetVar "file_name",fileName
End If
// With unchanged names, cached IDs and validation fields can be reused.
// Clear the corresponding cached fields to refresh after a remote rename/move.
// Examine the plan without running any HTTP requests.
Dim setupPlan As New Chilkat.JsonObject
setupPlan.EmitCompact = False
Dim authorizedCommand1 As New Chilkat.StringBuilder
success = authorizedCommand1.SetString("curl -X GET ""https://api.box.com/2.0/files/{{file_id}}/content"" -H ""Authorization: Bearer {{access_token}}"" -L")
Dim headerReplacement1 As Int32
headerReplacement1 = authorizedCommand1.Replace("{{access_token}}",curl.GetVar("access_token"))
success = curl.ExaminePlan(authorizedCommand1.GetAsString(),setupPlan)
If (success <> True) Then
System.DebugLog(curl.LastErrorText)
Return
End If
System.DebugLog(setupPlan.Emit())
System.DebugLog("Keep this HttpCurl object for the search-based download operation.")