How to use postman to access the cardano api on Debian GNU/Linux Sid


#1

originally posted here

Cardano API

The api is described in detail here via the swagger generated HTML
https://cardanodocs.com/technical/wallet/api/

Postman

What is postman?

https://www.getpostman.com/ Postman is a user friendly GUI to manage API calls. It can be used to run rest api calls and inspect results.

Setup postman

Download the postman app from here
https://app.getpostman.com/app/download/linux64

Untar it

tar -xzf Postman-linux-x64-5.5.0.tar.gz

and run it

cd Postman/
./Postman 

Now first you want to turn off your ssl check for now
Go to menu File/Settings

Now turn off the SSL certificate verification

So that it looks like this
image

Swagger

What is swagger

https://swagger.io/ Swagger claims to be the most popular API framework. It allows you to describe your API in json manner and then generate HTML pages from that to invoke operations. Postman can consume it.

Where is the swagger URI for cardano?

The url is located here https://localhost:8090/swagger.json but postman cannot import it directly.

Here is how I import it

First I use the jq tool https://stedolan.github.io/jq/ to make the json pretty

curl -k https://localhost:8090/swagger.json | jq . > pretty.json

And then I replace the raw paths like “/api” with https://localhost:8090/api

sed -e's!\"/api!\"https://localhost:8090/api!g' pretty.json > localized.json

Note I could use jq to do this replacement but that is more work.

Then finally the parameters in postman can be sent via variables which you can specify with {{variablename}} but the swagger specifies them with {variable} name.

You first import the localized.json into postman


image

And then select the file localized.json you then want to save to postman v1 and edit the paths to change the ::variable name to {{variablename}} in the paths.

My resulting json file

My updated postman.json is here

Variables

Here are the variables you can find the api calls

There are three variables where the ADA address is sent

  • from From ADA address
  • to ADA address to send to
  • address an ADA address you want to send money to
  • transaction a transaction
  • passphrase your wallets passphrase

Setting variables

So next you want to setup an environment


Click on Manage environments.

Then add

Then name it my wallet, you can add in the variable names as empty above, or click on bulk edit

Then enter in these

walletId:
accountId:
amount:
from:
to:
address:
transaction:
passphrase:

It will look like this after saving

Now to fill out the variables, lets start by selecting the environment

And then lets start with this api call
https://localhost:8090/api/wallets

When you run that you will see the wallet ids and now you can select that to put into a variable like this
You select the text and then right click, you can store the value in a variable
In


this case select Mywallet.Walletid

Now confirm the values
image

You can then use variables to call the next api call
https://localhost:8090/api/wallets/{{walletId}}

So this shows you how to use postman to explore and use the cardano API.



Posted on Utopian.io - Rewarding Open Source Contributors

Swagger UI on running node (wallet)
What About the CLI *nix Wallet?
Cardano Wallet API v1 Beta (who has experience with this?)
Send/Broadcast tx endpoint in Cardano explorer api?