Network/wallet/tutorials/json-snippets

Below is a couple of useful JSON snippets for working with the wallet REST API.

The examples use the command line tool curl to talk to the service.

Please not that on Windows the commands must be put in a single line without breaks.

Creating a currency
This request creates a new currency. All currencies must be created before referred to in accounts and transactions.

curl -XPOST -H "Content-type: application/json" http://localhost:9091/wallet-service-rest/rest/currencies -d ' { "fractionalDigits" : 2, "code" : "EUR" }'

Create Account
Create a system account. Set it to allow negative balances. This type of account can be used a source for money that are "created" in the system.

For example when new funds are deposited by users. Then a transaction is made from this money factory account to the user's static account.

curl -XPOST -H "Content-type: application/json" http://localhost:9091/wallet-service-rest/rest/wallet/accounts -d ' {    "negativeBalanceAllowed" : true, "userId" : "1", "type" : "SYSTEM_ACCOUNT", "currencyCode" : "EUR" }'

Create a static account for a user. This account type normally used for users primary wallets. The balance should not be allowed to go negative. curl -XPOST -H "Content-type: application/json" http://localhost:9091/wallet-service-rest/rest/wallet/accounts -d ' {     "negativeBalanceAllowed" : false, "userId" : "2", "type" : "STATIC_ACCOUNT", "currencyCode" : "EUR" }'

List accounts
curl -XPUT -H "Content-type: application/json" http://localhost:9091/wallet-service-rest/rest/wallet/accounts -d ' { "statuses" : [], "types" : [], "offset" : 0, "limit" : 1000, "sortOrder" : "ID", "ascending" : false }'

Create Transaction
Create a transaction by moving funds from one account to another.

The transaction is described by entries. There must be at least 2 entries. The summary of the entries amounts must be zero.

curl -XPOST -H "Content-type: application/json" http://localhost:9091/wallet-service-rest/rest/wallet/transaction -d ' { "entry" : [ {     "accountId" : 1, "amount" : { "fractionalDigits" : 2, "amount" : -1234.56, "currency" : "EUR" }   },    {      "accountId" : 2, "amount" : { "fractionalDigits" : 2, "amount" : 1234.56, "currency" : "EUR" }   }  ],  "comment" : "test transaction" }'

List Transactions
curl -XPUT -H "Content-type: application/json" http://localhost:9091/wallet-service-rest/rest/wallet/transactions -d ' { "offset" : 0, "limit" : 1000, "order" : "ID", "ascending" : false }'