API Reference

Mobingi API is organized around REST.
Our API has predictable, resource-oriented URLs. We support CORS (Cross-Origin Resource Sharing), allowing you to interact securely with our API.

API Endpoint

https://api.mobingi.com

Versioning

The current available API version is v2 only.

OAuth Authentication

In order to interact with the API, your application must authenticate. Mobingi API handles this through OAuth. An OAuth token functions as a complete authentication request. In effect, it acts as a substitute for a username and password pair.

To get an OAuth token, make a POST request to

POST /v2/access_token
Parameters Type Required Detail
client_id string Yes
client_secret string Yes
grant_type string Yes This value is always client_credentials

Example Request:

curl -X POST https://api.mobingi.com/v2/access_token \
-H "Content-Type: application/json" \
-d '{"grant_type":"client_credentials","client_id":"lg-5447826c870e7-xBV0OSJEN-tm","client_secret":"sFVYDoe08fxPjNgYvauYGOYCeXbOTE","grant_type":"client_credentials"}'

Response Body:

{
  "token_type": "Bearer",
  "expires_in": 43200,
  "access_token": "eyJ0eXAiOiJQiLCJhbGciOMeXzQfME"
}

You can then start making API requests by passing the access_token value to the Authorization Header

Authorization: Bearer eyJ0eXAiOiJQiLCJhbGciOMeXzQfME

Application Stacks

List Stacks

GET /v2/alm/stack

Request Header

Authorization: Bearer eyJ0eXAiOiJQiLCJhbGciOMeXzQfME
Content-Type: application/json

Response Body

HTTP/1.1 200 OK

[
  {
    "auth_token": "AzPoBVghiCGAHz3cyPMRImBaQUJoF",
    "user_id": "5447826c880e8",
    "nickname": "Test Stack",
    "configuration": {
      "image": "mobingi\/ubuntu-apache2-php5",
      "code": "git:\/\/github.com\/mobingilabs\/default-site-php",
      "max": "3",
      "type": "m3.medium",
      "min": "2",
      "region": "ap-northeast-1",
      "architecture": "art_elb",
      ...
    },
    "create_time": "2016-12-03T11:51:34+09:00",
    "stack_outputs": [
      {
        "OutputValue": "mo-5447826c880e8-ELB-B45HZIW6UW08-749188260.ap-northeast-1.elb.amazonaws.com",
        "OutputKey": "Address"
      },
      ...
    ],
    "stack_id": "mo-5447826c880e8-v56QbKqA-tk",
    "stack_status": "CREATE_COMPLETE"
  },
  ..
]

Create Stack

POST /v2/alm/stack
Parameters Type Required Detail
vendor string No Reserved namespace. Default value is always aws. Other supported values in Enterprise edition API are:
- OpenStack,
- AliCloud,
- SBCloud,
- K5Cloud.
cred string Yes The credential id to which Cloud vendor this stack should be deployed to. You need to set this value in Save Credential API first.
region string Yes Eg. ap-northeast-1 for AWS Tokyo region
configurations json Yes [see below]
configurations Type Required Detail
architecture string Yes Specify art_single for single stack or art_elb for load-balanced stack
type string Yes The server type, eg: t2.small
image string No The docker registry path. You can either:
- specify the full path, eg: registry.mobingi.com/wayland/lamp, or
- omit the domain part for pulling images from hub.docker.com directly, eg:greyltc/lamp/
dockerHubUsername string No Specify your username of the docker Hub if this is a private repository.
dockerHubPassword string No Specify your password of the docker Hub if this is a private repository.
min int No The minimum instances in an autoscaling group if your architecture parameter is set to art_elb. Default value is 1.
max int No The maximum instances in an autoscaling group if your architecture parameter is set to art_elb. Default value is 1.
spotRange int No AWS Only. The percentage of which spot instances should be deployed within your autoscaling group range, set it between 0 to 100.
For eg, if you have a total of 20 instances running in the autoscaling group, and spotRange is set to 50, then there will be a fleet of 10 spot instances and 10 on-demand instances.
nickname string No
code string No A git repository URI, eg: github.com/mobingilabs/default-site-php
Note: you can always update the code repository after at any time after the stack creation is complete.
gitReference string No A git repository branch tag, default value is master
gitPrivateKey string No The private key for pulling your code if the repository is a private repo.
database array No [see below]
elasticache array No [see below]
database Type Required Detail
Engine string Yes Specify either db_mysql or db_postgresql
DBtype string Yes Eg. db.m3.medium
DBStorage string Yes Storage size in GB, between 5 to 6144
ReadReplica1 string No true or false, default is false
ReadReplica2 string No [same as above]
ReadReplica3 string No [same as above]
ReadReplica4 string No [same as above]
ReadReplica5 string No [same as above]
elasticache Type Required Detail
ElastiCacheEngine string Yes Specify either Redis or Memcached
ElastiCacheNodeType string Yes Eg. cache.r3.large
ElastiCacheNodes string Yes -Redis, Specify the number of Nodes between 1 to 6. One of them is the primary node, the others are the number of replicas.
-Memcached, Specify the number of Nodes between 1 to 20

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Request body

{
    "region": "ap-northeast-1",
    "nickname": "sample stack",
    "vendor": "AWS",
    "cred": "AKIAJ2*********2DZLA",
    "configurations": {
        "spotRange":"50",
        "nickname":"sample stack",
        "min":"2",
        "max":"10",
        "type":"m3.medium",
        "architecture":"art_elb",
        "image":"mobingi/ubuntu-apache2-php7:7.1",
        "code":"github.com/mobingilabs/default-site-php",
        "region":"ap-northeast-1",
        "nodetype":"cache.r3.large",
        "database":
        [
            "DBStorage":"100",
            "Engine":"db_mysql",
            "DBtype":"db.t2.micro"
        ],
    }
}

Response Body

HTTP/1.1 200 OK
{
    "stack_id":"mo-5447826c880e8-v56QbKqA-tk",
    "status":"CREATE_IN_PROGRESS"
}

The stack creation usually takes 5 to 30 minutes to complete depends on your infrastructure's complexity. You can either log in to admin UI interface to see the stack creation progress, or make request to describe stack API.

In case if the response return a CREATE-FAILED result, you may want to check your Cloud vendor's account to see if you've reached your account limit. Eg. there are a maxium of 20 VPCs per region per AWS account.

Describe Stack

GET /v2/alm/stack/{stack_id}

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Example Response:

[
  {
    "stack_id": "mo-5447826c880e8-v56QbKqA-tk",
    "auth_token": "AzPoBVghiCGAHz3cyPMRImBaQUJoF",
    "user_id": "5447826c880e8",
    "nickname": "Test Stack",
    "vendor": "AWS",
    "cred": "AKIAJ2*********2DZLA",
    "configuration": {
      "image": "mobingi\/ubuntu-apache2-php5",
      "code": "git:\/\/github.com\/mobingilabs\/default-site-php",
      "max": "3",
      "type": "m3.medium",
      "min": "2",
      "region": "ap-northeast-1",
      "architecture": "art_elb",
      ...
    },
    "create_time": "2016-12-03T11:51:34+09:00",
    "stack_outputs": [
      {
        "OutputValue": "mo-5447826c880e8-ELB-B45HZIW6UW08-749188260.ap-northeast-1.elb.amazonaws.com",
        "OutputKey": "Address"
      },
      ...
    ],
    "stack_status": "CREATE_COMPLETE",
    "instances": [
        {
            "InstanceId":"i-01164e4912759cbed",
            "ImageId":"ami-9f0c67f8",
            "InstanceType":"m3.medium",
            "PublicIpAddress":"54.250.172.11"
            ...
        }
    ]
    "dbinstances": [
        {
            "AllocatedStorage":"100",
            "AvailabilityZone":"ap-northeast-1a",
            "DBInstanceClass":"db.m3.large",
            ...
        }
    ]
  }
]

Update Stack

PUT /v2/alm/stack/{stack_id}
Parameters Type Required Detail
configurations json No This parameter is the same as Create Stack's configurations parameter.

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Request Body

{
    "configurations":"{
        \"min\":1,
        \"max\":10
    }"
}

Example Response:

HTTP/1.1 200 OK
{
    "status":"UPDATE_IN_PROGRESS"
}

Delete Stack

DELETE /v2/alm/stack/{stack_id}

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Response Body:

HTTP/1.1 200 OK
{   
    'status':'DELETE_IN_PROGRESS'
}

Note: It may take couple minutes to delete all related resources of your stack. Though the API will try to delete all resources (such as ELB, security groups, subnets, keypairs, etc) created by this stack, but in case some resource are linked/shared across other stacks, it may shown as a DELETE-FAILED response, and you may need to manually resolve the conflict resources in your Cloud vendor account (eg. AWS) and call the API to delete the stack again.

Deploy Code

POST /v2/alm/stack/{stack_id}/code
Parameters Type Required Detail
method string Yes Options are s3, github_public,github_private, or github
filepath string No When 'method' is s3 or github_public or github_private, this value is required
privateKey string No When 'method' is github_private, this value is required

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Request Body

{
    "method":"github_public",
    "filepath":"git://github.com/mobingilabs/default-site-php"
}

Example Response:

HTTP/1.1 200 OK
{
    "status":"success"
}

Put Lifecycle Hook

AWS Only PUT /v2/alm/stack/{stack_id}/lifecyclehook
Parameters Type Required Detail
heartbeat string No The time in seconds of which lifecyclehook will apply to instances (in the same autoscaling group) when terminates on scale-in or restarts. Default value is 3600.

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Request Body

{
    "heartbeat":3600
}

Example Response:

HTTP/1.1 200 OK
{
    "status":"success"
}

Get Lifecycle Hook

AWS Only GET /v2/alm/stack/{stack_id}/lifecyclehook

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Example Response:

HTTP/1.1 200 OK

{
    "LifecycleTransition": "autoscaling:EC2_INSTANCE_TERMINATING",
    "GlobalTimeout": "172800",
    "LifecycleHookName": "mo-5447826c880e8-BHqH3h6XN-tk-lch-ists-tmnt",
    "HeartbeatTimeout": "3600"
}

Restart Instance

POST /v2/alm/stack/{stack_id}/restart_instance
Parameters Type Required Detail
instance_id string Yes

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Request Body

{
    "instance_id":"i-01164e4912759cbed"
}

Example Response:

HTTP/1.1 200 OK

{
    "status":"success",
    "reason":"Instance deleted from autoscaling group, with a protection of 3600 seconds."
}

Describe ServerConfig

GET /v2/alm/serverconfig?stack_id={stack_id}
Parameters Type Required Detail
stack_id string Yes

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Example Response:

HTTP/1.1 200 OK

{
    "image":"mobingi\/ubuntu-apache2-php5",
    "code":"git:\/\/github.com\/mobingilabs\/default-site-php",
    "codeDir":"\/srv\/code\/",
    "ports":[
        80,
        443
    ],
    "environmentVariables":[],
    "updated":1479374854,
    "version":"2017-02-01",
}

Update ServerConfig

PUT /v2/alm/serverconfig
Parameters Type Required Detail
stack_id string Yes
filepath string No Required if privateKey or branch are set
privateKey string No
branch string No
mackerelApiKey string No Required if parameter key is set
envvars array No Required if parameter key is set
keypair_id string No Required if parameter key is set

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Request Body

{
    "stack_id":"mo-5447826c880e8-v56QbKqA-tk",
    "filepath":"git:\/\/github.com\/mobingilabs\/default-site-php"
}

or 

{
    "stack_id":"mo-5447826c880e8-v56QbKqA-tk",
    "mackerelApiKey" : "************",
}

or 
{
    "stack_id":"mo-5447826c880e8-v56QbKqA-tk",
    "envvars" : ["AWS_REGION": "ap-northeast-1", "TEST_USER_NAME": "testuser"],
}

or 
{
    "stack_id":"mo-5447826c880e8-v56QbKqA-tk",
    "keypair_id" : "421a3b5bc2",
}

Example Response:

HTTP/1.1 200 OK

{
    "status":"success"
}

User Credentials

List Credentials

GET /v2/credentials/{vendor}
Parameters Type Required Detail

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Response Body

HTTP/1.1 200 OK

[
    {
        "id": "*** your aws access key id ***",
        "account": "My Aws account 1",
        "lastModified": "2017-01-21T06:39:06.000Z"
    },
    {
        "id": "*** your aws access key id ***",
        "account": "My Aws account 2",
        "lastModified": "2017-01-21T06:33:10.000Z"
    },
    ...
]

Save Credentials

POST /v2/credentials/{vendor}
Parameters Type Required Detail
credentials array Yes contains credentials information (see example request below)

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Request Body

{
  "credentials": {
    "AWSAccessKeyId": "*** your aws access key id ***",
    "AWSSecretKey": "*** your aws secret key ***",
    "AWSAccountName": "My Aws account 1"
  }
}

Response Body

HTTP/1.1 200 OK

{
    "status":"success"
}

Delete Credentials

DELETE /v2/credentials/{vendor}
Parameters Type Required Detail
credential_id string Yes

Request Header

Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json

Request Body

{
    "credential_id":"*** your aws access key id **"
}

Example Response:

HTTP/1.1 200 OK

{
    "status":"success"
}