Connect

Connect to existing database or create new one.

This method returns Long Access Token which is required to get Short Access Token - main token for all requests.

Set parameter isNewUser: true to register new user.

Method

POST

URI

/api/database/connection

Headers

Content-Type	application/json

Body

{
    "data": [
        {
            "email": "some-user@example.com",
            "password": "some_secret_password",
            "name": "Some User"
        }
    ],
    "context": {
        "domain": "mycooldomain.net",
        "isNewUser": true,
        "location": "custom",
        "locale": "en"
    }
}

Result

{
    "accessToken": "<long-access-token>",
    "name": "Some User"
}

Examples

const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

const raw = JSON.stringify({
  "data": [
    {
      "email": "some-user@example.com",
      "password": "some_secret_password",
      "name": "Some User",
    }
  ],
  "context": {
    "domain": "mycooldomain.net",
    "isNewUser": true,
    "location": "custom",
    "locale": "en",
  },
});

const requestOptions = {
  method: 'POST',
  headers: myHeaders,
  body: raw,
  redirect: 'follow'
};

fetch("https://api-test-tool.backend.spacemonopoly3d.com/api/database/connection", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
const request = require('request');
const options = {
  'method': 'POST',
  'url': 'https://api-test-tool.backend.spacemonopoly3d.com/api/database/connection',
  'headers': {
    'Content-Type': ['application/json'],
  },
  body: JSON.stringify({
    "data": [
      {
        "email": "some-user@example.com",
        "password": "some_secret_password",
        "name": "Some User",
      }
    ],
    "context": {
      "domain": "mycooldomain.net",
      "isNewUser": true,
      "location": "custom",
      "locale": "en",
    }
  }),
};

request(options, function (error, response) { 
  if (error) throw new Error(error);
  console.log(response.body);
});
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://api-test-tool.backend.spacemonopoly3d.com/api/database/connection');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Content-Type' => 'application/json'
));
$request->setBody(json_encode(array(
  "data" => [
    array(
      "email" => "some-user@example.com",
      "password" => "some_secret_password",
      "name" => "Some User",
    )
  ],
  "context" => array(
    "domain" => "mycooldomain.net",
    "isNewUser" => true,
    "location" => "custom",
    "locale" => "en",
  )
)));

try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}