Create wallet
Route
POST
/api/v1/wallets
Usage
- Curl
- Python
- Ruby
- Node.js
- Go
- C#
- PHP
LAGO_URL="https://api.getlago.com"
API_KEY="__YOUR_API_KEY__"
curl --location --request POST "$LAGO_URL/api/v1/wallets" \
--header "Authorization: Bearer $API_KEY" \
--header 'Content-Type: application/json' \
--data-raw '{
"wallet": {
"name": "wallet_name",
"rate_amount": "1.5",
"paid_credits": "20.0",
"granted_credits": "10.0",
"currency": "USD",
"expiration_at": "2022-07-07",
"external_customer_id": "12345"
}
}'
from lago_python_client import Client
from lago_python_client.models import Wallet
client = Client(api_key='__YOUR_API_KEY__')
wallet = Wallet(
name='wallet_name',
rate_amount='1.5',
paid_credits='20.0',
granted_credits='10.0',
currency='USD',
expiration_at='2022-07-07T23:59:59Z',
external_customer_id='12345'
)
client.wallets().create(wallet)
require 'lago-ruby-client'
client = Lago::Api::Client.new({api_key: '__YOUR_API_KEY__'})
client.wallets.create({
name: 'wallet_name',
rate_amount: '1.5',
paid_credits: '20.0',
granted_credits: '10.0',
currency: 'USD',
expiration_at: '2022-07-07T23:59:59Z',
external_customer_id: '12345'
})
import Wallet from 'lago-nodejs-client/wallet'
let client = new Client('__API_KEY__')
let wallet = new Wallet({
name: 'wallet_name',
rate_amount: '1.5',
paid_credits: '20.0',
granted_credits: '10.0',
expiration_at: '2022-07-07T23:59:59Z',
external_customer_id: '12345'
})
await client.createWallet(wallet);
import "fmt"
import "github.com/getlago/lago-go-client"
func main() {
lagoClient := lago.New().
SetApiKey("__YOUR_API_KEY__")
walletInput := &lago.WalletInput{
Name: "Wallet Name",
RateAmount: "1.5",
PaidCredits: "20.0"
GrantedCredits: "10.0",
Currency: "USD",
ExpirationAt: "2022-07-07T23:59:59Z",
ExternalCustomerId: "12345",
}
wallet, err := lagoClient.Wallet().Create(walletInput)
if err != nil {
// Error is *lago.Error
panic(err)
}
// wallet is *lago.Wallet
fmt.Println(wallet)
}
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;
namespace Example
{
public class CreateWalletExample
{
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 walletInput = new WalletInput(); // WalletInput | Wallet payload
try
{
// Create a new wallet
Wallet result = apiInstance.CreateWallet(walletInput);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling WalletsApi.CreateWallet: " + 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_input = new \OpenAPI\Client\Model\WalletInput(); // \OpenAPI\Client\Model\WalletInput | Wallet payload
try {
$result = $apiInstance->createWallet($wallet_input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling WalletsApi->createWallet: ', $e->getMessage(), PHP_EOL;
}
Arguments
{
"wallet": {
"name": "wallet_name",
"rate_amount": "1.5",
"paid_credits": "20.0",
"granted_credits": "10.0",
"currency":"USD",
"expiration_at": "2022-07-07T23:59:59Z",
"external_customer_id": "12345"
}
}
Attributes | Type | Description |
---|---|---|
name | String Optional | Wallet name |
rate_amount | String Required | Rate between credits and the amount in given currency |
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. |
currency | String Required | Currency. |
expiration_at | String Optional ISO 8601 datetime in UTC | Date and time that determines when the wallet will expire. |
external_customer_id | String Required | External customer ID. |
Deprecated arguments
Attributes | Type | Description |
---|---|---|
expiration_date | String Optional | Date that determines when the wallet will expire. Replaced by expiration_at. Value will be converted to "end_of_day" |
Responses
- HTTP 200
- HTTP 400
- HTTP 401
- HTTP 422
The wallet was created
Returns a wallet object.
{
"status": 400,
"error": "Bad Request"
}
The wallet
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 |
---|---|---|
customer | customer_not_found | Provided customer was not found |
customer | wallet_already_exists | A wallet is already attached to the customer |
paid_credits | invalid_paid_credits | paid_credits is not a valid amount |
granted_credits | invalid_granted_credits | granted_credits is not a valid amount |