Top-up wallet
Route
POST
/api/v1/wallet_transactions
Usage
- Curl
- Python
- Ruby
- Javascript
- Go
- C#
- PHP
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
curl --location --request POST "$LAGO_URL/api/v1/wallet_transactions" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"wallet_transaction": {
"wallet_id": "12345",
"paid_credits": "20.0",
"granted_credits": "10.0"
}
}'
from lago_python_client.client import Client
from lago_python_client.exceptions import LagoApiError
from lago_python_client.models import WalletTransaction
client = Client(api_key='__YOUR_API_KEY__')
transaction = WalletTransaction(
wallet_id='12345',
paid_credits='20.0',
granted_credits='10.0'
)
try:
client.wallet_transactions.create(transaction)
except LagoApiError as e:
repair_broken_state(e) # do something on error or raise your own exception
require 'lago-ruby-client'
client = Lago::Api::Client.new({api_key: '__YOUR_API_KEY__'})
client.wallet_transactions.create({
wallet_id: '12345',
paid_credits: '20.0',
granted_credits: '10.0'
})
await client.walletTransactions.createWalletTransaction({
walletTransaction: {
walletId: "12345",
paidCredits: 20.0,
grantedCredits: 10.0,
},
});
import "fmt"
import "github.com/getlago/lago-go-client"
func main() {
lagoClient := lago.New().
SetApiKey("__YOUR_API_KEY__")
walletTransactionInput := &lago.WalletTransactionInput{
WalletId: "12345",
PaidCredits: "20.0"
GrantedCredits: "10.0",
}
transactions, err := lagoClient.WalletTransaction().Create(walletTransactionInput)
if err != nil {
// Error is *lago.Error
panic(err)
}
// wallet is *lago.Wallet
fmt.Println(transactions)
}
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;
namespace Example
{
public class CreateWalletTransactionExample
{
public static void Main()
{
Configuration.Default.BasePath = "https://api.getlago.com/api/v1";
// Configure HTTP bearer authorization: bearerAuth
Configuration.Default.AccessToken = "YOUR_ACCESS_TOKEN";
var apiInstance = new WalletsApi(Configuration.Default);
var walletTransactionInput = new WalletTransactionInput(); // WalletTransactionInput | Wallet transaction payload
try
{
// Create a new wallet transaction
WalletTransaction result = apiInstance.CreateWalletTransaction(walletTransactionInput);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling WalletsApi.CreateWalletTransaction: " + e.Message );
Debug.Print("Status Code: "+ e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure Bearer authorization: bearerAuth
$config = OpenAPI\Client\Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$apiInstance = new OpenAPI\Client\Api\WalletsApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client(),
$config
);
$wallet_transaction_input = new \OpenAPI\Client\Model\WalletTransactionInput(); // \OpenAPI\Client\Model\WalletTransactionInput | Wallet transaction payload
try {
$result = $apiInstance->createWalletTransaction($wallet_transaction_input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling WalletsApi->createWalletTransaction: ', $e->getMessage(), PHP_EOL;
}
Arguments
{
"wallet_transaction": {
"wallet_id": "12345",
"paid_credits": "20.0",
"granted_credits": "10.0"
}
}
Attributes | Type | Description |
---|---|---|
wallet_id | String Required | Wallet ID |
paid_credits | String Optional (This field is required only if there is no granted credits) | Paid credits. |
granted_credits | String Optional (This field is required only if there is no paid credits) | Granted (free) credits. |
Responses
- HTTP 200
- HTTP 400
- HTTP 401
- HTTP 422
The wallet transactions were created
Returns a wallet_transaction List.
{
"status": 400,
"error": "Bad Request"
}
The wallet_transaction
json root is not present in the request body.
{
"status": 401,
"error": "Unauthorized"
}
Access to the API endpoint is unhautorized.
Possible reasons are:
- The
Authorization
header is missing - The
Authorization
header does not contain the API key - The Api key is invalid or expired
{
"status": 422,
"error": "Unprocessable entity",
"code": "validation_errors",
"error_details": {
"field": ["error"]
}
}
Possible errors:
field | error | description |
---|---|---|
wallet_id | wallet_not_found | Wallet was not found |
wallet_id | wallet_is_terminated | Wallet is terminated |
paid_credits | invalid_paid_credits | paid_credits is not a valid amount |
granted_credits | invalid_granted_credits | granted_credits is not a valid amount |