Skip to content
Thomas Howe edited this page Apr 14, 2016 · 1 revision

GreenBot API

The Greenbot API is currently provided by the admin portal, and uses Restivus to provide access to the Sessions, Bots and Scripts collections. This section is copied straight from there:

Basic Usage

We can call our POST /bots endpoint the following way.

curl -d "name=My New Bot" http://localhost:3000/api/bots

Authenticating

Warning: Make sure you're using HTTPS, otherwise this is insecure!

Default Authentication

Note: To use the default authentication, you must first create a user with the accounts-password package. You can do this with Restivus if you setup a POST collection endpoint for the Meteor.users collection.

Logging In

If you have useDefaultAuth set to true, you now have a POST /api/login endpoint that returns a userId and authToken. You must save these, and include them in subsequent requests. In addition to the password, the login endpoint requires one of the following parameters (via the request body):

  • email: An email address associated with your Meteor.user account
  • username: The username associated with your Meteor.user account
  • user: Note: This is for legacy purposes only. It is recommended to use one of the options above. Accepts either of the options listed above. Restivus will (very naively) attempt to determine if the value provided is an email, otherwise it will assume it to be the username. This can sometimes lead to unexpected behavior.

A login will look something like

curl http://localhost:3000/api/login/ -d "username=test&password=password"

And the response will look like

{ status: "success", data: {authToken: "f2KpRW7KeN9aPmjSZ", userId: fbdpsNf4oHiX79vMJ} }

You'll need to save the userId and token on the client, for subsequent authenticated requests.

Logging Out

You also have an authenticated POST /api/logout endpoint for logging a user out. If successful, the auth token that is passed in the request header will be invalidated (removed from the user account), so it will not work in any subsequent requests.

curl http://localhost:3000/api/logout -X POST -H "X-Auth-Token: f2KpRW7KeN9aPmjSZ" -H "X-User-Id: fbdpsNf4oHiX79vMJ"

Authenticated Calls

For any endpoints that require the default authentication, you must include the userId and authToken with each request under the following headers:

  • X-User-Id
  • X-Auth-Token
curl -H "X-Auth-Token: f2KpRW7KeN9aPmjSZ" -H "X-User-Id: fbdpsNf4oHiX79vMJ" http://localhost:3000/api/bots/