2017-06-21 14:47:55 +02:00
|
|
|
OVH API Bash client
|
2014-04-17 20:13:09 +02:00
|
|
|
================
|
|
|
|
|
|
|
|
A bash client for OVH API (https://api.ovh.com/)
|
|
|
|
|
|
|
|
Initialize
|
|
|
|
----------
|
|
|
|
|
2014-04-17 22:17:09 +02:00
|
|
|
### Retrieve dependency
|
|
|
|
|
2014-04-17 22:17:44 +02:00
|
|
|
First in order to retrieve needed dependency, run:
|
2014-04-17 22:17:09 +02:00
|
|
|
```
|
|
|
|
make
|
|
|
|
```
|
|
|
|
|
2014-04-17 21:31:01 +02:00
|
|
|
### Create an OVH API Application
|
|
|
|
|
2014-04-17 21:28:03 +02:00
|
|
|
In order to create a new OVH API application, run:
|
2014-04-17 20:16:30 +02:00
|
|
|
```
|
2014-04-19 21:59:27 +02:00
|
|
|
./ovh-api-bash-client.sh --initApp
|
2014-04-17 20:16:30 +02:00
|
|
|
```
|
2014-04-17 20:13:09 +02:00
|
|
|
|
2014-04-17 21:31:01 +02:00
|
|
|
### Create a Consumer Key
|
|
|
|
|
|
|
|
In order to create a new consumer key, run:
|
|
|
|
```
|
2014-04-19 21:59:27 +02:00
|
|
|
./ovh-api-bash-client.sh --init
|
2014-04-17 21:31:01 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Options
|
|
|
|
-------
|
|
|
|
|
2017-06-13 18:06:41 +02:00
|
|
|
### Show help
|
|
|
|
```
|
|
|
|
./ovh-api-bash-client.sh --help
|
|
|
|
```
|
|
|
|
|
2014-04-17 21:31:01 +02:00
|
|
|
Possible arguments are:
|
|
|
|
```
|
2017-06-19 18:36:33 +02:00
|
|
|
--url <url> : the API URL to call, for example /domains (default is /me)
|
|
|
|
--method <method> : the HTTP method to use, for example POST (default is GET)
|
|
|
|
--data <JSON data> : the data body to send with the request
|
|
|
|
--target <CA|EU> : the target API (default is EU)
|
|
|
|
--init : to initialize the consumer key
|
|
|
|
--initApp : to initialize the API application
|
|
|
|
--list-profile : list available profiles in profile/ directory
|
|
|
|
--profile <value>
|
|
|
|
* default : from script directory
|
|
|
|
* <dir> : from profile/<dir> directory
|
2014-04-17 21:31:01 +02:00
|
|
|
```
|
|
|
|
|
2014-04-17 20:13:09 +02:00
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
|
2014-04-17 21:31:01 +02:00
|
|
|
### Just some examples:
|
|
|
|
|
2014-04-17 21:28:03 +02:00
|
|
|
To make a basic call on GET /me just run:
|
2014-04-17 20:16:30 +02:00
|
|
|
```
|
2014-04-19 21:59:27 +02:00
|
|
|
./ovh-api-bash-client.sh
|
2014-04-17 20:16:30 +02:00
|
|
|
```
|
2014-04-17 20:13:09 +02:00
|
|
|
|
2014-04-17 21:28:03 +02:00
|
|
|
To retrieve your domain list, run:
|
|
|
|
```
|
2014-04-19 21:59:27 +02:00
|
|
|
./ovh-api-bash-client.sh --url "/domain"
|
2014-04-17 21:28:03 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
To activate the monitoring on your dedicated server, run:
|
|
|
|
```
|
2014-04-19 21:59:27 +02:00
|
|
|
./ovh-api-bash-client.sh --method PUT --url "/dedicated/server/ns00000.ovh.net" --data '{"monitoring": true}'
|
2014-04-17 21:28:03 +02:00
|
|
|
```
|
|
|
|
|
2017-06-21 14:31:13 +02:00
|
|
|
To create a Consumer key for different account or usage (profile is created if missing)
|
2017-06-13 18:06:41 +02:00
|
|
|
```
|
|
|
|
./ovh-api-bash-client.sh --profile demo1 --init
|
|
|
|
./ovh-api-bash-client.sh --profile demo2 --init
|
|
|
|
```
|
2017-06-30 18:57:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
Embedded lib for external scripts
|
|
|
|
----------
|
|
|
|
|
|
|
|
### ovh-api-lib.sh
|
|
|
|
|
|
|
|
#### OvhRequestApi
|
|
|
|
|
2017-07-03 00:38:10 +02:00
|
|
|
OvhRequestApi() is wrapper to ovh-api-bash-client.sh
|
2017-06-30 18:57:05 +02:00
|
|
|
|
|
|
|
```
|
|
|
|
OvhRequestApi url [method] [post_data]
|
|
|
|
```
|
|
|
|
|
|
|
|
return values in OVHAPI_HTTP_STATUS and OVHAPI_HTTP_RESPONSE
|
|
|
|
|
|
|
|
|
2017-07-03 00:38:10 +02:00
|
|
|
#### wrappers for JSON.sh
|
|
|
|
|
|
|
|
- getJSONKeys() : get JSON keys, remove first/last double quotes if present
|
|
|
|
- getJSONValue() : get a JSON key value, remove first/last double quotes if present
|
2017-06-30 18:57:05 +02:00
|
|
|
- getJSONValues() : get all JSON values at once
|
|
|
|
|
|
|
|
### sample usage
|
|
|
|
|
|
|
|
Once you've an available OVH API authentication, you can use the library :
|
|
|
|
|
2017-07-03 00:38:10 +02:00
|
|
|
- To override profile, set OVHAPI_BASHCLIENT_PROFILE
|
|
|
|
- To override target, set OVHAPI_TARGET
|
|
|
|
- For **ovh-api-lib.sh** debug output, set OVHAPILIB_DEBUG to 1
|
2017-06-30 18:57:05 +02:00
|
|
|
|
2017-07-03 00:38:10 +02:00
|
|
|
This variables can be set in your script or exported from commandline
|
2017-06-30 18:57:05 +02:00
|
|
|
|
2017-07-03 00:38:10 +02:00
|
|
|
You can find some samples scripts in the **samples/** directory
|
2017-06-30 18:57:05 +02:00
|
|
|
|
2017-07-03 00:38:10 +02:00
|
|
|
**sample usage**
|
2017-06-30 18:57:05 +02:00
|
|
|
|
2017-07-03 00:38:10 +02:00
|
|
|
```
|
|
|
|
OVHAPI_BASHCLIENT_PROFILE=demo samples/list-domains.sh
|
|
|
|
```
|