/en/_posts/2014-05-20-how-to-use-runabove-api.markdown

https://gitlab.com/billyprice1/knowledge-base · Markdown · 86 lines · 62 code · 24 blank · 0 comment · 0 complexity · 40a1efd49979289b2975cdd7aba98c9a MD5 · raw file

  1. ---
  2. layout: post
  3. title: "How to use RunAbove API?"
  4. categories: Instances
  5. author: VincentCasse
  6. lang: en
  7. ---
  8. RunAbove has been designed to help developers in building scalable software faster. To create applications with our product, we provide an API for each of our products. But, how do you use our api ?
  9. # API capabilities
  10. To discover all possibilities of our APIs, you could use the automated console available here : [https://api.runabove.com/console/](https://api.runabove.com/console/). In the console, you can see the documentation of APIs and you can test each of the calls available .
  11. __Note__ : The RunAbove API is designed to be very simple. If you want to deal directly with Openstack API, you can authenticate with Keystone in [https://auth.runabove.io/](https://auth.runabove.io/).
  12. More information about how to use Openstack APIs for [Object Storage](http://developer.openstack.org/api-ref-objectstorage-v1.html), [Instances](http://developer.openstack.org/api-ref-compute-v2.html) and [Authentication](http://developer.openstack.org/api-ref-identity-v2.html)
  13. # How to authenticate a user?
  14. First, you have to declare your application in the API to be authorized to communicate with RunAbove API. To declare a new application, you can fill in the form found at the following page : [https://api.runabove.com/createApp/]( https://api.runabove.com/createApp/). This application will be linked to your account with a specific name and description. You need to save your _application key_ and _application secret_ to identify your requests.
  15. If you want to develop an application with RunAbove API, you have to use a token, called a _consumer key_ for each API's request. To get this token, you must go to this url [https://api.runabove.com/1.0/auth/credential](https://api.runabove.com/1.0/auth/credential) with some data inside the body of the request:
  16. ```bash
  17. curl -X POST \
  18. -H 'X-Ra-Application: z5czlUfqJL6HsYKj' \
  19. -H 'Content-Type: application/json' \
  20. -d '{
  21. "accessRules":
  22. [
  23. { "method":"GET","path":"/me"}
  24. ],
  25. "redirection":"http://runabove.com"
  26. }' \
  27. "https://api.runabove.com/1.0/auth/credential"
  28. ```
  29. This request contains your application key included in metadata and requires that the access rules be listed inside the body.
  30. Access rules define which call will be authorized when the consumer key is used. For example, here, the application can only call /me but you can add requests as required. You can precisely define which calls each app has access to: you can use regex to declare with request will be authorize in the consumer key. If you want get vnc console of all your instances, you could authorize your application with this accessRules :
  31. ```bash
  32. { "method":"GET","path":"/instance/*/vnc"}
  33. ```
  34. In return to this request, you will get the consumer key and a url. In this url, a user can validate the consumer key with their authentication.
  35. # How to call the API?
  36. Now that you have the application's credentials and consumer key validated, by user login, you can call our API. For example to get a list of your instances.
  37. To do this, you need to send a request to [https://api.runabove.com/1.0/instance](https://api.runabove.com/1.0/instance) with the following.
  38. ```bash
  39. $ curl -XGET
  40. -H 'X-Ra-Application:your_application_key' \
  41. -H 'X-Ra-Timestamp:current_timestamp' \
  42. -H 'X-Ra-Signature:generated_signature' \
  43. -H 'X-Ra-Consumer:the_consumer_key' \
  44. https://api.runabove.com/1.0/instance
  45. ```
  46. To reduce differences between your local timestamp and timestamp inside API's servers, you can get the current timestamp of our servers with a call on [https://api.runabove.com/1.0/auth/time](https://api.runabove.com/1.0/auth/time).
  47. ```bash
  48. $ curl https://api.runabove.com/1.0/auth/time
  49. 1400000000
  50. ```
  51. With this information, you can calculate the difference between timestamps and add it on your local timestamp on each request.
  52. Signature is a sha1, in hexadecimal format, composed by a string with some information separated by _+_ character: your application secret, the consumer key, HTTP verb, query, body of the request and timestamp.
  53. ```bash
  54. $ echo -n "your_application_secret_key+application_consumer_key+GET+https://api.runabove.com/1.0/instance++1400000000" | openssl dgst -sha1 | awk '{print $2}'
  55. d33fced42c337a8dfc15d6b7a8e0c588d3a0f62f
  56. ```
  57. Prepend `$1$` to the signature so it becomes:
  58. ```
  59. $1$d33fced42c337a8dfc15d6b7a8e0c588d3a0f62f
  60. ```
  61. # Congratulations!
  62. You have your first request on RunAbove API! Now you can create applications on object storage or automate your infrastructure with some creation of new instances!