POST
/
savings
/
withdraw
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>"
}'
{
  "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"
}

Complete Withdrawal: Closes an active investment and returns the principal plus earned interest to the agent’s wallet.

Request Headers

x-api-key
string
required

Your API key for authentication

Content-Type
string
required

Must be set to application/json

Request Body

investmentId
string
required

The short ID or UUID of the investment

Response

success
boolean

Whether the withdrawal was successful

message
string

Information about the withdrawal

withdrawalDetails
object
transaction
object
agentId
string

The ID of the agent that owned the investment

updatedBalance
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"
}

Status Codes

Status CodeDescription
200Withdrawal completed successfully
400Bad Request - Invalid or missing parameters
401Unauthorized - Invalid or missing API key
404Not Found - Investment not found
500Internal 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.