Using the ObjectRocket API for Elasticsearch

By February 22, 2017 August 18th, 2022 No Comments

Have you every spent time dreaming of a fully automated Elasticsearch environment? If so, stay tuned as this post will walk you through some of ObjectRocket’s basic API features for our Elasticsearch product. Using the ObjectRocet API will allow you to create instances, users, acls, and more on demand.

Getting Started

All authentication to our API occurs using HTTP basic authentication. To do so, you’ll need to authenticate with the SJC API server (no matter what zone you’re in) to receive a token before you can perform any API functions. To get a token, you’ll need to provide a username and password. This will be the same credentials used when logging into the ObjectRocket Login Page. It’s worth mentioning, any RESTful client can be used to perform these requests. However, for our examples we’ll show the syntax using the curl utility:

curl -XGET 'https://sjc-api.objectrocket.com/v2/tokens/' --user 'my_login@objectrocket.com'

After supplying your password, if successful, you’ll receive a payload that looks like the following:

# Payload
  "data": {
    "login": "my_login@objectrocket.com",
    "uid": "57fc6b07c3fbee4cbc1e8b77"

If you get this message back you’ve successfully received your token! We can now use this token going forward to make additional API calls. In the examples below I’ve saved this value as a variable for reusability:

export token="X-Auth-Token:THISISATOKENImI4Nc1ODVmYjRiMjRiZDczYTJhOTk1ZDc0ZmVjIAvCvVFP5rhdGetXDHETY"
Creating a new instance:

For each of the different API calls below we’ll show an example of the payload (if necessary) followed by an example of the command itself.

# Payload
  "service": "elasticsearch",
  "name": "my_instance",
  "version": "5.1.1",
  "zone": "US-East-IAD1",
  "plan": 32,
  "type": "elasticsearch"

If you need assistance figuring out what plan sizings we offer you can visit our pricing page. Additionally, more details about (version, zone, etc) can be found in the instance creation modal in the UI.

curl -XPOST 'https://sjc-api.objectrocket.com/v2/instances' -d '{"service":"elasticsearch","name":"my_instance","version":"5.1.1","zone":"US-East-IAD1","plan":32,"type":"elasticsearch"}' -H $token -H "Content-Type: application/json"
Create a user:
# Payload
  "username": "myuser",
  "password": "mytestp@ss",
  "role": "admin"
curl -XPOST 'https://sjc-api.objectrocket.com/v2/elasticsearch/my_instance/users' -d '{"username": "myuser", "password": "mytestp@ss", "role": "admin"}' -H $token -H "Content-Type: application/json"
Add an acl:
# Payload
  "cidr_mask": "",
  "description": "my acl"
curl -XPOST 'https://sjc-api.objectrocket.com/v2/instances/my_instance/acls' -d '{"cidr_mask": "", "description": "my acl"}' -H $token -H "Content-Type: application/json"
Add a data node:
# Payload
  "count": 1
curl -XPOST 'https://sjc-api.objectrocket.com/v2/elasticsearch/new_instance/data_nodes' -d '{"count":1}' -H $token -H "Content-Type: application/json"
Get curator tasks:
curl -XGET 'https://sjc-api.objectrocket.com/v2/instances/my_instance/curatortasks' -H $token -H "Content-Type: application/json"


These are just a few of the API calls you can leverage using the ObjectRocket API for Elasticsearch. We’ll continue to publish and update our documentation for the API as more features are pushed out. If you have any requests for new API calls or if you have any questions you can always let us know at support@objectrocket.com!