Visual FoxPro Requires Chilkat v11.7.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loCurl
LOCAL loSetupCommand
LOCAL lnSetupReplacements
LOCAL lcFolderName
LOCAL lcFileName
LOCAL loQueryText
LOCAL loSetupPlan
LOCAL loAuthorizedCommand1
LOCAL lnHeaderReplacement1
lnSuccess = 0
* Requires Chilkat 11.7.0 or later and a previously unlocked Chilkat bundle.
* See Global Unlock Sample.
* Guide: Box API Guide.
lnSuccess = 0
* 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.
loCurl = CreateObject('Chilkat.HttpCurl')
loCurl.SetVar("access_token","BOX_ACCESS_TOKEN")
loSetupCommand = CreateObject('Chilkat.StringBuilder')
* searchFolder: Box searches names; quotes request a phrase match.
loSetupCommand.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"')
lnSetupReplacements = loSetupCommand.Replace("ACCESS_TOKEN",loCurl.GetVar("access_token"))
lnSuccess = loCurl.AddFunction("searchFolder",loSetupCommand.GetAsString())
IF (lnSuccess <> 1) THEN
? loCurl.LastErrorText
RELEASE loCurl
RELEASE loSetupCommand
CANCEL
ENDIF
* Deferred selection: folder_name need not be set during setup.
lnSuccess = loCurl.AddOutput2("searchFolder","entries","name","{{folder_name}}",1,"id","folder_id")
IF (lnSuccess <> 1) THEN
? loCurl.LastErrorText
RELEASE loCurl
RELEASE loSetupCommand
CANCEL
ENDIF
lnSuccess = loCurl.AddOutput2("searchFolder","entries","name","{{folder_name}}",1,"name","folder_result_name")
IF (lnSuccess <> 1) THEN
? loCurl.LastErrorText
RELEASE loCurl
RELEASE loSetupCommand
CANCEL
ENDIF
lnSuccess = loCurl.AddOutput2("searchFolder","entries","name","{{folder_name}}",1,"parent.id","folder_parent_id")
IF (lnSuccess <> 1) THEN
? loCurl.LastErrorText
RELEASE loCurl
RELEASE loSetupCommand
CANCEL
ENDIF
lnSuccess = loCurl.AddOutput("searchFolder","total_count","folder_search_count")
IF (lnSuccess <> 1) THEN
? loCurl.LastErrorText
RELEASE loCurl
RELEASE loSetupCommand
CANCEL
ENDIF
* searchFile: Box searches names; quotes request a phrase match.
loSetupCommand.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"')
lnSetupReplacements = loSetupCommand.Replace("ACCESS_TOKEN",loCurl.GetVar("access_token"))
lnSuccess = loCurl.AddFunction("searchFile",loSetupCommand.GetAsString())
IF (lnSuccess <> 1) THEN
? loCurl.LastErrorText
RELEASE loCurl
RELEASE loSetupCommand
CANCEL
ENDIF
* Deferred selection: file_name need not be set during setup.
lnSuccess = loCurl.AddOutput2("searchFile","entries","name","{{file_name}}",1,"id","file_id")
IF (lnSuccess <> 1) THEN
? loCurl.LastErrorText
RELEASE loCurl
RELEASE loSetupCommand
CANCEL
ENDIF
lnSuccess = loCurl.AddOutput2("searchFile","entries","name","{{file_name}}",1,"name","file_result_name")
IF (lnSuccess <> 1) THEN
? loCurl.LastErrorText
RELEASE loCurl
RELEASE loSetupCommand
CANCEL
ENDIF
lnSuccess = loCurl.AddOutput2("searchFile","entries","name","{{file_name}}",1,"parent.id","file_parent_id")
IF (lnSuccess <> 1) THEN
? loCurl.LastErrorText
RELEASE loCurl
RELEASE loSetupCommand
CANCEL
ENDIF
lnSuccess = loCurl.AddOutput("searchFile","total_count","file_search_count")
IF (lnSuccess <> 1) THEN
? loCurl.LastErrorText
RELEASE loCurl
RELEASE loSetupCommand
CANCEL
ENDIF
* 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.
lcFolderName = "images"
lcFileName = "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.
loQueryText = CreateObject('Chilkat.StringBuilder')
loQueryText.SetString('"')
loQueryText.Append(lcFolderName)
loQueryText.Append('"')
loCurl.SetVar("folder_query",loQueryText.GetEncoded("url","utf-8"))
loQueryText.SetString('"')
loQueryText.Append(lcFileName)
loQueryText.Append('"')
loCurl.SetVar("file_query",loQueryText.GetEncoded("url","utf-8"))
IF (loCurl.GetVar("folder_name") <> lcFolderName) THEN
loCurl.ClearVar("folder_id")
loCurl.ClearVar("folder_result_name")
loCurl.ClearVar("folder_parent_id")
loCurl.ClearVar("folder_search_count")
loCurl.ClearVar("file_id")
loCurl.ClearVar("file_result_name")
loCurl.ClearVar("file_parent_id")
loCurl.ClearVar("file_search_count")
loCurl.SetVar("folder_name",lcFolderName)
ENDIF
IF (loCurl.GetVar("file_name") <> lcFileName) THEN
loCurl.ClearVar("file_id")
loCurl.ClearVar("file_result_name")
loCurl.ClearVar("file_parent_id")
loCurl.ClearVar("file_search_count")
loCurl.SetVar("file_name",lcFileName)
ENDIF
* 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.
loSetupPlan = CreateObject('Chilkat.JsonObject')
loSetupPlan.EmitCompact = 0
loAuthorizedCommand1 = CreateObject('Chilkat.StringBuilder')
loAuthorizedCommand1.SetString('curl -X GET "https://api.box.com/2.0/files/{{file_id}}/content" -H "Authorization: Bearer {{access_token}}" -L')
lnHeaderReplacement1 = loAuthorizedCommand1.Replace("{{access_token}}",loCurl.GetVar("access_token"))
lnSuccess = loCurl.ExaminePlan(loAuthorizedCommand1.GetAsString(),loSetupPlan)
IF (lnSuccess <> 1) THEN
? loCurl.LastErrorText
RELEASE loCurl
RELEASE loSetupCommand
RELEASE loQueryText
RELEASE loSetupPlan
RELEASE loAuthorizedCommand1
CANCEL
ENDIF
? loSetupPlan.Emit()
? "Keep this HttpCurl object for the search-based download operation."
RELEASE loCurl
RELEASE loSetupCommand
RELEASE loQueryText
RELEASE loSetupPlan
RELEASE loAuthorizedCommand1