Origin Storage has two interfaces: JSON-RPC and HTTP. This document presents code samples for both. To get started running code samples, see:
If you want to copy and paste Python code samples into a Python editor, please copy from the HTML version of this document and not the PDF. If you copy from PDF, indentation will not be preserved.
Code Samples in the HTTP Interface
All HTTP interface code samples use the curl command line tool and are written for use on Linux/Unix but you can easily adapt them to run on windows. Instructions for using curl are in the following sections:
Regardless of the operating system you use, always use the curl -v (verbose) option, which causes curl to output all its actions.
You can download curl from the curl web site.
Running curl on Unix/Linux
The HTTP interface code samples use the backslash
\
as the line continuation character to break parts of the command over multiple lines for readability. When using the \
character, be sure that nothing, not even a space, follows the character.Running curl on Windows
If you want to run a curl sample on Windows, you can create a batch file (a file with the .bat extension) and run it by double-clicking it. Windows will open a command prompt when you run the file.
Note the following:
- Use the caret
^
character as the line continuation character when breaking a command over multiple lines. Be sure that nothing, not even a space, follows the caret. _Insert the pause command as the last command in the batch file to keep the command prompt window open after curl finishes executing so you can see curl output. (Alternatively, you can open a command prompt, then within it navigate to the directory with the batch file and run it by typing the file name and pressing enter. All output will be displayed in the command prompt window.) Note that you don’t need the caret ^ character at the end of the line that precedes the pause command.
Here is a sample Windows batch file:
1curl -v ^2-H "X-Agile-Username: yourUser" ^3-H "X-Agile-Password: yourPassword" ^4https://{Account name}.upload.llnw.net/account/login5pause
Running Your First HTTP Request
Prior to running any code samples in the remainder of this document, you can try logging in using either of the following samples: one for windows and one for Linux/Unix.
Always use https for logging in to prevent sniffer attacks that can detect your credentials and token.
Windows sample:
1curl -v ^2-H "X-Agile-Username: yourUser" ^3-H "X-Agile-Password: yourPassword" ^4https://{Account name}.upload.llnw.net/account/login5pause
Linux/Unix sample:
1curl -v \2-H "X-Agile-Username: yourUser" \3-H "X-Agile-Password: yourPassword" \4https://{Account name}.upload.llnw.net/account/login
If the call was successful, it outputs information with HTTP Status Code 200 and 0 (zero) in the X-Agile-Status header. Example:
1HTTP/1.1 200 OK2Date: Wed, 27 May 2015 16:22:46 GMT3Server: Apache4Access-Control-Allow-Origin: *5Access-Control-Allow-Headers: X-Agile-Authorization, X-Content-Type6Access-Control-Allow-Methods: OPTIONS7X-Agile-Status: 08Content-Length: 09X-Agile-Uid: 1202010X-Agile-Token: e1339185-3f71-47bc-bb69-ea970515et8811X-Agile-Gid: 10012X-Agile-Path: /{Account name}13Content-Type: text/json;charset=utf-8
(If you would like to learn more about account/login, see Logging in Using the HTTP Interface.)
Code Samples in the JSON-RPC Interface
JSON-RPC code samples in this document are in Python, but you can use any language with libraries that support JSON-RPC requests.
Languages other than Python
Obtain the necessary libraries and make any configurations needed. Then refer to the appropriate sections in this document for specific requests.
Python
To use Python, do the following:
- Refer to instructions in the following sections
- Installing the jsonrpclib Library
- Configuring the Server and Obtaining a Token
- Testing Your Setup
- Make desired calls, referring to the appropriate sections in this document for specific JSON-RPC request. See API Index
Installing the jsonrpclib Library
To install the library, follow these steps:
- Open a terminal or command prompt.
- Issue either of the following commands:
easy_install jsonrpclib
pip install jsonrpclib
Configuring the Server and Obtaining a Token
Prior to making any calls, you must point your installation to the server where your content is hosted and obtain a token. The token is required for all other API calls you make.
The following sample illustrates how to configure the server and obtain a token.
Always use https for logging in to prevent sniffer attacks that can detect your credentials and token.
JSON
1>>> import jsonrpclib2>>> api = jsonrpclib.Server('https://{Account name}.upload.llnw.net/jsonrpc')3>>> token, user = api.login( 'yourUserId', 'yourPassword' )4>>> print (token)5u'42c4160c-cb49-4352-b07b-348687495972'
(If you would like to learn more about the login method and the token, see Log In.)
Note that the sample above uses the login method to obtain a token, but you can also login using the
authenticate
method (JSON-RPC interface) or the /account/login
call (HTTP interface). See Log in to a Sub-directory and Logging in Using the HTTP Interface for additional information.All JSON-RPC code samples in this document use
api
as the server variable and token
as the token variable.Testing Your Setup
As a test, submit the noop call:
>>> result = api.noop(token)
If your output is as follows, you have successfully logged in:
1>>> print (result)2{u'operation': u'pong', u'code': 0}
(If you would like to learn more about the
noop
call, see Perform an Authenticated API Verification.)Where to Go from Here
If you successfully submited your first JSON-RPC or HTTP request, you are ready to learn the various Origin Storage APIs! Head over to API Index and choose one of the APIs listed therein. Or, if you would like to jump in and run ready-made samples for uploading files, head on over to File Upload End-to-End Examples.