How to use and explore the cardano api from postman via the swagger.json on Debian/Sid 64bit GNU/Linux

in #utopian-io7 years ago (edited)

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
image

Now turn off the SSL certificate verification
image

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
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
https://github.com/h4ck3rm1k3/cardano-sl/blob/master/wallet-new/spec/Cardano%20SL%20Wallet%20Web%20API.postman_collection.json

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
image
Click on Manage environments.

Then add
image

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

Then enter in these

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

It will look like this after saving
image

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

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

image

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
Inimage
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}}
image

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



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Very informative tutorials. Detailed and precise, that's what I like. It will come in handy when I look into Cardano. I as well as many here do appreciate your contribution.

JGV

Hey @h4ck3rm1k3st33m I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

good job dear @h4ck3rm1k3st33m

@resteemator is a new bot casting votes for its followers. Follow @resteemator and vote this comment to increase your chance to be voted in the future!

Your contribution cannot be approved yet. See the Utopian Rules.

Your objective is "use postman to explore and use the cardano API". However, this is not reflected in the title. Please change the title.

Please edit your contribution to reapply for approval.

You may edit your post here, as shown below:

You can contact us on Discord.
[utopian-moderator]

Ok, I have edited it!

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 57135.10
ETH 2349.23
USDT 1.00
SBD 2.39