These instructions assume that your python binary is called "python".
The first time you run apiclient.py
, you will be asked to enter configuration
information, including credentials. For more details see the Configuration
section of readme.md
.
There are two main uses of apiclient.py
- Print API endpoints.
python apiclient.py --print_api
will print all endpoints and information needed to make calls against that endpoint.
- Make requests to an API endpoint.
The most basic call you can make is a GET request to an endpoint that requires no parameters:
python apiclient.py --api /help/versions --method GET
Arguments for basic calls:
--api /api_name/endpoint
- This is the path to your api endpoint. It is the part of the url that
you would append to
http://<server_ip>/restapi/api
. For examplehttp://<server_ip>/restapi/api/referencedata/sets
.
--method METHOD
- This determines whether your api request will be a GET, POST, or
DELETE. To know what method an endpoint needs, check the output of
--print_api
.
There are three types of parameters. path, query, and body parameters.
Path parameters are those that modify the endpoint you are calling. For
example, name is a parameter of the ver 0.1 endpoint
/referencedata/sets/{name}
. This means, to call this endpoint,
you must place the name of the set in the path to the endpoint you specify
in --api
. For example, to retrieve a reference set identified by the name
exampleset
. You would call:
python apiclient.py --api /referencedata/sets/exampleset --method GET
Any path parameters will correspond to some place in endpoint portion in the url.
If you have any query parameters, they must be entered with the syntax
--params <param_name>="<param_value>"
. For example, to use the filter
parameter with the /help/versions
endpoint:
python apiclient.py --api /help/versions --method GET --params filter="version=6.0"
Once again check the output of --print_api
to determine which parameters
are query, or body parameters.
Body parameters are entered in the command line the same way as query
parameters, --<param_name>="<param_value>"
, except you must specify the
content type of the body you are sending with the --content_type TYPE
or
--request_format TYPE
argument. For example, to bulkload data to an existing
set of element type ALN named exampleset
:
python apiclient.py --api /referencedata/sets/bulkLoad/exampleset
--method POST --content_type="application/json"
--params data="['value1','value2','value3']"
The --request_format
or --content_type
argument needs to be specified or
the body will be sent as a query parameter, and the API call will fail.
--response_format RESPONSE_FORMAT
This sets the Accept
header of the request object, determining the
Content-type of the response object. The default is application/json
.
If the endpoint does not support application/json
you will get an
error 406 with the message:
"MIME pattern 'application/json' does not match any content types
returned by this endpoint. This endpoint supports "
This means you must set your --response_format
argument to one of the
supported types.
--version VERSION
This tells the system which version of the endpoint you are calling. If the endpoint does not have that exact version it will round down to the closest available version number.
--range RANGE
If an endpoint supports paging, you can supply the range of items you
would like to have returned with --range x-y
.