Skip to content

Configuring your API

After creating an API, you can make updates to it (e.g., its name, API credentials, documentation, earning details, etc):

  1. Enter the API portal.
  2. Link the wallet that owns your API.
  3. Click "My APIs".
  4. Click the API you want to update.
  5. Click "Edit" and follow the dialogs (this stage requires re-authorisation).

Setting you earnings rate

Dhali currently supports setting your earnings per request or per second. In addition, we allow API providers to apply surcharging (i.e., dynamic pricing).

Surcharging

Dhali allows API providers to apply dynamic pricing. This is in addition to the base per-second and per-request earning types. A basic example can be found here. To enable surcharging, edit your API and select a non-zero maximum surcharge value. The general flow of surcharging is:

  • A user accesses your surcharge enabled API through Dhali.
  • Dhali forwards the request, adding the header X-Payment-Claim-Surcharge-Currency, which is a base 64 encoded string taking the decoded form:
{
   "schema": (string) A version,
   "networkType": (string) The payment network type, e.g., XRPL,
   "networkID": (int, required) For XRPL-like networks, we use these IDs: https://docs.xahau.network/technical/protocol-reference/transactions/transaction-common-fields#networkid-field,
   "code" : (string) The currency code the API earns, e.g., XRP,
   "scale": (int) The currency's scale, e.g., 6,
   "maxAmount": (int) The maximum amount this API allows to be surcharged,
   "issuer": (string, optional) The identifier of a token issuer,
}
  • The linked API responds to Dhali with the header X-Payment-Claim-Surcharge, which must be a base 64 encoded string taking the decoded form:
    {
       "schema": (string, required) A version,
       "amount": (unsigned int) The amount to surcharged, measured in the code/scale pair from 2.
    }
    

Encoding and decoding surcharge headers

Below are JavaScript examples of how X-Payment-Claim-Surcharge-Currency and X-Payment-Claim-Surcharge headers should be encoded when placed into the header:

const data = { key: "value", number: 123 };
const jsonString = JSON.stringify(data);
const base64EncodedString = Buffer.from(jsonString).toString('base64');
And can be decoded as follows:
const decodedBytes = Buffer.from(base64EncodedString, 'base64');
const decodedJsonString = decodedBytes.toString('utf-8');
const originalData = JSON.parse(decodedJsonString);
console.log(originalData);