API Documents

Overview

MilaCoins provide a payment gateway and business wallet that allows merchants to automate the processes of accepting cryptocurrency payments and payouts from their customers, as well as making currency exchange transactions and receiving data on the transaction history and account balance status for reporting. developer also can call MilaCoins API directly over HTTPS using JSON requests.

Environment

In addition to the Production environment, MilaCoins also provides developers with a test environment, also known as Sandbox. The SandBox environment is exactly like the Production environment. The only difference between the Production and Sandbox environment is that the latter uses test networks (testnets).

The Sandbox Environment and the Production Environment are independent environments and are not connected to each other in any way.

Sandbox Base URL - https://sandbox-api.milacoins.com

Production Base URL - https://api.milacoins.com

Authentication

All API requests must be made over HTTPS, Please note that plain HTTP will be refused. You must include your X-headers in all requests.

The X-headers:

  • X-api-key an API Key that you generate in our backoffice

  • X-Sig signature of the request in the hex format (See "Signing a request" below)

  • X-time number of seconds since Unix Epoch in UTC

Api Keys

  • You can generate API Keys in your profile->Security->API for test and production environments.
  • Secret key values are shown only once upon key creation.
  • Next, you will be asked to add IP addresses that are allowed to use these keys.

Signing a request

The value of the X-Sig is generated by a sha256 HMAC algorithm with a secret key. It contains the following information:

  • A timestamp (value of the X-time header in Seconds!) taken as a string
  • An HTTP request method name in upper-case, GET | POST
  • Endpoint (URL of the request without a host name), starting with a slash and including all query parameters, example : /transactions?from=2020-1-1&to=2022-1-1
  • Request body, taken exactly as it will be sent. If there is no request body like GET requests, don't include it
  • Example of the string to be signed to get a signature Header Aka X-sig: 1618832932.344GET/transactions/?from=2020-1-1&to=2022-1-1

Signing Function Example

const axios = require('axios'),
  crypto = require('crypto'),
  baseUrl = process.env.MILACOINS_BASE_URL,
  apiKey = process.env.MILACOINS_API_KEY,
  secretKey = process.env.MILACOINS_SECRET_KEY;

async function request(endPoint, { method = 'GET', body } = {}) {
  const options = {
      url: `${baseUrl}${endPoint}`,
      method,
      data: body,
      headers: {}
    },
    time = Math.round(Date.now() / 1000),
    hmacSha256 = crypto.createHmac('sha256', secretKey);
  hmacSha256.update(time + options.method.toUpperCase() + endPoint);
  if (options.data) {
    options.data = JSON.stringify(options.data);
    hmacSha256.update(Buffer.from(options.data, 'utf-8'));
  }

  options.headers.Accept = 'application/json';
  options.headers['Content-Type'] = 'application/json';
  options.headers['X-api-key'] = apiKey;
  options.headers['X-time'] = time;
  options.headers['X-Sig'] = hmacSha256.digest('hex');

  try {
    const { data } = await axios(options);
    return data;
  } catch (err) {
    if (err.response && err.response.data) throw err.response.data;
    else throw new Error('unknown error');
  }
}

Libraries

MilaCoins maintains server-side API libraries in various programming languages that are available via popular package managers.

Node.js

To install the NPM Package, go to https://www.npmjs.com/package/milauth

Python

To install the Python Package, go to https://pypi.org/project/milauth

Postman Collection

To download the Postman collection (v2.1), click-here

For more instructions on Postman, please visit this section.

Logs

Get Http Logs

GET
/api/logs/

Request Query string:

Field Description
limit  

Limit of documents for response. default:100 , max:500

page  

Page-numbering is based on the value of limit. If limit=20, then page=1 will display the docs from 1 to 20, page=3 will display the docs from 41 to 60. (default:1)

Response (JSON):

Field Type Description
count Number
limit Number
skip Number
docs Array (objects)
  --id String
  --status Number
  --ip String
  --method String
  --uri String
  --device Any
  --headers Any
  --location Any
  --body Any
  --params Any
  --query Any
  --response Any
  --error String
  --createdAt String

Get Http Log By Id

GET
/api/logs/:id

Request Parameters (URL):

Field Type Required
id string Required

Response (JSON):

Field Type Description
id String
status Number
ip String
method String
uri String
device Any
headers Any
location Any
body Any
params Any
query Any
response Any
error String
createdAt String

Info

Get Supported Currencies

GET
/api/v1/info/supportedCurrencies

Response (JSON):

Field Type Description
currencies Array (string)

Get Supported wallets

GET
/api/v1/info/supportedWallets

Response (JSON):

Field Type Description
wallets Array (string)

Transactions

Create Checkout

POST
/api/v1/transactions/invoices/checkout

Request Body (JSON):

Field Type Required Description
wallet string Required Wallet (currency code ISO 4217) you wish to receive payments to. options: click here
amount number Required Invoice amount. (number)
currency string Required Invoice currency. (ISO 4217), options: click here
externalID string No Name of the customer or contains unique record identifiers from your system
expiredAt string No Invoice expiration Time

Response (JSON):

Field Type Description
id String
wallet String
amount Number
currency String
externalID String
url String
expiredAt Number
createdAt Number

Create Widget

POST
/api/v1/transactions/invoices/widget

Request Body (JSON):

Field Type Required Description
wallet string Required Wallet (currency code ISO 4217) you wish to receive payments to. options: click here
amount number Required Invoice amount. (number)
currency string Required Invoice currency. (ISO 4217) options: click here
externalID string No Name of the customer or contains unique record identifiers from your system
cancelUrl string Required Redirect url on cancel payment or error, include {INVOICE_ID} and {EXTERNAL_ID} in the URL to dynamically pass through parameters
completedUrl string Required Redirect url on complete payment, include {INVOICE_ID} and {EXTERNAL_ID} in the URL to dynamically pass through parameters
callbackUrl string No Callback url to get events, include {EVENT},{INVOICE_ID} and {EXTERNAL_ID} in the URL to dynamically pass through parameters. events options: cancel,complete
customerEmail string No Customer Email, will show on the payment page
customerLastName string No Customer Last Name, will show on the payment page
customerFirstName string No Customer First Name, will show on the payment page

Response (JSON):

Field Type Description
id String
wallet String
amount Number
currency String
externalID String
url String
expiredAt Number
createdAt Number

Get Invoices

GET
/api/v1/transactions/invoices/

Request Query string:

Field Description
limit  

Limit of documents for response. default:100 , max:500

page  

Page-numbering is based on the value of limit. If limit=20, then page=1 will display the docs from 1 to 20, page=3 will display the docs from 41 to 60. (default:1)

from  

ISO 8601 date format.

to  

ISO 8601 date format.

wallet  

Wallet currency code (ISO 4217).

externalID  

Customer name or contains unique record identifiers from your system.

status  

Status or list of statuses separate by comma. example: (new,completed) emun: init,completed,invalid,new,waitingForConfirmation,underPaid,overPaid,paidLate.

type  

Valid values: widget OR checkout. 'checkout' is invoice link that generated on MineCoins backoffice, 'widget' is invoice that ganarated by payment button.

Response (JSON):

Field Type Description
count Number
limit Number
skip Number
docs Array (objects)
  --id String
  --receiptID Number
  --type String
  --status String
  --refund Object
  --  --id String
  --  --status String
  --  --network String
  --  --amount Number
  --  --agent String
  --  --createdAt String
  --  --address String
  --  --txID String
  --invoiceCurrency String
  --invoiceAmount Number
  --wallet String
  --walletCredited Number
  --network String
  --networkAmountReceived Number
  --exchangeRate Object
  --  --base String
  --  --quote String
  --  --rate Number
  --address String
  --txs Array (string)
  --externalID String
  --customer Object
  --  --firstName String
  --  --lastName String
  --  --email String
  --createdAt String

Get Invoice By Id

GET
/api/v1/transactions/invoices/:id

Request Parameters (URL):

Field Type Required
id string Required

Response (JSON):

Field Type Description
id String
receiptID Number
type String
status String
refund Object
  --id String
  --status String
  --network String
  --amount Number
  --agent String
  --createdAt String
  --address String
  --txID String
invoiceCurrency String
invoiceAmount Number
wallet String
walletCredited Number
network String
networkAmountReceived Number
exchangeRate Object
  --base String
  --quote String
  --rate Number
address String
txs Array (string)
externalID String
customer Object
  --firstName String
  --lastName String
  --email String
createdAt String

Errors

MilaCoins API uses HTTP status to indicate the success or failure responses. Status that bigger then 400 will indicate has error.

Error response example:

{
  "requestID": "62d956eda0a3bf0730f5fd18",
  "name": "DOCUMENT_NOT_FOUND",
  "message": "No Invoice found with that ID (id:62d8df9142d15eaa837f8ace)",
  "code": 1604
}

Errors list:

HTTP code Error Code Message Description
401 1603 Please provide a valid ID PROVIDE_ID
404 1604 No Document found with that ID ("id") DOCUMENT_NOT_FOUND
401 1600 Invalid "patch": "value". DB_CAST
401 1601 Already exist. DB_DUPLICATE
401 1602 Invalid input data. DB_INVALID_INPUT
404 404 Not Found NOT_FOUND
429 4302 Too many requests, please try again later. LIMIT_ERROR
403 4303 X-time hadear is invalid: INVALID_TIME
403 4304 Fail to Authentication: Check the api key, the secret key and the sign function FAIL_TO_AUTH
403 4301 "ip" ip not allowed IP_WHITE_LIST
401 1001 "filed name" Filed: Incorrect type, required: "type", but got:"type" VALIDATION_REQUEST_INCORRECT_TYPE
401 1002 "filed name" Filed: not allowed on this request VALIDATION_REQUEST_ALLOWED_FILED
401 1003 "filed name" Filed: is required VALIDATION_REQUEST_FILED_REQUIRED
401 1004 "value" is not a valid enum value for filed "filed name". Valid values: "valid values list" VALIDATION_REQUEST_ENUM_VALUE
401 1005 "status" is not a valid status. Valid statuses: "statuses list" VALIDATION_REQUEST_ENUM_STATUS
401 1006 "wallet" is not a valid wallet. Valid wallets: "wallets list" VALIDATION_REQUEST_ENUM_WALLETS
401 1007 "currency" is not a valid currency. Valid currencies: AED,MYR,BRL,EUR,USD,GBP,ILS,JPY,RUB,TRY,UAH,NZD VALIDATION_REQUEST_ENUM_CURRENCY

Postman

Postman is an API Collaboration Platform.

MilaCoins now offers Postman Collection for quick and easy usage of our REST APIs.

How to import Collection

  • Download the Collection. (click-here)
  • Import the Collection into the Postman app.

How to use Postman

  • Open the Postman app.

  • Click the Import button.

  • On the MilaCoins-API on the left side-bar. When it’s open, in Variables you'll need to set:

  • apiBaseUrl Production / Sandbox environment.

  • api-key generated from your profile.

  • secret-key generated from your profile.

logo
API Documentation