Withdraw from Agent
curl --request POST \
--url https://api.magebank.ai/agents/withdraw \
--header 'Content-Type: application/json' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"userid": "<string>",
"agentid": "<string>",
"amount": 123,
"currency": "<string>"
}
'import requests
url = "https://api.magebank.ai/agents/withdraw"
payload = {
"userid": "<string>",
"agentid": "<string>",
"amount": 123,
"currency": "<string>"
}
headers = {
"x-api-key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<x-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({userid: '<string>', agentid: '<string>', amount: 123, currency: '<string>'})
};
fetch('https://api.magebank.ai/agents/withdraw', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magebank.ai/agents/withdraw",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'userid' => '<string>',
'agentid' => '<string>',
'amount' => 123,
'currency' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.magebank.ai/agents/withdraw"
payload := strings.NewReader("{\n \"userid\": \"<string>\",\n \"agentid\": \"<string>\",\n \"amount\": 123,\n \"currency\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<x-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.magebank.ai/agents/withdraw")
.header("x-api-key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"userid\": \"<string>\",\n \"agentid\": \"<string>\",\n \"amount\": 123,\n \"currency\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magebank.ai/agents/withdraw")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"userid\": \"<string>\",\n \"agentid\": \"<string>\",\n \"amount\": 123,\n \"currency\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"txHash": "0x123...abc",
"message": "Successfully withdrew 50 USDC from agent to user",
"updatedBalance": "50"
}
{
"error": "userid, agentid, and amount are required."
}
{
"error": "Invalid withdraw amount"
}
{
"error": "Insufficient balance"
}
{
"error": "Agent not found"
}
{
"success": false,
"error": "Transfer failed on-chain"
}
Agents
Withdraw from Agent
Withdraw funds from an agent’s wallet
POST
/
agents
/
withdraw
Withdraw from Agent
curl --request POST \
--url https://api.magebank.ai/agents/withdraw \
--header 'Content-Type: application/json' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"userid": "<string>",
"agentid": "<string>",
"amount": 123,
"currency": "<string>"
}
'import requests
url = "https://api.magebank.ai/agents/withdraw"
payload = {
"userid": "<string>",
"agentid": "<string>",
"amount": 123,
"currency": "<string>"
}
headers = {
"x-api-key": "<x-api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<x-api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({userid: '<string>', agentid: '<string>', amount: 123, currency: '<string>'})
};
fetch('https://api.magebank.ai/agents/withdraw', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.magebank.ai/agents/withdraw",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'userid' => '<string>',
'agentid' => '<string>',
'amount' => 123,
'currency' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <x-api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.magebank.ai/agents/withdraw"
payload := strings.NewReader("{\n \"userid\": \"<string>\",\n \"agentid\": \"<string>\",\n \"amount\": 123,\n \"currency\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<x-api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.magebank.ai/agents/withdraw")
.header("x-api-key", "<x-api-key>")
.header("Content-Type", "application/json")
.body("{\n \"userid\": \"<string>\",\n \"agentid\": \"<string>\",\n \"amount\": 123,\n \"currency\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magebank.ai/agents/withdraw")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<x-api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"userid\": \"<string>\",\n \"agentid\": \"<string>\",\n \"amount\": 123,\n \"currency\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"txHash": "0x123...abc",
"message": "Successfully withdrew 50 USDC from agent to user",
"updatedBalance": "50"
}
{
"error": "userid, agentid, and amount are required."
}
{
"error": "Invalid withdraw amount"
}
{
"error": "Insufficient balance"
}
{
"error": "Agent not found"
}
{
"success": false,
"error": "Transfer failed on-chain"
}
Withdrawal Process: Transfers funds from the agent’s wallet to the user’s wallet. The operation includes: 1. Verification of user and agent existence 2. Validation of withdrawal amount against available balance 3. Transfer of funds on blockchain 4. Update of agent balance in database 5. Creation of transaction record
Request Headers
string
required
Your API key for authentication
Request Body
string
required
ID of the user receiving the withdrawal
string
required
ID of the agent sending the funds
number
required
Amount to withdraw
string
default:"USDC"
Currency type to withdraw (defaults to USDC)
Response
boolean
Whether the withdrawal was successful
string
Transaction hash on the blockchain
string
Information about the withdrawal
string
New balance of the agent after the withdrawal
{
"success": true,
"txHash": "0x123...abc",
"message": "Successfully withdrew 50 USDC from agent to user",
"updatedBalance": "50"
}
{
"error": "userid, agentid, and amount are required."
}
{
"error": "Invalid withdraw amount"
}
{
"error": "Insufficient balance"
}
{
"error": "Agent not found"
}
{
"success": false,
"error": "Transfer failed on-chain"
}
Status Codes
| Status Code | Description |
|---|---|
| 200 | Funds withdrawn successfully |
| 400 | Invalid request parameters |
| 404 | Not Found |
| 500 | Transaction failed |
Balance Requirement: The agent must have sufficient balance to complete the withdrawal. The transaction will fail if the requested amount exceeds the available balance.
Blockchain Transaction: This operation creates an on-chain transaction which may take a few moments to be confirmed depending on network conditions.