Withdraw Savings
curl --request POST \
--url https://api.magebank.ai/savings/withdraw \
--header 'Content-Type: <content-type>' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"investmentId": "<string>"
}
'import requests
url = "https://api.magebank.ai/savings/withdraw"
payload = { "investmentId": "<string>" }
headers = {
"x-api-key": "<x-api-key>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<x-api-key>', 'Content-Type': '<content-type>'},
body: JSON.stringify({investmentId: '<string>'})
};
fetch('https://api.magebank.ai/savings/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/savings/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([
'investmentId' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: <content-type>",
"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/savings/withdraw"
payload := strings.NewReader("{\n \"investmentId\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<x-api-key>")
req.Header.Add("Content-Type", "<content-type>")
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/savings/withdraw")
.header("x-api-key", "<x-api-key>")
.header("Content-Type", "<content-type>")
.body("{\n \"investmentId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magebank.ai/savings/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"] = '<content-type>'
request.body = "{\n \"investmentId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "Withdrawal completed successfully.",
"withdrawalDetails": {
"principal": "1000.00",
"interest": "45.75",
"totalAmount": "1045.75",
"duration": {
"days": 30,
"hours": 5,
"minutes": 23
}
},
"transaction": {
"txHash": "0x123...abc",
"status": "completed"
},
"agentId": "agent_k77NTwxp2Ym3JCmVsKtXQA",
"updatedBalance": "1545.75"
}
{
"error": "Investment ID is required"
}
{
"error": "Investment not found"
}
{
"error": "Investment has already been completed or cancelled"
}
```json 401 Unauthorized
{
"error": "Invalid or missing API key"
}
{
"error": "Internal Server Error"
}
Savings
Withdraw Savings
Withdraw funds from a savings investment
POST
/
savings
/
withdraw
Withdraw Savings
curl --request POST \
--url https://api.magebank.ai/savings/withdraw \
--header 'Content-Type: <content-type>' \
--header 'x-api-key: <x-api-key>' \
--data '
{
"investmentId": "<string>"
}
'import requests
url = "https://api.magebank.ai/savings/withdraw"
payload = { "investmentId": "<string>" }
headers = {
"x-api-key": "<x-api-key>",
"Content-Type": "<content-type>"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<x-api-key>', 'Content-Type': '<content-type>'},
body: JSON.stringify({investmentId: '<string>'})
};
fetch('https://api.magebank.ai/savings/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/savings/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([
'investmentId' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: <content-type>",
"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/savings/withdraw"
payload := strings.NewReader("{\n \"investmentId\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<x-api-key>")
req.Header.Add("Content-Type", "<content-type>")
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/savings/withdraw")
.header("x-api-key", "<x-api-key>")
.header("Content-Type", "<content-type>")
.body("{\n \"investmentId\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.magebank.ai/savings/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"] = '<content-type>'
request.body = "{\n \"investmentId\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"message": "Withdrawal completed successfully.",
"withdrawalDetails": {
"principal": "1000.00",
"interest": "45.75",
"totalAmount": "1045.75",
"duration": {
"days": 30,
"hours": 5,
"minutes": 23
}
},
"transaction": {
"txHash": "0x123...abc",
"status": "completed"
},
"agentId": "agent_k77NTwxp2Ym3JCmVsKtXQA",
"updatedBalance": "1545.75"
}
{
"error": "Investment ID is required"
}
{
"error": "Investment not found"
}
{
"error": "Investment has already been completed or cancelled"
}
```json 401 Unauthorized
{
"error": "Invalid or missing API key"
}
{
"error": "Internal Server Error"
}
Complete Withdrawal: Closes an active investment and returns the principal plus earned interest to the agentās wallet.
Request Headers
string
required
Your API key for authentication
string
required
Must be set to
application/jsonRequest Body
string
required
The short ID or UUID of the investment
Response
boolean
Whether the withdrawal was successful
string
Information about the withdrawal
object
Show properties
Show properties
string
Original amount invested
string
Interest earned during the investment period
string
Total amount withdrawn (principal + interest)
object
string
The ID of the agent that owned the investment
string
New balance of the agent after the withdrawal
{
"success": true,
"message": "Withdrawal completed successfully.",
"withdrawalDetails": {
"principal": "1000.00",
"interest": "45.75",
"totalAmount": "1045.75",
"duration": {
"days": 30,
"hours": 5,
"minutes": 23
}
},
"transaction": {
"txHash": "0x123...abc",
"status": "completed"
},
"agentId": "agent_k77NTwxp2Ym3JCmVsKtXQA",
"updatedBalance": "1545.75"
}
{
"error": "Investment ID is required"
}
{
"error": "Investment not found"
}
{
"error": "Investment has already been completed or cancelled"
}
```json 401 Unauthorized
{
"error": "Invalid or missing API key"
}
{
"error": "Internal Server Error"
}
Status Codes
| Status Code | Description |
|---|---|
| 200 | Withdrawal completed successfully |
| 400 | Bad Request - Invalid or missing parameters |
| 401 | Unauthorized - Invalid or missing API key |
| 404 | Not Found - Investment not found |
| 500 | Internal Server Error |
Active Investments Only: Only investments with an āactiveā status can be withdrawn. Attempting to withdraw completed or cancelled investments will result in an error.
Interest Calculation: Interest is calculated up to the exact moment of withdrawal, including partial days.
Blockchain Confirmation: The transaction may take a few moments to be confirmed on the blockchain before the funds appear in the agentās wallet.