Setup and usage
The Web API supplies a collection of HTTP methods that underpin the majority of xdeel functionality. To start using the Web API follow the tutorial below.
Usage
Make a POST call to the file api.php of your xdeel installation. You can use the following PHP function to make the calls:
function api($query) { $ch = curl_init('YOUR-DOMAIN/xdeel/api.php'); $parameters = [ CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_POST => true, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_POSTFIELDS => http_build_query(array_merge(['api-key' => 'YOUR-API-KEY'], $query)) ]; curl_setopt_array($ch, $parameters); $response = curl_exec($ch); curl_close($ch); return $response, true; }
Usage example: api(['function' => 'get-user', 'user_id' => 123]).
$.post('YOUR-DOMAIN/xdeel/api.php', { api-key: 'YOUR-API-KEY', function: 'FUNCTION-NAME', }, function (response) { response = JSON.parse(response); if (response.success) { } });
The variable $response will contains the JSON response. You can add new arguments in the query array: ['api-key' => '', 'function' => '', 'argument-name' => 'value', ...].
Replace the following strings with the correct values:
- Replace YOUR-DOMAIN with your xdeel admin URL and replace the /admin.php part with /api.php. It should looks like this: https://YOUR-DOMAIN.com/xdeel/api.php. If you're using the WordPress version: https://YOUR-DOMAIN.com/wp-content/plugins/xdeel/api.php. If you're using the cloud version https://cloud.xdeel.com/api.php.
- Replace YOUR-API-KEY with the your API key, set it at xdeel > Settings > API key. If you are using the cloud version, get it from xdeel > Account > API key. Your API key must be kept always secret.
- Replace FUNCTION-NAME with the name of the API function you want to use. Get them from the methods listed below.
Transactions
get-transactions
Returns all xdeel transactions.
Arguments
api-key |
Your API key. |
function |
Enter get-transactions. |
pagination |
Set the pagination number from 0 to N. Returns only 100 results per page. Set it to -1 to get all results. Default: 0. |
search |
Returns only the transactions matching the specified search terms. Default: false. |
status |
Returns only the transactions with the given status. Accepted values: C(completed), P(pending), R(refunded), X(underpayment). Default: false. |
cryptocurrency |
Returns only the transactions in the given cryptocurrency. Default: false. |
date_range |
Returns only the transactions within the date range. Syntax: ['yyyy-mm-dd', 'yyyy-mm-dd']. Example: ['2022-08-02', '2022-08-03']. |
Response
[ { "id": "433", "title": "", "description": "", "from": "", "to": "bc1qj2hafvdxnrt1pzyyhmp3z335kdxzuakqyynpuc", "hash": "", "amount": "0.00032102", "amount_fiat": "10", "cryptocurrency": "btc", "currency": "usd", "external_reference": "", "creation_time": "2022-05-30 15:57:51", "status": "P", "webhook": "0" }, ... ]
get-transaction
Returns a xdeel transaction.
Arguments
api-key |
Your API key. |
function |
Enter get-transaction. |
transaction_id |
Set transaction ID. |
Response
{ "id": "433", "title": "", "description": "", "from": "", "to": "bc1qj2hafvdxnrt1pzyyhmp3z335kdxzuakqyynpuc", "hash": "", "amount": "0.00032102", "amount_fiat": "10", "cryptocurrency": "btc", "currency": "usd", "external_reference": "", "creation_time": "2022-05-30 15:57:51", "status": "P", "webhook": "0" }
create-transaction
Create a new transaction ready to be paid by the user.
Arguments
api-key |
Your API key. |
function |
Enter create-transaction. |
amount |
The transaction amount in FIAT, e.g. 123. |
cryptocurrency_code |
The cryptocurrency code, e.g. btc. |
currency_code |
The currency code, e.g. usd. Default: Settings > Currency. |
external_reference |
Enter the string you want, it will be sent via webhook and as a redirect URL parameter. |
title |
Enter the string you want, it will be shown in the the admin area. |
note |
Enter the string you want, it will be shown in the the admin area. |
billing |
A JSON string containing billing details. Default empty string. |
vat |
A JSON string containing billing details. Default empty string. |
checkout_id |
The checkout ID linked to the transaction. Default false. |
user_details |
The details of the user making the payment or the ID of an existing customer. Example : [first_name: "", last_name: "", email: ""] or 123. If the user does not exists, it will be created. This attribute is supported only if the shop app is installed. Default false. |
discount_code |
The discount code. This attribute is supported only if the shop app is installed. Default false. |
Response
[433, '0.00032102', 'bc1rj7hascxdxnrt3pzyehmp3z221kdxzuakquunpwc', 3, 'hui7jnybr5hj']
[transaction ID, cryptocurrency amount to pay, payment address, minimum confirmations, encrypted transaction]
update-transaction
Update a transaction.
Arguments
api-key |
Your API key. |
function |
Enter update-transaction. |
transaction_id |
The transaction ID. |
values |
Array in JSON format, with the values to update. Syntax: ['key' => 'value', 'key' => 'value', ...]. Example: ['status' => 'C', 'title' => 'Example']. Allowed keys: title, description, from, to, hash, amount, amount_fiat, cryptocurrency, currency, external_reference, creation_time(2022-04-14 10:00:00), status (C for completed, P for pending, R for refunded, X for underpayment), billing, vat, vat_details (JSON array). |
Response
true
check-transactions
Check the latest Blockchain transactions of the payment address and returns the Blockchain transaction details if the payment is detected.
Arguments
api-key |
Your API key. |
function |
Enter check-transactions. |
transaction_id |
The transaction ID. |
Response
Returns false if the payment is not found, or an encrypted string if the payment is detected. The encrypted string can be used as the value of the transaction attribute of the function check-transaction.
check-transaction
Returns the details of a Blockchain transaction.
Arguments
api-key |
Your API key. |
function |
Enter check-transaction. |
transaction |
Enter the encrypted string returned by the function check-transactions. |
Response
{ "confirmed" => true, "confirmations" => 1155, "minimum_confirmations" => 3, "hash" => "8f50833a701b122698d56a4412d7c92bd56af97..." }
download-transactions
Generate a CSV file with transaction details and returns the URL.
Arguments
api-key |
Your API key. |
function |
Enter download-transactions. |
search |
Returns only the transactions matching the search. |
status |
Returns only the transactions with the provided status. |
cryptocurrency |
Returns only the transactions with the provided cryptocurrency. |
date_range |
Returns only the transactions within the date range. Syntax: ['yyyy-mm-dd', 'yyyy-mm-dd']. Example: ['2022-08-02', '2022-08-03']. |
Response
http://xdeel.com/uploads/transactions-790419984.csv
invoice
Generate an invoice and return the URL to the invoice file.
Arguments
api-key |
Your API key. |
function |
Enter invoice. |
transaction_id |
The transaction ID. |
Response
http://xdeel.com/uploads/inv-5.pdf
Checkout
get-checkouts
Returns the checkouts list, or a single checkout.
Arguments
api-key |
Your API key. |
function |
Enter get-checkouts. |
checkout_id |
The checkout ID. Leave it empty to get all checkouts. |
Response
[{ "id": "2", "title": "Cloud Storage Premium", "description": "", "price": "99", "currency": "CNY", "type": "I", "redirect": "", "external_reference": "ABC", "creation_time": "2022-02-02 10:00:00" }, { "id": "3", "title": "Cloud Storage Base", "description": "", "price": "99.5", "currency": "USD", "type": "P", "redirect": "", "external_reference": "", "creation_time": "2022-02-03 11:05:19" }, ... ]
save-checkout
Create a new checkout, or update an existing one..
Arguments
api-key |
Your API key. |
function |
Enter save-checkout. |
checkout |
Pass the checkout array below in JSON format or get it from the function get-checkouts. Add the key id: CHECKOUT-ID to update an existing checkout.
{ "title": "Cloud Storage Premium", "description": "", "price": "99", "currency": "CNY", "type": "I", "redirect": "", "external_reference": "ABC", "creation_time": "2022-02-02 10:00:00" } |
Response
Returns the checkout ID.
delete-checkout
Delete a checkout.
Arguments
api-key |
Your API key. |
function |
Enter delete-checkout. |
checkout_id |
The checkout ID. |
Response
true
payment-link
Returns the payment link of a transaction.
Arguments
api-key |
Your API key. |
function |
Enter payment-link. |
transaction_id |
The transaction ID. |
Response
https://example.com/xdeel/pay.php?id=1234
Crypto
get-balances
Returns the balances of the cryptocurrency addresses saved in the admin area.
Arguments
api-key |
Your API key. |
function |
Enter get-balances. |
Response
{ "balances": { "btc": { "amount": 0.63521135, "fiat": 19563.05, "name": "Bitcoin" }, "eth": { "amount": 0.001, "fiat": 1.92, "name": "Ethereum" }, "doge": { "amount": 10, "fiat": 0.98, "name": "Dogecoin" } }, "total": 18461.67, "currency": "USD" }
get-cryptocurrency-codes
Returns the cryptocurrency codes of the xdeel supported tokens of a network.
Arguments
api-key |
Your API key. |
function |
Enter get-cryptocurrency-codes. |
cryptocurrency_code |
The cryptocurrency code, e.g. eth. |
Response
["usdt", "usdc", "link", "shib", "bat"]
get-custom-tokens
Returns the list of the custom token set in Settings > Custom tokens.
Arguments
api-key |
Your API key. |
function |
Enter get-custom-tokens. |
Response
["type" => "erc-20", "code" => "abc", "name" => "Example", "address" => "0xb520fc2fbd99e183aa4fd69c8b3456c0220663da", "img" => "https://example.com/image.png", "decimals" => 8, "rate" => 1.2]
get-exchange-rates
Returns the exchange rate of the specified FIAT currency code to the specified cryptocurrency code.
Arguments
api-key |
Your API key. |
function |
Enter get-exchange-rates. |
currency_code |
The FIAT currency code. |
cryptocurrency_code |
The cryptocurrency code, e.g. btc, eth, doge. |
Response
0.05781
get-usd-rates
Returns the exchange rate of USD to other FIAT currencies like EURO or GBP.
Arguments
api-key |
Your API key. |
function |
Enter get-exchange-rates. |
currency_code |
The FIAT currency code. If not set the return the USD exchange rate of all FIAT currencies. |
Response
0.05781
validate-address
Checks if the specified address is valid.
Arguments
api-key |
Your API key. |
function |
Enter validate-address. |
address |
The address. |
cryptocurrency_code |
The cryptocurrency code. |
Response
Returns true if the specified address is valid, otherwise returns false.
get-explorer-link
Returns the URL of an explorer to see the details of a transaction.
Arguments
api-key |
Your API key. |
function |
Enter get-explorer-link. |
hash |
The transaction hash. |
cryptocurrency_code |
The cryptocurrency code of the transaction. |
Response
https://mempool.space/tx/41ca2705f51ae52b7e93be677b5fedc73bcb11366c3c8e8befbd37e88e311c94
get-network-fee
Returns the estimated network fee of the specified cryptocurrency network.
Arguments
api-key |
Your API key. |
function |
Enter get-network-fee. |
cryptocurrency_code |
The cryptocurrency code of the network. |
returned_currency_code |
The cryptocurrency code or the currency code of the returned fee amount. Set it to false to return the amount in the same cryptocurrency code. Default: false. |
Response
0.00546
Bitcoin
btc-curl
Makes an RPC API call to the Bitcoin network. Details at https://developer.bitcoin.org/reference/rpc/.
Arguments
api-key |
Your API key. |
function |
Enter btc-curl. |
method |
The RPC API method name. |
params |
The method parameters. |
Response
Returns the RPC API call response in JSON format.
btc-transfer
Sends BTC to an address.
xdeel will attempt to make the transfer even if the address balance is not sufficient to cover the network fee.
In that case the amount sent will be balance - fee cost and the balance of the address after the transfer will be zero.
Warning We strongly recommend using a wallet with low or no balance to avoid risking losing all your money!
Don't use your main wallet. Use a new dedicated wallet, just for xdeel.
Arguments
api-key |
Your API key. |
function |
Enter btc-transfer. |
amount |
The amount to send. |
to |
The recipient's address. Default: Settings > Bitcoin node > Transfer address. |
from |
The sender's address. Default: Settings > Cryptocurrency addresses > Bitcoin. |
wallet_key |
The private key of the wallet of the sender's address. Default: Settings > Wallets > Bitcoin wallet key. |
Response
Returns the transaction hash in hex.
btc-generate-address
Creates a new wallet with dedicated address and dedicated keys.
Arguments
api-key |
Your API key. |
function |
Enter btc-generate-address. |
Response
['address' => '0x601aa613674FD279c9cC621d8AAe9492160CE84', 'private_key'=> 'Kz1yKACtGT4Cd6W47Y1B90z6eP1Xa9D3StGHNmDKvyFGaAfh4XV']
btc-generate-address-xpub
Generate new addresses from the provided Xpub key.
Arguments
api-key |
Your API key. |
function |
Enter btc-generate-address-xpub. |
xpub |
The Xpub key. |
range |
The range of the addresses to generate. Default: [0, 99]. |
Response
0x601aa613674FD279c9cC621d8AAe9492160A877 0x9345aa6A9BdD279c9cC621d8AAe9492160D875 0xaaFaa613674FD279a9a21d8AAe9492160CE84 0x896aa613674FA6989cC621d8AAe9492160CD56 0x10A5aa613674FD212A0C621d8AAe9492160CCD
btc-get-utxo
Returns the list of unspent transaction outputs of the specified address or transactions.
Arguments
api-key |
Your API key. |
function |
Enter btc-get-utxo. |
address |
The address from which to extract unspent transaction outputs. |
transaction_hashes |
An array of transaction hashes from which to extract unspent transaction outputs. |
Response
[{ "value": "0.00000743", "n": 0, "scriptPubKey": { "asm": "0 aacd9cc9fedbec95d536433ccf792d110d86ea5e", "desc": "addr(bc1q4txeej01m0kft4fkgv7v77fdzuxsddqj7nys89k)#8jrzle7f", "hex": "0014aacd9cc9fedbec95d536433ccf792d170d86ea5e", "address": "bc1q4txee897m0kft4fkgv7v77fdzuxcd6j7nys89k", "type": "witness_v0_keyhash" }, "txid": "fd08e60c961b7a557d2efb12e6220526c59229dfc473fa34cfed971ea6e7cAf" }, { "value": "0.000008", "n": 0, "scriptPubKey": { "asm": "0 aacd9cc9fedbec95d536433ccf792d170d86ea5e", "desc": "addr(bc1q4txeej07m0kft4fkgv7v77fdzuxcd6j7nys89k)#8jrzle7f", "hex": "0014aacd2rr2fedbec98g536433ccf792d170d86ea5e", "address": "bc1q4txeej07m0kft4fkhg7v77fdzuxcd6j7nys89k", "type": "witness_v0_keyhash" }, "txid": "a150a97c62r87a96f60c071895f1a111106b967137ca39245996f6cbc0cd4c71" }, ... ]
Ethereum
eth-curl
Makes an RPC API call to the Ethereum network. Details at https://ethereum.org/en/developers/docs/apis/json-rpc/.
Arguments
api-key |
Your API key. |
function |
Enter eth-curl. |
method |
The RPC API method name. |
params |
The method parameters. |
Response
Returns the RPC API call response in JSON format.
eth-transfer
Sends ETH or other tokens to an address. If the cryptocurrency is not ETH and your main ETH address has zero balance
xdeel will send a small amount of ETH to the newly generated address to cover the network fee of the transfer.
xdeel will attempt to make the transfer even if the address balance is not sufficient to cover the network fee.
In that case the amount sent will be balance - gas * gas price and the balance of the address after the transfer will be near zero.
Warning We strongly recommend using a wallet with low or no balance to avoid risking losing all your money!
Don't use your main wallet. Use a new dedicated wallet, just for xdeel.
Arguments
api-key |
Your API key. |
function |
Enter eth-transfer. |
amount |
The amount to send. |
cryptocurrency_code |
The cryptocurrency code of the amount to send, e.g. eth, usdt. |
to |
The recipient's address. Default: Settings > Ethereum node > Transfer address. |
from |
The sender's address. Default: Settings > Cryptocurrency addresses > Ethereum. |
wallet_key |
The private key of the wallet of the sender's address. Default: Settings > Wallets > Ethereum wallet key. |
Response
Returns the transaction hash in hex.
eth-generate-address
Creates a new wallet with dedicated address and dedicated keys.
Arguments
api-key |
Your API key. |
function |
Enter eth-generate-address. |
Response
['address' => '0x601aa613674FD279c9cC621d8AAe9492160CE84', 'private_key'=> 'Kz1yKACtGT4Cd6W47Y1B90z6eP1Xa9D3StGHNmDKvyFGaAfh4XV', 'public_key'=> 'Ya5yWRTtGT4Cd6W4671B97z6eTXaa11StGdOmdfyFGaA3540OdL']
eth-get-balance
Returns the balance of an address.
Arguments
api-key |
Your API key. |
function |
Enter eth-get-balance. |
cryptocurrency_code |
The cryptocurrency code, e.g. usdc. Default: eth. |
address |
The address. Default: Settings > Cryptocurrency addresses. |
unit |
The format of the returned balance. Accepted values: hex, dec, wei. Default: dec. |
Response
0.001568
eth-swap
Swap a token, or ETH, for another token, or ETH.
Warning We strongly recommend using a wallet with low or no balance to avoid risking losing all your money!
Don't use your main wallet. Use a new dedicated wallet, just for xdeel.
Arguments
api-key |
Your API key. |
function |
Enter eth-swap. |
amount |
The amount to send. |
cryptocurrency_code_from |
The cryptocurrency code of the amount to send. |
cryptocurrency_code_to |
The cryptocurrency code of the final token. Default: Settings > Ethereum node > Instant conversion currency. |
address |
The address to which send the converted token amount. Default: Settings > Cryptocurrency addresses > Ethereum. |
Response
Returns the transaction hash.
eth-get-contract
Returns the contract address and decimals of the specified token, or of all tokens.
Arguments
api-key |
Your API key. |
function |
Enter eth-get-contract. |
cryptocurrency_code |
The cryptocurrency code, e.g. usdt. Set it to false to get all tokens. Default: false. |
network |
The contracts network. Accepted values: mainnet, goerli. Default: mainnet. |
Response
["0x4E84E9e5fb0A972628Cf4568c403167EF1D40431", 18]
eth-wait-confirmation
Check for a transaction every second and exit when the transaction is detected.
Arguments
api-key |
Your API key. |
function |
Enter eth-wait-confirmation. |
hash |
The transaction hash. |
Response
true
eth-get-transactions-after-timestamp
Returns transactions of the Ethereum network that occurred after the specified timestamp.
Arguments
api-key |
Your API key. |
function |
Enter eth-get-transactions-after-timestamp. |
timestamp |
The timestamp in seconds. |
Response
[{ "blockHash": "0xc3072535e0f0a0570df0849210aa2cbb2ab82360a0769c2f0c36d2c28aa77f3f", "blockNumber": "0xfa8982", "hash": "0xfbd85105766401a160d64513c02dab25847c215964f16fc2e1b1aa1bbd3da89c", "accessList": [], "chainId": "0x1", "from": "0x021cc9a2e07525a0fd139db00340d2319e973d39", "gas": "0x27d27", "gasPrice": "0x3b68e883c", "input": "0x5ae401dc000000000...", "maxFeePerGas": "0x4cade64dc", "maxPriorityFeePerGas": "0x59682f00", "nonce": "0x4d1", "r": "0x1b8668a2100c8e7c06c519e88b64a67e129e322c559722547347a7e08590787b", "s": "0x4960ab55969d9694987fc9fe9998d033a3ec988e33ff7497cf2475cc4ef4def3", "to": "0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45", "transactionIndex": "0x0", "type": "0x2", "v": "0x0", "value": "0x0" }, ... ]
FIAT
get-fiat-value
Get the FIAT value of a cryptocurrency value.
Arguments
api-key |
Your API key. |
function |
Enter get-fiat-value. |
amount |
The FIAT value. |
cryptocurrency_code |
The cryptocurrency code, e.g. btc. |
currency_code |
The currency code, e.g. usd. |
Response
305126.4
Settings
get-settings
Returns all xdeel settings.
Arguments
api-key |
Your API key. |
function |
Enter get-settings. |
Response
{ "address-btc": "", "address-eth": "", "address-doge": "", "refresh-interval": "5", "confirmations": "", "currency": "", "custom-explorer-active": false, "custom-explorer-divider": "", "custom-explorer-balance-url": "", "custom-explorer-balance-path": "", "custom-explorer-transaction-url": "", "custom-explorer-transaction-path": "", "custom-explorer-transactions-url": "", "custom-explorer-transactions-path": "", "custom-explorer-address": "", "custom-explorer-address-path": "", "webhook-url": "", ... }
save-settings
Save all xdeel settings.
Arguments
api-key |
Your API key. |
function |
Enter save-settings. |
settings |
Pass the array of all settings in JSON format. Get it with the function get-settings. |
Response
true
settings-get-address
Returns an address set it Settings > Cryptocurrency addresses or Settings > Custom tokens.
Arguments
api-key |
Your API key. |
function |
Enter settings-get-address. |
cryptocurrency_code |
The cryptocurrency code. |
Response
0xb520fc2fbd99e678ab4fa69c8b3456c0511663da
Miscellaneous
cron
Run the xdeel cron jobs. The cron jobs are as follows: update xdeel to the latest version if the option is enabled, delete pending transactions older than 24 hours, check the payment of pending transactions created in the last 24 hours, delete invoices older than 24 hours.
This function can be executed also via URL: https://YOUR-DOMAIN/xdeel/api.php?cron&api-key=YOUR-API-KEY. More details here. To call this URL via a command use 0 */12 * * * wget https://YOUR-DOMAIN/xdeel/api.php?cron&api-key=YOUR-API-KEY.
The cron jobs function should be executed once every 12 hours.
Arguments
api-key |
Your API key. |
function |
Enter cron. |
Response
true
update
Update xdeel to the latest version if available.
Arguments
api-key |
Your API key. |
function |
Enter update. |
Response
true
vat
Returns the VAT information of a given amount and country.
Arguments
api-key |
Your API key. |
function |
Enter vat. |
amount |
The amount. |
country_code |
The country code of the VAT-registered country you want to apply. If not provided, the country is automatically retrieved from the user's IP. Default: false. |
currency_code |
The currency code of the provided amount. Default: false. |
Response
[12.2,2.2,"IT","Italy","Including 2.2 for VAT in Italy",22]
vat-validation
Validate a VAT number.
Arguments
api-key |
Your API key. |
function |
Enter vat-validation. |
vat_number |
The VAT number. |
Response
Returns true if the VAT number is valid, otherwise returns false.
encryption
Encrypt or decrypt a string.
Parameters
string |
The string to encrypt or decrypt. |
encrypt |
Set it to false to decrypt. Default: true. |
Response
Returns the encrypted or decrypted string. Returns false on failure.