#Region - Timestamp ;2011-11-20 20:31:44 #EndRegion - Timestamp Global Const $REST_API_URL = "https://www.box.net/api/1.0/rest" ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getTicket() ; Description ...: Description ; Syntax ........: _BoxAPI_getTicket($sAPIKey, $sUserAgent) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns the string containing the ticket ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from ; calling this function. ; |2 - When no api_key parameter is provided. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923936/ApiFunction_get_ticket ; ================================================================================================= Func _BoxAPI_getTicket($sAPIKey, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "autoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_ticket" & _ "&api_key=" & $sAPIKey) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "wrong_input" SetError(2, 0, -1) Case "get_ticket_ok" Return __BoxAPI_stringBetween($oHTTP.ResponseText, "ticket") EndSwitch EndFunc ;==>_BoxAPI_getTicket ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getAuthToken() ; Description ...: This method is used in the authorization process. You should call this method ; after the user has authorized oneself on the Box partner authentication page. ; Pass the ticket that you get when calling the get_ticket method. ; Syntax ........: _BoxAPI_getAuthToken($sAPIKey, $sTicket, $sUserAgent) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sTicket - The ticket obtained from _BoxAPI_getTicket(). ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns a 2d array containing user informations. ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from ; calling this function. ; |2 - The user did not successfully authenticate on the page provided in the ; authentication process. ; |3 - Generic error for other invalid inputs. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923930/ApiFunction_get_auth_token ; ================================================================================================= Func _BoxAPI_getAuthToken($sAPIKey, $sTicket, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "autoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_auth_token" & _ "&api_key=" & $sAPIKey & _ "&ticket=" & $sTicket) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "get_auth_token_error" SetError(3, 0, -1) Case "get_auth_token_ok" Dim $aUser[8][2] = [["auth_token", __BoxAPI_stringBetween($oHTTP.ResponseText, "auth_token")], _ ["login", __BoxAPI_stringBetween($oHTTP.ResponseText, "login")], _ ["email", __BoxAPI_stringBetween($oHTTP.ResponseText, "email")], _ ["access_id", __BoxAPI_stringBetween($oHTTP.ResponseText, "access_id")], _ ["user_id", __BoxAPI_stringBetween($oHTTP.ResponseText, "user_id")], _ ["space_amount", __BoxAPI_stringBetween($oHTTP.ResponseText, "space_amount")], _ ["space_used", __BoxAPI_stringBetween($oHTTP.ResponseText, "space_used")], _ ["max_upload_size", __BoxAPI_stringBetween($oHTTP.ResponseText, "max_upload_size")]] Return $aUser EndSwitch EndFunc ;==>_BoxAPI_getAuthToken ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_logout() ; Description ...: This method is used to logout a user. ; Syntax ........: _BoxAPI_logout($sAPIKey, $sToken[, $sUserAgent = "AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Return 1 ; Failure ; |Return -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from ; calling this function. ; |2 - The user is already no longer logged into Box for your application. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923939/ApiFunction_logout ; ================================================================================================= Func _BoxAPI_logout($sAPIKey, $sToken, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=logout" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "logout_ok" Return 1 EndSwitch EndFunc ;==>_BoxAPI_logout ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_registerNewUser() ; Description ...: This method is used to register a new user with a free personal account. ; Syntax ........: _BoxAPI_registerNewUser($sAPIKey, $sEmail, $sPassword[, $sUserAgent = "AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sEmail - The login username for the user you intend to create. ; $sPassword - The login password for the user you intend to create. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns a 2d array containing user informations. ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from ; calling this function. ; |2 - The email adress provided is already registered by another user. ; |3 - The login provided is not a valid email address. ; |4 - Generic error warning for other errors. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923945/ApiFunction_register_new_user ; ================================================================================================= Func _BoxAPI_registerNewUser($sAPIKey, $sEmail, $sPassword, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=register_new_user" & _ "&api_key=" & $sAPIKey & _ "&login=" & _URIEncode($sEmail) & _ "&password=" & _URIEncode($sPassword)) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "email_already_registered" SetError(2, 0, -1) Case "email_invalid" SetError(3, 0, -1) Case "e_register" SetError(4, 0, -1) Case "successful_register" Dim $aUser[8][2] = [["auth_token", __BoxAPI_stringBetween($oHTTP.ResponseText, "auth_token")], _ ["login", __BoxAPI_stringBetween($oHTTP.ResponseText, "login")], _ ["email", __BoxAPI_stringBetween($oHTTP.ResponseText, "email")], _ ["access_id", __BoxAPI_stringBetween($oHTTP.ResponseText, "access_id")], _ ["user_id", __BoxAPI_stringBetween($oHTTP.ResponseText, "user_id")], _ ["space_amount", __BoxAPI_stringBetween($oHTTP.ResponseText, "space_amount")], _ ["space_used", __BoxAPI_stringBetween($oHTTP.ResponseText, "space_used")], _ ["max_upload_size", __BoxAPI_stringBetween($oHTTP.ResponseText, "max_upload_size")]] Return $aUser EndSwitch EndFunc ;==>_BoxAPI_registerNewUser ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_verifyRegistrationEmail() ; Description ...: This method is used to verify whether a user email is available, or already in use. ; Syntax ........: _BoxAPI_verifyRegistrationEmail($sAPIKey, $sEmail[, $sUserAgent = "AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sEmail - The login username of the user for which you would like to verify registration. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from ; calling this function. ; |2 - The email adress provided is already registered by another user. ; |3 - The login provided is not a valid email address. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923952/ApiFunction_verify_registration_email ; ================================================================================================= Func _BoxAPI_verifyRegistrationEmail($sAPIKey, $sEmail, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=verify_registration_email" & _ "&api_key=" & $sAPIKey & _ "&login=" & _URIEncode($sEmail)) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "email_already_registered" SetError(2, 0, -1) Case "email_invalid" SetError(3, 0, -1) Case "email_ok" Return 1 EndSwitch EndFunc ;==>_BoxAPI_verifyRegistrationEmail ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_downloadFile() ; Description ...: Downloads a file. ; Syntax ........: _BoxAPI_downloadFile($sToken, $iFileID, $sFile, $iOptions, $iBackground[, $sUserAgent="AutoIt"]) ; Parameters ....: $sToken - The authentication token for your service to connect to a user's ; $iFileID - The file to download. ; $sFile - @see InetGet() ; $iOptions - @see InetGet() ; $iBackground - @see InetGet() ; $sUserAgent - [optional] (default:"AutoIt") ; Author ........: i2c ; ================================================================================================= Func _BoxAPI_downloadFile($sToken, $iFileID, $sFile, $iOptions, $iBackground, $sUserAgent="AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" HttpSetUserAgent($sUserAgent) InetGet("https://www.box.net/api/1.0/download/" & $sToken & "/" & $iFileID, $sFile, $iOptions, $iBackground) EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_downloadVersion() ; Description ...: Downloads a file. ; Syntax ........: _BoxAPI_downloadFile($sToken, $iFileID, $sFile, $iOptions, $iBackground[, $sUserAgent="AutoIt"]) ; Parameters ....: $sToken - The authentication token for your service to connect to a user's ; $iFileID - The file to download. ; $iVersionID - The verson ID obtained by using _BoxAPI_getVersions() ; $sFile - @see InetGet() ; $iOptions - @see InetGet() ; $iBackground - @see InetGet() ; $sUserAgent - [optional] (default:"AutoIt") ; Author ........: i2c ; ================================================================================================= Func _BoxAPI_downloadVersion($sToken, $iFileID, $iVersionID, $sFile, $iOptions, $iBackground, $sUserAgent="AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" HttpSetUserAgent($sUserAgent) InetGet("https://www.box.net/api/1.0/download_version/" & $sToken & "/" & $iFileID & "/" & $iVersionID, $sFile, $iOptions, $iBackground) EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_uploadFile() ; Description ...: Uploads one or more files to your box. ; Syntax ........: _BoxAPI_uploadFile($sToken, $aFiles, $sFolderID, $aEmails[, $iCopy = 1[, $sUserAgent="AutoIt" ]]) ; Parameters ....: $sToken - The authentication token for your service to connect to a user's ; $aFiles - An Array of files to be uploaded ; $sFolderID - The folder ID to upload to. ; $aEmails - An array of email adresses to send notifications ; $iCopy - [optional] If a file already exists, save a copy of this file. Can be 0 or 1 (default:1) ; $sUserAgent - [optional] (default:"AutoIt" ) ; Return values .: Success ; |Returns an XML structure (not wellformed) ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function. ; |2 - The user is not logged into your application. Your authentication_token is not valid. ; |3 - Some of the files were not successfully uploaded. ; |4 - There is not enough space in this user's account to accommodate the new files. ; |5 - A file is too large to be uploaded to a user's account (Lite users have a 25 MB ; upload limit per file, premium users have a 1 GB limit per file) ; |6 - The user does not have uploading privileges for that particular folder. ; |7 - The specified folder_id is not valid. ; |8 - The name of the file contains invalid characters not accepted by Box.net. ; Author ........: i2c ; ================================================================================================= Func _BoxAPI_uploadFile($sToken, $aFiles, $sFolderID, $aEmails, $iCopy = 1, $sUserAgent="AutoIt" ) Local $sEmails, $sFiles If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $iCopy = Default Then $iCopy = 1 If IsArray($aEmails) Then For $i = 0 To UBound($aEmails)-1 If $aemails[$i] <> "" Then $sEmails &= "&emails[]=" $aEmails[$i] Next EndIf If IsArray($aFiles) Then For $i = 0 To UBound($aFiles)-1 If $aFiles[$i] <> "" Then $sFiles &= "&new_file" & $i+1 & "="$aFiles[$i] Next EndIf Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "https://upload.box.net/api/1.0/upload/" & $sToken & "/" & $sFolderID, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=upload_files" & _ $sFiles & _ "&message=" & $sMessage & _ "new_copy=" & $iCopy & _ $sEmails) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "wrong auth token" SetError(2, 0, -1) Case "upload_some_files_failed" SetError(3, 0, -1) Case "not_enough_free_space" SetError(4, 0, -1) Case "filesize_limit_exceeded" SetError(5, 0, -1) Case "access_denied" SetError(6, 0, -1) Case "wupload_wrong_folder_id" SetError(7, 0, -1) Case "upload_invalid_file_name" SetError(8, 0, -1) Case "upload_ok" Return $oHTTP.ResponseText EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: __BoxAPI_getAccountInfo() ; Description ...: This method is used to get the user's account information. ; Syntax ........: __BoxAPI_getAccountInfo($sAPIKey, $sToken[, $sUserAgent = "AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns a 2d array with user informations. ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function. ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923928/ApiFunction_get_account_info ; ================================================================================================= Func _BoxAPI_getAccountInfo($sAPIKey, $sToken, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_account_info" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "get_account_info_ok" Dim $aUser[7][2] = [["login", __BoxAPI_stringBetween($oHTTP.ResponseText, "login")], _ ["email", __BoxAPI_stringBetween($oHTTP.ResponseText, "email")], _ ["access_id", __BoxAPI_stringBetween($oHTTP.ResponseText, "access_id")], _ ["user_id", __BoxAPI_stringBetween($oHTTP.ResponseText, "user_id")], _ ["space_amount", __BoxAPI_stringBetween($oHTTP.ResponseText, "space_amount")], _ ["space_used", __BoxAPI_stringBetween($oHTTP.ResponseText, "space_used")], _ ["max_upload_size", __BoxAPI_stringBetween($oHTTP.ResponseText, "max_upload_size")]] Return $aUser EndSwitch EndFunc ;==>_BoxAPI_getAccountInfo ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getAccountTree() ; Description ...: This method is used to get a tree representing all of the user's files and ; folders. Usage of the optional 'onelevel' parameter is highly recommended ; as extremely large accounts involving substantial amounts of data may ; cause the request to time out if the entire tree is pulled. ; Syntax ........: _BoxAPI_getAccountTree($sAPIKey, $sToken, $iFolderID[, $iOption = 1[, $sUserAgent = "AutoIt"]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iFolderID - The ID of the root folder from which the tree begins. If this value is "0", ; the user's full account tree is returned. ; $iOption - [optional] Allows you to set additional, optional parameters: (default:1) ; |1 - make a tree of one level depth, so you will get only the files and folders ; stored in the folder of the folder_id you have provided. ; |2 - only include the folders in the user account tree, and ignore the files. ; |4 - display the full tree with a limited list of attributes to make for smaller, ; more efficient output (folders only contain the 'name' and 'id' attributes, ; and files will contain the 'name', 'id', 'created', and 'size' attributes) ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns an XML structure of the tree representing the folders and files from a user's particular folder ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923929/ApiFunction_get_account_tree ; ================================================================================================== Func _BoxAPI_getAccountTree($sAPIKey, $sToken, $iFolderID = 0, $iOption = 1, $sUserAgent = "AutoIt") Local $sTree, $aOptions[1] If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $iFolderID = Default Then $iFolderID = 0 If $iOption = Default Then $iOption = 1 Switch $iOption Case 1 $sOption = "¶ms[]=onelevel" Case 2 $sOption = "¶ms[]=nofiles" Case 3 $sOption = "¶ms[]=onelevel¶ms[]=nofiles" Case 4 $sOption = "¶ms[]=simple" Case 5 $sOption = "¶ms[]=onelevel¶ms[]=simple" Case 6 $sOption = "¶ms[]=nofiles¶ms[]=simple" Case 7 $sOption = "¶ms[]=onelevel¶ms[]=nofiles¶ms[]=simple" EndSwitch Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_account_tree" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&folder_id=" & $iFolderID & _ "¶ms[]=nozip" & $sOption) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_folder_id" SetError(3, 0, -1) Case "listing_ok" Return __BoxAPI_stringBetween($oHTTP.ResponseText, "tree") EndSwitch EndFunc ;==>_BoxAPI_getAccountTree ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_createFolder() ; Description ...: This method creates a new folder in a user's account. ; Syntax ........: _BoxAPI_createFolder($sAPIKey, $sToken, $sFolderID, $sName[, $iShare = 0[, $sUserAgent = "AutoIt"]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iFolderID - The folder_id in which the new folder will be created. ; $sName - The name of the folder when it will be created. ; $iShare - [optional] A binary parameter which can be set to 1 in order to allow the folder to be shared. (default:0) ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns a 2d array with folder informations ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The folder_id provided is not a valid folder_id for the user's account. ; |3 - A folder withthe same name already exists in that location. ; |4 - The user is not logged into your application. Your authentication_token is not valid. ; |5 - The name provided for the new folder contained invalid characters or too many characters. ; |6 - The user does not have the necessary permissions to perform the specified operation. ; Most likely the user is trying to create a folder within a collaborated folder, for ; which the user has view-only permission. ; |7 - A folder name was not properly provided. ; |8 - The folder name contained more than 100 characters, exceeding the folder name length limit. ; |9 - Another invalid input was provided. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923925/ApiFunction_create_folder ; ================================================================================================= Func _BoxAPI_createFolder($sAPIKey, $sToken, $iFolderID, $sName, $iShare = 0, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $iShare = Default Then $iShare = 0 Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=create_folder" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&parent_id=" & $iFolderID & _ "&name=" & _URIEncode($sName) & _ "&share=" & $iShare) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") ConsoleWrite($sStatus & @CRLF) Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "no_parent" SetError(2, 0, -1) Case "s_folder_exists" SetError(3, 0, -1) Case "not_logged_in" SetError(4, 0, -1) Case "invalid_folder_name" SetError(5, 0, -1) Case "e_no_access" SetError(6, 0, -1) Case "e_no_folder_name" SetError(7, 0, -1) Case "folder_name_too_big" SetError(8, 0, -1) Case "e_input_params" SetError(9, 0, -1) Case "create_ok" Dim $aFolder[9][2] = [["folder_id", __BoxAPI_stringBetween($oHTTP.ResponseText, "folder_id")], _ ["folder_name", __BoxAPI_stringBetween($oHTTP.ResponseText, "folder_name")], _ ["user_id", __BoxAPI_stringBetween($oHTTP.ResponseText, "user_id")], _ ["path", __BoxAPI_stringBetween($oHTTP.ResponseText, "path")], _ ["shared", __BoxAPI_stringBetween($oHTTP.ResponseText, "shared")], _ ["public_name", __BoxAPI_stringBetween($oHTTP.ResponseText, "public_name")], _ ["show_comments", __BoxAPI_stringBetween($oHTTP.ResponseText, "show_comments")], _ ["parent_folder_id", __BoxAPI_stringBetween($oHTTP.ResponseText, "parent_folder_id")], _ ["password", __BoxAPI_stringBetween($oHTTP.ResponseText, "password")]] Return $aFolder EndSwitch EndFunc ;==>_BoxAPI_createFolder ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_moveItem() ; Description ...: This method moves a file or folder into another folder. ; Syntax ........: _BoxAPI_move($sAPIKey, $sToken[, $sTarget = "file", $iTargetID, $iDestination[, $sUserAgent = "AutoIt"]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $sTarget - [optional] The type of item to be moved. Can be 'file' or 'folder'. (default:"file") ; $iTargetID - The id of the item you wish to move. If the target is a folder, this will be the folder_id. ; If the target is a file, this will be the file_id. ; $iDestination - The folder_id of the folder to which you will move the item. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; ================================================================================================= Func _BoxAPI_moveItem($sAPIKey, $sToken, $iTargetID, $iDestID, $sTarget = "file", $sUserAgent = "AutoIt") If $sTarget = Default Then $sTarget = "file" If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=move" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sTarget & _ "&target=" & $sTarget & _ "&target_id=" & $iTargetID & _ "&destination_id=" & $iDestID) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_move_node" SetError(3, 0, -1) Case "s_move_node" Return 1 EndSwitch EndFunc ;==>_BoxAPI_moveItem ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_copyItem() ; Description ...: This method copies a file into another folder. ; Syntax ........: _BoxAPI_copyItem($sAPIKey, $sToken, $iTargetID, $iDestID[, $sUserAgent = "AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTargetID - The id of the file you wish to copy. ; $iDestID - The folder_id of the folder to which you will copy the item. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Return 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - The file cannot be copied because a file of the same name already exists in that folder. ; |4 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923924/APIFunction_copy ; ================================================================================================= Func _BoxAPI_copyItem($sAPIKey, $sToken, $iTargetID, $iDestID, $sUserAgent = "AutoIt") Local $sTarget = "file" If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=copy" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target=" & $sTarget & _ "&target_id=" & $iTargetID & _ "&destination_id=" & $iDestID) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") ConsoleWrite($sStatus & @CRLF) Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_filename_in_use" SetError(3, 0, -1) Case "e_copy_node" SetError(4, 0, -1) Case " s_copy_node" Return 1 EndSwitch EndFunc ;==>_BoxAPI_copyItem ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_renameItem() ; Description ...: This method renames a file or folder. ; Syntax ........: _BoxAPI_renameItem($sAPIKey, $sToken[, $sTarget = "file", $iTargetID, $sName[, $sUserAgent = "AutoIt"]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTarget - [optional] The type of item to be renamed. This can be set to 0 = 'file' or 1 = 'folder'. (default:"file") ; $iTargetID - The id of the item you wish to rename. If the target is a folder, this will be the folder_id. ; If the target is a file, this will be the file_id. ; $sName - The new name to be applied to the item. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - The file cannot be copied because a file of the same name already exists in that folder. ; |4 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923947/ApiFunction_rename ; ================================================================================================= Func _BoxAPI_renameItem($sAPIKey, $sToken, $iTargetID, $sName, $iTarget = 0, $sUserAgent = "AutoIt") Local $sTarget If $iTarget = Default Then $iTarget = 0 If $sUserAgent = Default Then $sUserAgent = "AutoIt" Switch $iTarget Case 0 $sTarget = "file" Case 1 $sTarget = "folder" Case Else SetError(4, 0, -1) EndSwitch Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=rename" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sTarget & _ "&target=" & $sTarget & _ "&target_id=" & $iTargetID & _ "&new_name=" & $sName) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_filename_in_use" SetError(3, 0, -1) Case "e_rename_node" SetError(4, 0, -1) Case "s_rename_node" Return 1 EndSwitch EndFunc ;==>_BoxAPI_renameItem ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_deleteItem() ; Description ...: This method deletes a file or folder. ; Syntax ........: _BoxAPI_deleteItem($sAPIKey, $sToken[, $sTarget = "file", $iTargetID[, $sUserAgent = "AutoIt"]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTarget - [optional] The type of item to be deleted. This can be set to 0 = 'file' or 1 = 'folder'. (default:"file") ; $iTargetID - The id of the item you wish to delete. If the target is a folder, this will be the folder_id. If the target is a file, this will be the file_id. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923926/ApiFunction_delete ; ================================================================================================= Func _BoxAPI_deleteItem($sAPIKey, $sToken, $iTargetID, $iTarget = 0, $sUserAgent = "AutoIt") Local $sTarget If $iTarget = Default Then $iTarget = 0 If $sUserAgent = Default Then $sUserAgent = "AutoIt" Switch $iTarget Case 0 $sTarget = "file" Case 1 $sTarget = "folder" Case Else SetError(3, 0, -1) EndSwitch Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=delete" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target=" & $sTarget & _ "&target_id=" & $iTargetID) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_delete_node" SetError(3, 0, -1) Case "s_delete_node" Return 1 EndSwitch EndFunc ;==>_BoxAPI_deleteItem ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getFileInfo() ; Description ...: This method retrieves the details for a specified file. ; Syntax ........: _BoxAPI_getFileInfo($sAPIKey, $sToken, $iFileID[, $sUserAgent = "AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iFileID - The id of the file for with you want to obtain more information. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns a 2d array with file informations ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - The file_id is either invalid, or not accessible by that user. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923934/ApiFunction_get_file_info ; ================================================================================================= Func _BoxAPI_getFileInfo($sAPIKey, $sToken, $iFileID, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_file_info" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&file_id=" & $iFileID) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_access_denied" SetError(3, 0, -1) Case "s_get_file_info" Dim $aFile[10][2] = [["file_id", __BoxAPI_stringBetween($oHTTP.ResponseText, "file_id")], _ ["file_name", __BoxAPI_stringBetween($oHTTP.ResponseText, "file_name")], _ ["folder_id", __BoxAPI_stringBetween($oHTTP.ResponseText, "folder_id")], _ ["shared", __BoxAPI_stringBetween($oHTTP.ResponseText, "shared")], _ ["shared_name", __BoxAPI_stringBetween($oHTTP.ResponseText, "shared_name")], _ ["size", __BoxAPI_stringBetween($oHTTP.ResponseText, "size")], _ ["description", __BoxAPI_stringBetween($oHTTP.ResponseText, "description")], _ ["sha1", __BoxAPI_stringBetween($oHTTP.ResponseText, "sha1")], _ ["created", __BoxAPI_stringBetween($oHTTP.ResponseText, "created")], _ ["updated", __BoxAPI_stringBetween($oHTTP.ResponseText, "updated")]] Return $aFile EndSwitch EndFunc ;==>_BoxAPI_getFileInfo ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_setDescribtion() ; Description ...: This method sets the description for a file or folder. ; Syntax ........: _BoxAPI_setDescribtion($sAPIKey, $sToken[, $sTarget="file", $iTargetID, $sDescription[, $sUserAgent = "AutoIt"]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTarget - [optional] The type of item being targetted. This can be set to 0 = 'file' or 1 = 'folder'. (default:"file") ; $iTargetID - The id of the item for you wish to set a description. ; If the target is a folder, this will be the folder_id. If the target is a file, this will be the file_id. ; $sDescription - The description to be applied to the item. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923949/ApiFunction_set_description ; ================================================================================================= Func _BoxAPI_setDescribtion($sAPIKey, $sToken, $iTargetID, $sDescription, $iTarget = 0, $sUserAgent = "AutoIt") Local $sTarget If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $iTarget = Default Then $iTarget = 0 Switch $iTarget Case 0 $sTarget = "file" Case 1 $sTarget = "folder" Case Else SetError(3, 0, -1) EndSwitch Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=set_description" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target=" & $sTarget & _ "&target_id=" & $iTargetID & _ "&description=" & _URIEncode($sDescription)) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_set_description" SetError(3, 0, -1) Case "s_set_description" Return 1 EndSwitch EndFunc ;==>_BoxAPI_setDescribtion ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_publicShare() ; Description ...: This method makes a file or folder shareable. ; Syntax ........: _BoxAPI_publicShare($sAPIKey, $sToken[, $sTarget="file", $iTargetID[, $sPassword=""[, $sMessage=""[, $aEmails=""[, $sUserAgent = "AutoIt"]]]]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTarget - [optional] The type of item to be shared. This can be set to 0 = 'file' or 1 = 'folder'. (default:"file") ; $iTargetID - The id of the item you wish to share. If the target is a folder, this will be the folder_id. ; If the target is a file, this will be the file_id. ; $sPassword - [optional] The password to protect the folder or file. (default:"") ; $sMessage - [optional] An message to be included in a notification email. (default:"") ; $aEmails - [optional] An array of emails for which to notify users about the newly shared file or folder. (default:"") ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns a unique identifier of the publicly shared file. This can be used to generate shared ; page URLs, in the form 'http://www.box.net/shared/'. ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - The item_id may be invalid. ; |4 - Another error occured in your call. ; |5 - incorrect/incomplete parameters are supplied ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923943/ApiFunction_public_share ; ================================================================================================= Func _BoxAPI_publicShare($sAPIKey, $sToken, $iTargetID, $iTarget = 0, $sPassword = "", $sMessage = "", $aEmails = "", $sUserAgent = "AutoIt") Local $sEmails, $sTarget If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $iTarget = Default Then $iTarget = 0 If $sPassword = Default Then $sPassword = "" If $sMessage = Default Then $sMessage = "" If $aEmails = Default Then Dim $aEmails[1] Switch $iTarget Case 0 $sTarget = "file" Case 1 $sTarget = "folder" Case Else SetError(6, 0, -1) EndSwitch Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") If IsArray($aEmails) Then For $i = 0 To UBound($aEmails) - 1 If $aEmails[$i] <> "" Then $sEmails &= "&emails[]=" & $aEmails[$i] Next Else $sEmails = "" EndIf $oHTTP.Send("action=public_share" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target=" & $sTarget & _ "&target_id=" & $iTargetID & _ "&password=" & $sPassword & _ "&message=" & $sMessage & $sEmails) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") ConsoleWrite($sStatus & @CRLF) Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "wrong_node" SetError(3, 0, -1) Case "share_error" SetError(4, 0, -1) Case "wrong_input_params" SetError(5, 0, -1) Case "share_ok" Return __BoxAPI_stringBetween($oHTTP.ResponseText, "public_name") EndSwitch EndFunc ;==>_BoxAPI_publicShare ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_publicUnshare() ; Description ...: This method unshares a shared file or folder. ; Syntax ........: _BoxAPI_publicUnshare($sAPIKey, $sToken[, $sTarget = "file", $iTargetID[, $sUserAgent="AutoIt"]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $sTarget - [optional] The type of item to be shared. This can be set as 'file' or 'folder'. (default:"file") ; $iTargetID - he id of the item you wish to share. If the target is a folder, this will be the folder_id. If the target is a file, this will be the file_id. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - The item_id may be invalid. ; |4 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923944/ApiFunction_public_unshare ; ================================================================================================= Func _BoxAPI_publicUnshare($sAPIKey, $sToken, $iTargetID, $sTarget = "file", $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $sTarget = Default Then $sTarget = "file" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=public_unshare" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target=" & $sTarget & _ "&target_id=" & $iTargetID) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "wrong_node" SetError(3, 0, -1) Case "unshare_error" SetError(4, 0, -1) Case "unshare_ok" Return 1 EndSwitch EndFunc ;==>_BoxAPI_publicUnshare ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_privateShare() ; Description ...: This method privately shares a file or folder with another user(s). ; Syntax ........: _BoxAPI_privateShare($sAPIKey, $sToken[, $sTarget = "file", $iTargetID[, $sMessage = ""[, $aEmails = ""[, $sNotify = "false"]]]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $sTarget - [optional] The type of item to be shared. This can be set as 'file' or 'folder'. (default:"file") ; $iTargetID - The id of the item you wish to share. If the target is a folder, this will be the folder_id. ; If the target is a file, this will be the file_id. ; $sMessage - [optional] An message to be included in a notification email. (default:"") ; $aEmails - [optional] An array of emails for which to notify users about the newly shared file or folder. (default:"") ; $sNotify - [optional] If this parameter is set to "1", then a notification email will be sent to users. If set to "0", notifications will not be sent. (default:"false") ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - The item_id may be invalid. ; |4 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923942/ApiFunction_private_share ; ================================================================================================= Func _BoxAPI_privateShare($sAPIKey, $sToken, $iTargetID, $sTarget = "file", $sMessage = "", $aEmails = "", $sNotify = "false", $sUserAgent = "AutoIt") Local $sEmails If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $sTarget = Default Then $sTarget = "file" If $sMessage = Default Then $sMessage = "" If $aEmails = Default Then $aEmails = "" If $sNotify = Default Then $sNotify = "false" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") If IsArray($aEmails) Then For $i = 0 To UBound($aEmails) - 1 $sEmails += "&emails[]=" & $aEmails[$i] Next Else $sEmails = "" EndIf $oHTTP.Send("action=private_share" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target=" & $sTarget & _ "&target_id=" & $iTargetID & _ "&message=" & $sMessage & _ "¬ify=" & $sNotify & $sEmails) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "wrong_node" SetError(3, 0, -1) Case "private_share_error" SetError(4, 0, -1) Case "private_share_ok" Return 1 EndSwitch EndFunc ;==>_BoxAPI_privateShare ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_addToMyBox() ; Description ...: This method copies a file that publicly shared by another individual and into a user's ; a designated folder in the user's Box. ; Syntax ........: _BoxAPI_addToMyBox($sAPIKey, $sToken, $iFileID, $sPubName, $iFolderID, $aTags[, $sUserAgent = "AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iFileID - The id of the file you wish to copy. ; $sPubName - The unique public name of the shared file that you wish to copy. ; $iFolderID - The folder_id of the folder to which you will copy the item. ; $aTags - A List of tags to apply to the file when copied into the user's own folder. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; |4 - The file cannot be copied because a file of the same name already exists in that folder. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923920/ApiFunction_add_to_mybox ; ================================================================================================= Func _BoxAPI_addToMyBox($sAPIKey, $sToken, $iFileID, $sPubName, $iFolderID, $aTags, $sUserAgent = "AutoIt") Local $sTags If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") If IsArray($aTags) Then For $i = 0 To UBound($aTags) - 1 If $aTags[$i] <> "" Then $sTags += "&tags[]=" & $sTags[$i] Next Else $sTags = "" EndIf $oHTTP.Send("action=add_to_mybox" & _ "&api_key=" & $sAPIKey & _ "&file_id=" & $iFileID & _ "&public_name=" & $sPubName & _ "&folder_id=" & $iFolderID & _ $sTags) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "addtomybox_error" SetError(3, 0, -1) Case "s_link_exists" SetError(4, 0, -1) Case "addtomybox_ok" Return 1 EndSwitch EndFunc ;==>_BoxAPI_addToMyBox ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_toggleFOlderEmail() ; Description ...: This method enables or disables the upload email address for a folder. ; Syntax ........: _BoxAPI_toggleFOlderEmail($sAPIKey, $sToken, $iFolderID, $iToggle[, $sUserAgent = "AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iFolderID - The id of the folder for which to enable or disable the upload email. ; $iToggle - Enable or disable email upload. Can be 1 or 0. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns the email address to use for file uploads. ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/35640290/ApiFunction_toggle_folder_email ; ================================================================================================= Func _BoxAPI_toggleFolderEmail($sAPIKey, $sToken, $iFolderID, $iToggle, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=toggle_folder_email" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&folder_id=" & $iFolderID & _ "&enable=" & $iToggle) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_toggle_folder_email" SetError(3, 0, -1) Case "s_toggle_folder_email" Return __BoxAPI_stringBetween($oHTTP.ResponseText, "upload_email") EndSwitch EndFunc ;==>_BoxAPI_toggleFolderEmail ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getCollaborations() ; Description ...: This method is used to obtain a list of collaborators for a file or folder. ; Syntax ........: _BoxAPI_getCollaborations($sAPIKey, $sToken, $iTargetID[, $sUserAgent="AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTargetID - The id of the folder for which to obtain the list of collaborators. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns a set of structures representing each collaboration on the item. ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Target ID does not exist. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923933/ApiFunction_get_collaborations ; ================================================================================================= Func _BoxAPI_getCollaborations($sAPIKey, $sToken, $iTargetID, $sUserAgent = "AutoIt") Local $sTarget = "folder" If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_collaborations" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target=" & $sTarget & _ "&target_id=" & $iTargetID) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_get_collaborations" SetError(3, 0, -1) Case "s_get_collaborations" Return $oHTTP.ResponseText EndSwitch EndFunc ;==>_BoxAPI_getCollaborations ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getCollaborationLink() ; Description ...: This function is used to invite collaborators to a file or a folder. ; Syntax ........: _BoxAPI_getCollaborationLink($sAPIKey, $sToken, $iTargetID[, $sUserAgent="AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTargetID - The id of a folder for which to obtain collaboration links. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns a 2d array. ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - ; |4 - ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923931/ApiFunction_get_collaboration_link ; ================================================================================================= Func _BoxAPI_getCollaborationLink($sAPIKey, $sToken, $iTargetID, $sUserAgent = "AutoIt") Local $sTarget = "folder" If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_collaboration_link" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target=" & $sTarget & _ "&target_id=" & $iTargetID) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_accept_collaborators" SetError(3, 0, -1) Case "e_collaboration_link_disabled" SetError(4, 0, -1) Case "s_get_collaboration_link" Dim $aCollabLinks[2][2] = [["Viewer", __BoxAPI_stringBetween($oHTTP.ResponseText, "Viewer")], _ ["Editor", __BoxAPI_stringBetween($oHTTP.ResponseText, "Editor")]] Return $aCollabLinks EndSwitch EndFunc ;==>_BoxAPI_getCollaborationLink ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_inviteCollaborators() ; Syntax ........: _BoxAPI_inviteCollaborators($sAPIKey, $sToken, $iTargetID, $aUserIDs, $aEmails[, $iRole=0[, $sUserAgent = "AutoIt"]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTargetID - The id of the folder for which to obtain the list of collaborators. ; $aUserIDs - Alist of userIDs for people who are to be invited to collaborate on the specified file or folder. ; $aEmails - A list of emails for people who are to be invited to collaborate on the specified file or folder. ; $iRole - [optional] Can be 0 = 'viewer' or 1 = 'editor' (default:0) ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns an XML structure containig some collaboration informations ; Failure ; |Returns -1 and sets @error ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923938/ApiFunction_invite_collaborators ; ================================================================================================= Func _BoxAPI_inviteCollaborators($sAPIKey, $sToken, $iTargetID, $aUserIDs, $aEmails, $iRole=0, $sUserAgent = "AutoIt") Local $sTarget = "folder", $sRole, $sUserIDs, $sEmails If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $iRole = Default Then $iRole = 0 Switch $iRole Case 0 $sRole = "viewer" Case 1 $sRole = "editor" Case Else Return -1 EndSwitch If IsArray($aUserIDs) Then For $i = 0 To UBound($aUserIDs) -1 If $aUserIDs[$i] <> "" Then $sUserIDs &= "&user_ids[]=" & $aUserIDs[$i] Next EndIf If IsArray($aEmails) Then For $i = 0 To UBound($aEmails) -1 If $aEmails[$i] <> "" Then $sEmails &= "&emails[]=" & $aEmails[$i] Next EndIf Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=invite_collaborators" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target=" & $sTarget & _ "&target_id=" & $iTargetID & _ $sUserIDs & _ $sEmails & _ "&item_role_name=" & $sRole) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "user_already_collaborator" SetError(3, 0, -1) Case "cannot_invite_subusers" SetError(4, 0, -1) Case "e_cannot_invite_self" SetError(5,0,-1) Case "e_collaborators_limit_reached" SetError(6,0,-1) Case "e_insufficient_permissions" SetError(7,0,-1) Case "s_invite_collaborators" return $oHTTP.ResponseText EndSwitch EndFunc ;==>__BoxAPI_inviteCollaborators ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_acceptCollaboration() ; Description ...: This function is used to accept a collaboration invitation. ; Syntax ........: _BoxAPI_acceptCollaboration($sAPIKey, $sToken, $iCollabID[, $iAccept = 1[, $sUserAgent = "AutoIt"]]) ; Parameters ....: ; Return values .: Success ; |Returns an XML structure ; Failure ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/46812096/ApiFunction_accept_collaboration ; ================================================================================================= Func _BoxAPI_acceptCollaboration($sAPIKey, $sToken, $iCollabID, $iAccept = 1, $sUserAgent = "AutoIt") Local $sTarget = "folder" If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $iAccept = Default Then $iAccept = 1 Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=accept_collaboration" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&collaboration_id=" & $iCollabID & _ "&accept=" & $iAccept) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_accept_collaborators" SetError(3, 0, -1) Case "s_accept_collaboration" return $oHTTP.ResponseText EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_removeCollaboration() ; Description ...: This function is used to remove a collaborator ; Syntax ........: _BoxAPI_removeCollaboration($sAPIKey, $sToken, $iCollabID[, $sUserAgent = "AutoIt"]) ; Parameters ....: ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923946/ApiFunction_remove_collaboration ; ================================================================================================= Func _BoxAPI_removeCollaboration($sAPIKey, $sToken, $iCollabID, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=remove_collaboration" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&collaboration_id=" & $iCollabID) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_no_such_collaboration" SetError(3, 0, -1) Case "s_remove_collaboration" return 1 EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_changeItemRole() ; Description ...: This function is used to change the permission (Viewer/Editor) of a collaborator on a file or folder. ; Syntax ........: _BoxAPI_changeItemRole($sAPIKey, $sToken, $iCollabID[, $iRole = 0[, $sUserAgent = "AutoIt"]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iCollabID - The id of the listed collaboration on the item. ; $iRole - [optional] Can be 0 = 'viewer' or 1 = 'editor' (default:0) ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - The provided collaborator does not exist ; |4 - Another error occured in your call. ; Author ........: i2c ; ================================================================================================= Func _BoxAPI_changeItemRole($sAPIKey, $sToken, $iCollabID, $iRole = 0, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $iRole = Default Then $iRole = 0 Switch $iRole Case 0 $sRole = "viewer" Case 1 $sRole = "editor" Case Else Return -1 EndSwitch Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=remove_collaboration" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&collaboration_id=" & $iCollabID & _ "item_role_name=" & $sRole) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_no_such_collaborator" SetError(3, 0, -1) Case "e_change_item_role" SetError(4,0,-1) Case "s_change_item_role" return 1 EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_requestFriends() ; Description ...: This method requests new friends to be added to the user's network. ; Syntax ........: _BoxAPI_requestFriends($sAPIKey, $sToken, $sMessage, $aEmails[, $iSubscribe = 1[, $iEmail = 1[, $sUserAgent = "AutoIt"]]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $sMessage - An message to be included in a notification email. ; $aEmails - An array of emails for which to notify users about the newly shared file or folder. ; $iSubscribe - [optional] Subscribe to the public boxes of invited users. (default:1) ; $iEmail - [optional] If set to 0, no notification mail will be send (default:1) ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923948/ApiFunction_request_friends ; ================================================================================================= Func _BoxAPI_requestFriends($sAPIKey, $sToken, $sMessage, $aEmails, $iSubscribe = 1, $iEmail = 1, $sUserAgent = "AutoIt") Local $sEmails, $sSubscribe, $sEmail, $sEmails If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $iSubscribe = Default Then $iSubscribe = 1 If $iEmail = Default Then $iEmail = 1 Switch $iSubscribe Case 0 $sSubscribe = "" Case 1 $sSubscribe = "¶ms[]=auto_subscribe" Case Else Return -1 EndSwitch Switch $iEmail Case 0 $sEmail = "¶ms[]=no_email" Case 1 $sEmail = "" Case Else Return -1 EndSwitch If IsArray($aEmails) Then For $i = 0 To UBound($aEmails) -1 If $aEmails[$i] <> "" Then $sEmails &= "&emails[]=" & $aEmails[$i] Next Else $sEmails = "" EndIf Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=request_friends" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&message=" & _URIEncode($sMessage) & _ $sEmails & _ $sSubscribe & _ $sEmail) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "'e_request_friends" SetError(3, 0, -1) Case "'s_request_friends" return 1 EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getFriends() ; Description ...: This method is used to retrieve a list of the user's friends. ; Syntax ........: _BoxAPI_getFriends($sAPIKey, $sToken[, $sUserAgent = "AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns a XML structure ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923935/ApiFunction_get_friends ; ================================================================================================= Func _BoxAPI_getFriends($sAPIKey, $sToken, $sUserAgent = "AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_friends" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "¶ms[]=nozip") $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "e_get_friends" SetError(3, 0, -1) Case "s_get_friends" Return $oHTTP.ResponseText EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getContacts() ; Description ...: This method is used to retrieve a list of the user's contacts (all users with ; whom the user has shared content or collaborated on content). ; Syntax ........: _BoxAPI_getContacts($sAPIKey, $sToken[, $sUserAgent ="AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns an XML structure ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/42307501/ApiFunction_get_contacts ; ================================================================================================= Func _BoxAPI_getContacts($sAPIKey, $sToken, $sUserAgent ="AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_contacts" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "¶ms[]=nozip") $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "'e_get_contacts" SetError(3, 0, -1) Case "s_get_contacts" Return $oHTTP.ResponseText EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getUserID() ; Description ...: This function is used to obtain a given user_id when the user's login email is available. ; Syntax ........: _BoxAPI_getUserID($sAPIKey, $sToken, $sLogin[, $sUserAgent="AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $sLogin - The users login email. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns the userID ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/43666486/ApiFunction_get_user_id ; ================================================================================================= Func _BoxAPI_getUserID($sAPIKey, $sToken, $sLogin, $sUserAgent="AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_user_id" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&login=" & $sLogin) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "'e_get_user_id" SetError(3, 0, -1) Case "s_get_user_id" Return __BoxAPI_stringBetween($oHTTP.ResponseText, "id") EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getUserInfo() ; Description ...: This function is used to obtain profile information for a user in one's contact list ; Syntax ........: _BoxAPI_getUserInfo($sAPIKey, $sToken, $iUserID[, $sUserAgent = "Autoit"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iUserID - The users UserID ; $sUserAgent - [optional] (default:"Autoit") ; Return values .: Success ; |Returns an XML structure ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/42307455/ApiFunction_get_user_info ; ================================================================================================= Func _BoxAPI_getUserInfo($sAPIKey, $sToken, $iUserID, $sUserAgent = "Autoit") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_user_info" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&user_id=" & $iUserID) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "'e_get_user_info" SetError(3, 0, -1) Case "s_get_user_info" Return $oHTTP.ResponseText EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_setTags() ; Description ...: This method applies a tag or tags to a designated file or folder, replacing all existing tags on the folder. ; Syntax ........: _BoxAPI_setTags($sAPIKey, $sToken, $iTargetID, $aTags[,$iTarget = 0[, $sUserAgent="AutoIt"]]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTargetID - The id of the item you wish to tag. If the target is a folder, this will be The folder_id. If the target is a file, this will be the file_id. ; $aTags - Array of tags ; $iTarget - [optional] The type of item to be tagged. Can be 0 = 'file' or 1 = 'folder'. (default:0) ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923921/ApiFunction_add_to_tag ; ================================================================================================= Func _BoxAPI_setTags($sAPIKey, $sToken, $iTargetID, $aTags,$iTarget = 0, $sUserAgent="AutoIt") Local $sTarget, $sTags If $sUserAgent = Default Then $sUserAgent = "AutoIt" If $iTarget = Default Then $iTarget = 0 Switch $iTarget Case 0 $sTarget = "file" Case 1 $starget = "folder" Case Else Return -1 EndSwitch If IsArray($aTags) Then For $i = 0 To UBound($aTags)-1 If $aTags[$i] <> "" Then $sTags &= "&tags[]=" & $aTags[$i] Next EndIf Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=add_to_tag" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target=" & $starget & _ "&target_id=" & $iTargetID & _ $sTags) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "'addtotag_error" SetError(3, 0, -1) Case "addtotag_ok" Return 1 EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getComments() ; Description ...: This method is used to retrieve the comments on an item. ; Syntax ........: _BoxAPI_getComments($sAPIKey, $sToken, $iTargetID[, $sUserAgent="AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTargetID - The id of the file for with you would like to obtain the comments. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns an XML structure ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/22889464/ApiFunction_get_comments ; ================================================================================================= Func _BoxAPI_getComments($sAPIKey, $sToken, $iTargetID, $sUserAgent="AutoIt") Local $starget = "file" If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_comments" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target_id=" & $iTargetID & _ "&target=" & $iTarget) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "'get_comments_error" SetError(3, 0, -1) Case "get_comments_ok" Return $oHTTP.ResponseText EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_deleteComment() ; Description ...: This method is used to delete a comment. ; Syntax ........: _BoxAPI_deleteComment($sAPIKey, $sToken, $iTargetID[, $sUserAgent="AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTargetID - The id of the comment that you would like to delete ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/22920573/ApiFunction_delete_comment ; ================================================================================================= Func _BoxAPI_deleteComment($sAPIKey, $sToken, $iTargetID, $sUserAgent="AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=delete_comments" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target_id=" & $iTargetID) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "'delete_comment_error" SetError(3, 0, -1) Case "delete_comment_ok" Return 1 EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getVersions() ; Description ...: This method is used to retrieve the past versions of a file. ; Syntax ........: _BoxAPI_getVersions($sAPIKey, $sToken, $iTargetID[, $sUserAgent="AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iTargetID - The id of the file for with you would like to obtain the comments. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Returns an XML structure ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Versions are not accessible on the item specified. It may be the case that the user ; doesn't have rights to access past versions. ; |4 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923937/ApiFunction_get_versions ; ================================================================================================= Func _BoxAPI_getVersions($sAPIKey, $sToken, $iTargetID, $sUserAgent="AutoIt") Local $sTarget = "file" If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_versions" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&target_id=" & $iTargetID & _ "&target=" & $starget) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "'e_no_access" SetError(3, 0, -1) Case "'e_get_versions" SetError(4, 0, -1) Case "s_get_versions" Return $oHTTP.ResponseText EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_makeCurrentVersion() ; Description ...: This method is used to set a past version of a file as the current version. ; Syntax ........: _BoxAPI_makeCurrentVersion($sAPIKey, $sToken, $iVersionID[, $sUserAgent="AutoIt"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iVersionID - The id of the item version that you would like to set as current. ; $sUserAgent - [optional] (default:"AutoIt") ; Return values .: Success ; |Retuns 1 ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - Another error occured in your call. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/12923940/ApiFunction_make_current_version ; ================================================================================================= Func _BoxAPI_makeCurrentVersion($sAPIKey, $sToken, $iVersionID, $sUserAgent="AutoIt") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=make_current_version" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&version_id=" & $iVersionID) $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "'e_no_access" SetError(3, 0, -1) Case "s_make_current_version" Return 1 EndSwitch EndFunc ; #FUNCTION# ====================================================================================== ; Name ..........: _BoxAPI_getUpdates() ; Description ...: This method returns the content of a user's Updates tab ; Syntax ........: _BoxAPI_getUpdates($sAPIKey, $sToken, $iStart, $iEnd[, $sUserAgent="Autoit"]) ; Parameters ....: $sAPIKey - The API key obtained when registering a project with the Box platform. ; $sToken - The authentication token for your service to connect to a user's ; Box account - obtained through _BoxAPI_getAuthToken(). ; $iStart - A unix_timestamp of the earliest point in time to obtain an update ; (the time of the oldest update you want to display) ; $iEnd - A unix_timestamp of the latest point in time to obtain an update ; $sUserAgent - [optional] (default:"Autoit") ; Return values .: Success ; |Returns an XML structure ; Failure ; |Returns -1 and sets @error ; |1 - You provided an invalid api_key, or the api_key is restricted from calling this function ; |2 - The user did not successfully authenticate on the page provided in the authentication process. ; |3 - The timestamp is not a valid unix timestamp. ; Author ........: i2c ; Link ..........: http://developers.box.net/w/page/22926051/ApiFunction_get_updates ; ================================================================================================= Func _BoxAPI_getUpdates($sAPIKey, $sToken, $iStart, $iEnd, $sUserAgent="Autoit") If $sUserAgent = Default Then $sUserAgent = "AutoIt" Local Static $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", $REST_API_URL, False) $oHTTP.SetRequestHeader("User-Agent", $sUserAgent) $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.Send("action=get_updates" & _ "&api_key=" & $sAPIKey & _ "&auth_token=" & $sToken & _ "&begin_timestamp=" & $iStart & _ "&end_timestamp=" & $iEnd & _ "¶ms[]=nozip") $sStatus = __BoxAPI_stringBetween($oHTTP.ResponseText, "status") Switch $sStatus Case "application_restricted" SetError(1, 0, -1) Case "not_logged_in" SetError(2, 0, -1) Case "'e_invalid_timestamp" SetError(3, 0, -1) Case "s_get_updates" Return $oHTTP.ResponseText EndSwitch EndFunc ;internal ; #FUNCTION# ====================================================================================== ; Name ..........: __Box_API_stringBetween() ; Description ...: Description ; Syntax ........: __Box_API_stringBetween($sString, $sSearch) ; Author ........: i2c ; ================================================================================================= Func __BoxAPI_stringBetween($sString, $sSearch) $aResult = StringRegExp($sString, "<" & $sSearch & ">(.*?)", 1, 1) If IsArray($aResult) Then Return $aResult[0] Else Return "" EndIf EndFunc ;==>__BoxAPI_stringBetween Func _URIEncode($sData) ; Prog@ndy Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "") Local $nChar $sData = "" For $i = 1 To $aData[0] $nChar = Asc($aData[$i]) Switch $nChar Case 45, 46, 48 - 57, 65 To 90, 95, 97 To 122, 126 $sData &= $aData[$i] Case 32 $sData &= "+" Case Else $sData &= "%" & Hex($nChar, 2) EndSwitch Next Return $sData EndFunc ;==>_URIEncode