NAV Navbar


javascript python go hide code



Account API

This section offers account management and authentication token management.

We have usage examples for Javascript and will add Python and Golang soon.

You can view code examples to the right, and switch the programming language above.

Authentication

Temporal uses JSON Web Tokens for authentication, accessed through the POST login call.

Throughout the code examples in this documentation, you will see <JWT> which requires a JWT for access.

General Errors

Except for 400 responses unique to an API call, error codes generally conform to the following:

Error CodeMeaning
400Error – Invalid data supplied.
401Unauthorized – Invalid authentication token. Check to make sure you’re properly passing the authorization token.
403Forbidden – You do not have access to this functionality.
404Not Found – Resource not found.
500Server Error – We had a problem with our server. Try again later or contact support@rtradetechnologies.com

In some cases, calls will return a 200 code as generally expected, but will not successfully execute the command. In this case, we will specify the particular conditions this could occur for a given API call.

Validation (400 Error Code)

{
  "code": "400",
  "response": [
    {
        "message": "Must be one of: RSA, ED25519",
        "field": "key_type"
    }
  ]
}

Methods that take input will validate all parameters. Any parameter that fails validation will trigger an error response with status 400. The response body will be a JSON object that includes a message as well as a list of fields that failed validation.

Account Management

POST login

Golang code here.
Python code here.
handleLogin = (username, password) => () => {

        fetch('https://dev.api.temporal.cloud/v2/auth/login', {
            method: 'POST',
            headers: {
                'Content-Type': 'text/plain'
            },
            body: JSON.stringify({
                "username": username.toString(),
                "password": password.toString()
            })
        }).then(res => res.json()).catch(error => {
            console.error(error);
            if (error) {
                throw error;
            }
        })
            .then(response => {
                if (response.expire) {
                    console.log(response.token.toString());
                }
                // Error handling here.
            })
            .catch(error => console.error('#' + error));

    };

Example Response (200)

{
  "expire": "2018-12-21T19:31:42Z",
  "token": "eyJhbG ... "
}

https://dev.api.temporal.cloud/v2/auth/login

Validates the provided username and password to generate a JSON Web Token (JWT) used for authentication. This token is valid for exactly 24 hours, at which point you will need to generate a new token.

Parameters

FieldTypeDescription
usernameStringThe username.
passwordStringThe associated password.

Response (200)

FieldTypeDescription
expireDateTimeTime at which the token expires (24 hours).
tokenStringValue of the JWT.

POST register

Golang code here.
Python code here.
handleRegister = (username, password, email) => () => {

        var data = new FormData();
        data.append("username", username);
        data.append("password", password);
        data.append("email_address", email);

        var xhr = new XMLHttpRequest();
        xhr.withCredentials = false;

        xhr.addEventListener("readystatechange", function () {

            if (xhr.readyState === 4) {

                let result = JSON.parse(xhr.responseText);

                if (result.code === 200) {
                    console.log(result);
                }

                else {
                    // Error handling.
                }
            }
        }.bind(this));

        xhr.open("POST", "https://dev.api.temporal.cloud/v2/auth/register");
        xhr.setRequestHeader("Cache-Control", "no-cache");
        xhr.send(data);

    };

Example Response (200)

{
  "code": 200,
  "response": {
    "ID": 225,
    "CreatedAt": "2018-12-20T19:33:52.003315586Z",
    "UpdatedAt": "2018-12-20T19:33:52.003315586Z",
    "DeletedAt": null,
    "UserName": "postables+test2019",
    "EmailAddress": "postables+test2019@rtradetechnologies.com",
    "EnterpriseEnabled": false,
    "AccountEnabled": true,
    "APIAccess": true,
    "EmailEnabled": false,
    "EmailVerificationToken": "",
    "AdminAccess": false,
    "HashedPassword": "scrubbed",
    "Credits": 99999999,
    "IPFSKeyNames": null,
    "IPFSKeyIDs": null,
    "IPFSNetworkNames": null
  }
}

https://dev.api.temporal.cloud/v2/auth/register

Registers your information for the POST login call, which is used to generate authenticated JSON Web Tokens (JWT).

Parameters

FieldTypeDescription
usernameStringYour desired username.
passwordStringYour desired password.
email_addressStringAn associated e-mail address.

Response (200)

FieldTypeDescription
IDIntThe unique ID of your registration.
CreatedAtDateTimeTime the account was created.
UpdatedAtDateTimeTime the account was last updated.
DeletedAtDateTimeTime the account was deleted.
UsernameStringYour username.
EmailAddressStringYour e-mail address.
EnterpriseEnabledBoolYour account’s enterprise status.
AccountEnabledBoolYour account status.
APIAccessBoolYour API access.
EmailEnabledBoolYour e-mail notification status.
EmailVerificationTokenStringSent via e-mail to confirm association.
AdminAccessBoolYour admin status.
HashedPasswordStringThe handling of your password.
CreditsIntYour starting credits.
IPFSKeyNamesArray[String]IPFS key names associated with your account.
IPFSKeyIDsArray[String]IPFS key values associated with your account.
IPFSNetworkNamesArray[String]Private IPFS networks associated with your account.

POST password change

Golang code here.
Python code here.
handleChangePassword = (oldPassword, newPassword) => () => {

    let data = new FormData();
    data.append("old_password", oldPassword);
    data.append("new_password", newPassword);

    let xhr = new XMLHttpRequest();
    xhr.withCredentials = false;

    xhr.addEventListener("readystatechange", function () {

        if (xhr.readyState === 4) {

            let result = JSON.parse(xhr.responseText);

            if (result.code === 200) {
                console.log(result);
            }

            else {
                // Error handling.
            }
        }
    }.bind(this));

    xhr.open("POST", "https://dev.api.temporal.cloud/v2/account/password/change");
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.setRequestHeader("Authorization", "Bearer " + <JWT>);
    xhr.send(data);

};

Example Response (200)

{
  "code": 200,
  "response": "password changed"
}

https://dev.api.temporal.cloud/v2/account/password/change

Change the password associated with your account.

Parameters

FieldTypeDescription
old_passwordStringYour old password.
new_passwordStringYour desired, new password.

GET credits

Golang code here.
Python code here.
let xhr = new XMLHttpRequest();
xhr.withCredentials = false;

xhr.addEventListener("readystatechange", function () {

    if (xhr.readyState === 4) {

        let result = JSON.parse(xhr.responseText);

        if (result.code === 200) {
            console.log(result);
        }

        else {
            // Error handling.
        }
    }
}.bind(this));

xhr.open("GET", "https://dev.api.temporal.cloud/v2/account/credits/available");
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Authorization", "Bearer " + <JWT>);
xhr.send();

Example Response (200)

{
  "code": 200,
  "response": 10000464.996296696
}

https://dev.api.temporal.cloud/v2/account/credits/available

View the amount of credits your account has.

The response is of type double.

Recovery

POST forgot username

Golang code here.
Python code here.
handleForgotUsername = (email) => () => {

    let data = new FormData();
    data.append("email_address", email);

    let xhr = new XMLHttpRequest();
    xhr.withCredentials = false;

    xhr.addEventListener("readystatechange", function () {

        if (xhr.readyState === 4) {

            let result = JSON.parse(xhr.responseText);

            if (result.code === 200) {
                console.log(result);
            }

            else {
                // Error handling.
            }
        }
    }.bind(this));

    xhr.open("POST", "https://dev.api.temporal.cloud/v2/forgot/username");
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.send(data);
};

Example Response (200)

{
  // Need an example response.
}

https://dev.api.temporal.cloud/v2/forgot/username

Sends a reminder to the associated e-mail address with the given username. Your account must have an activated e-mail address for this call to execute.

Parameters

FieldTypeDescription
email_addressStringThe e-mail address associated with your account.

POST forgot password

Golang code here.
Python code here.
handleForgotPassword = (email) => () => {

    let data = new FormData();
    data.append("email_address", email);

    let xhr = new XMLHttpRequest();
    xhr.withCredentials = false;

    xhr.addEventListener("readystatechange", function () {

        if (xhr.readyState === 4) {

            let result = JSON.parse(xhr.responseText);

            if (result.code === 200) {
                console.log(result);
            }

            else {
                // Error handling.
            }
        }
    }.bind(this));

    xhr.open("POST", "https://dev.api.temporal.cloud/v2/forgot/password");
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.send(data);
};

Example Response (200)

{
  // Need an example response.
}

https://dev.api.temporal.cloud/v2/forgot/password

Resets the password for the account with the associated email, sending it via email.

Parameters

FieldTypeDescription
email_addressStringThe e-mail address associated with your account.

POST forgot email

Golang code here.
Python code here.
handleForgotEmail => () => {

    let data = new FormData();
    data.append("email_address", email);

    let xhr = new XMLHttpRequest();
    xhr.withCredentials = false;

    xhr.addEventListener("readystatechange", function () {

        if (xhr.readyState === 4) {

            let result = JSON.parse(xhr.responseText);

            if (result.code === 200) {
                console.log(result);
            }

            else {
                // Error handling.
            }
        }
    }.bind(this));

    xhr.open("POST", "https://dev.api.temporal.cloud/v2/forgot/email");
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.setRequestHeader("Authorization", "Bearer " + <JWT>);
    xhr.send(data);
};

Example Response (200)

{
  // Need example response.
}

https://dev.api.temporal.cloud/v2/forgot/email

Returns the e-mail address associated with the JWT supplied.

IPFS Keys

POST generate ipfs key

Golang code here.
Python code here.
handleKeyGenerate = (keyName, keyType, keySize) => () => {

    let data = new FormData();
    data.append("key_name", keyName);
    data.append("key_type", keyType);
    data.append("key_bits", keySize);

    let xhr = new XMLHttpRequest();
    xhr.withCredentials = false;

    xhr.addEventListener("readystatechange", function () {

        if (xhr.readyState === 4) {

            let result = JSON.parse(xhr.responseText);

            if (result.code === 200) {
                console.log(result);
            }

            else {
                // Error handling.
            }
        }
    }.bind(this));

    xhr.open("POST", "https://dev.api.temporal.cloud/v2/account/key/ipfs/new");
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.setRequestHeader("Authorization", "Bearer " + <JWT>);
    xhr.send(data);
};

Example Response (200)

{
  "code": 200,
  "response": "key creation sent to backend"
}

https://dev.api.temporal.cloud/v2/account/key/ipfs/new

Create an IPFS key with the given parameters.

Parameters

FieldTypeDescription
key_typeStringThe type of the key, either RSA or ED25519.
key_sizeIntThe size of the key. RSA accepts 2048, 3072, or 4096 while ED25519 only accepts 256.
key_nameStringThe name of the key.

GET export ipfs key

Golang code here.
Python code here.
handleKeyExport = (keyName) => () => {

    let data = new FormData();
    let xhr = new XMLHttpRequest();
    xhr.withCredentials = false;

    xhr.addEventListener("readystatechange", function () {

        if (xhr.readyState === 4) {

            let result = JSON.parse(xhr.responseText);

            if (result.code === 200) {
                console.log(result);
            }

            else {
                // Error handling.
            }
        }
    }.bind(this));

    xhr.open("GET", "https://dev.api.temporal.cloud/v2/account/key/export/" + keyName);
    xhr.setRequestHeader("Cache-Control", "no-cache");
    xhr.setRequestHeader("Authorization", "Bearer " + <JWT>);
    xhr.send(data);
};

Example Response (200)

{
  "code": "200",
  "response": [
    "road",
    "carwash",
    "ambulance",
    "vehicle",
    "manhole",
    "explosion"
  ]
}

https://dev.api.temporal.cloud/v2/account/key/export/:name

Exports the mnemonic phrase associated with a given key.

Parameters

FieldTypeDescription
nameStringName of the key to export.

Response (200)

FieldTypeDescription
responseArray[String]An array of all words in the mnemonic phrase.

GET ipfs keys

Golang code here.
Python code here.
let xhr = new XMLHttpRequest();
xhr.withCredentials = false;

xhr.addEventListener("readystatechange", function () {

    if (xhr.readyState === 4) {

        let result = JSON.parse(xhr.responseText);

        if (result.code === 400) {
            // Error handling.
        }

        else if  (result.code === 200) {
            console.log(result);
        }

        else {
            // Error handling.
        }

    }
}.bind(this));

xhr.open("GET", "https://dev.api.temporal.cloud/v2/account/key/ipfs/get");
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Authorization", "Bearer " + <JWT>);
xhr.send();

Example Response (200)

{
  "code": 200,
  "response": {
    "key_ids": [
      "QmRxu16ho4kmak3ZFEwUuSQAHiLQoaanLeYa4R3LG2ozCg",
      "Qme3dCHims67ACrKXNoioP5ftr4tP1n1beaWCcJiTJYL1E",
      "QmNRcEwEmFK1jz6w58LS7TfxHsR42AinVdCbmqReXuAqWM",
      "12D3KooWRtMLutruxkjWkdTdkk96qyMvXtvLJDEUxdjyzQwj8HPS"
    ],
    "key_names": [
      "postables-ke2",
      "postables-muchkeysuchwow",
      "postables-1",
      "postables-key2019ED25519"
    ]
  }
}

https://dev.api.temporal.cloud/v2/account/key/ipfs/get

Retrieve all IPFS keys generated through Temporal.

Response (200)

FieldTypeDescription
key_idsIPFS HashThe hash of a key.
key_namesStringThe name of a key.

Utility

GET username from token

Golang code here.
Python code here.
let data = new FormData();
let xhr = new XMLHttpRequest();
xhr.withCredentials = false;

xhr.addEventListener("readystatechange", function () {

    if (xhr.readyState === 4) {

        let result = JSON.parse(xhr.responseText);

        if (result.code === 200) {
            console.log(result);
        }

        else {
            // Error handling.
        }
    }
}.bind(this));

xhr.open("GET", "https://dev.api.temporal.cloud/v2/account/token/username");
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Authorization", "Bearer " + Session.get('token'));
xhr.send(data);

Example Response (200)

{
  "code": 200,
  "response": "postables"
}

https://dev.api.temporal.cloud/v2/account/token/username

Returns the username associated with the current token (for validation purposes).

GET refreshed auth token

Golang code here.
Python code here.
let data = new FormData();
let xhr = new XMLHttpRequest();
xhr.withCredentials = false;

xhr.addEventListener("readystatechange", function () {

    if (xhr.readyState === 4) {

        let result = JSON.parse(xhr.responseText);

        if (result.code === 200) {
            console.log(result);
        }

        else {
            // Error handling.
        }
    }
}.bind(this));

xhr.open("GET", "https://dev.api.temporal.cloud/v2/auth/refresh");
xhr.setRequestHeader("Cache-Control", "no-cache");
xhr.setRequestHeader("Authorization", "Bearer " + Session.get('token'));
xhr.send(data);

Example Response (200)

{
  // Need example response.
}

https://dev.api.temporal.cloud/v2/auth/refresh

// Need description.