CentreStack offers a RESTful API (Representational State Transfer Application Programming Interface) that you can use to automate most tasks via simple HTTP requests (Hypertext Transfer Protocol), such as posts, gets, deletes, etc.
The actual API documentation contains the full reference along with the mandatory "Hello World," but in this article I will show you a Powershell example using two back-to-back API calls with simple response parsing. If you understand this example, you will be able to use any of the documented API functions, because most of the requests require an authentication cookie to be obtained first and then passed in the HTTP Header of any subsequent calls. Most calls also require an XML object to be passed in the HTTP body, and the example in this article shows you how to do both of these tasks. CentreStack offers an alternate Powershell API that you can call directly without having to make extra HTTP requests, but the REST API is more complete, up-to-date, and more flexible for programming with different languages. For more information about the native Powershell API, please go to the CentreStack documentation (https://centrestack.com/Documentation/) and look for the Powershell Module Guide.
Here is an example that uploads a small zip called c:\TMP\gladr.zip to the root of the Home storage. It performs the following tasks in succession:
1-Logs in a user and obtains an authentication cookie for future requests
2-Uploads a file using the authentication cookie
3-Invokes the API method to generate a public link for the file
4-Outputs the public link to the screen
This script can be modified to ask the user for a file location and file name, but for the sake of simplicity, these values have been hard-coded. Please replace them with something else of your choosing. The proxiedupload.up endpoint has a 20MB file limit. Larger file sizes need to use multi-part uploading, which is not covered by the public API.
The code should be self-explanatory since many comments have been added on the lines starting with a pound sign (#). Please customize the login credentials and IP access point where indicated.
To implement the script, simply copy the entire code between the equal sign lines below into a notepad text file and name it "UPLOAD_FILE_AND_SHARE_API_POWERSHELL_EXAMPLE.ps1". You may need to change your Powershell execution policy in order to run the script (see https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-6&viewFallbackFrom=powershell-Microsoft.PowerShell.Core for more information).
Here is the full API documentation.