Quantcast
Channel: Postmanタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 470

Postman APIをちょっと調べてみた

$
0
0

Postman APIをちょっと調べてみた

なんか使うかもしれないのでドキュメント読んでたんだが、まとめておいた方が後々楽だと思ったので。
あと、ドキュメントのスクショに表示されているUIが若干古いバージョンぽいので。
基本的には公式ドキュメント読んだ方が確実かつ早いと思う。

自分としてはこんなことをしたい:
1. Postman Desktop AppでAPIテストを作成・更新する
2. Postman APIで全collectionのuidを取得する
3. 取得したuidとnewmanを使って、cliでAPI叩く
4. 1,2を定期実行するバッチをつくるか、CI/CDツールと連携してコード変更時に回帰テストとして実行する

この記事は、そのうち1,2をやるためのもの

Postman APIとは

本家ドキュメントより抜粋:

The Postman API endpoints to help you integrate Postman within your development toolchain.
You can add new collections, update existing collections, update environments, and add and run monitors directly through the API. This enables you to programmatically access data stored in your Postman account.
You can get started with the API via the Run in Postman button at the top of the Postman API documentation and use the Postman app to send requests.

1分間に60リクエスト、月間1,000リクエストまでという縛りもあるっぽい、課金したらどうにかなるんだろうけど。
無料プランだとなんか厳しい気がする。

Postman API keyを取得する

  1. Postman API keysに遷移する
  2. "Generate API Key"ボタンをクリックする step2_2.png
  3. key nameを設定し、"Generate API Key"ボタンをクリックする step3.png
  4. "Copy to Clipboard"をクリックしたのち、"Close"ボタンをクリックする step4.pngコピーしたAPI keyは、collectionのuidを調べる際に利用するのでメモ帳か何かに保存しておくとよい

collectionのuidを調べる

  1. Postman API documentationにアクセスする
  2. 自分のワークスペースにforkする
  3. 環境変数に"postman_api_key"を作成し、その値としてAPI keyを設定する
  4. Collection Folder > All Collections を開き、sendボタンをクリックする the_last.png

リクエストが成功した場合、以下のようなレスポンスが得られるので、実行対象となるcollectionのuidを取得する

{
"collections": [
{
"id": "dac5eac9-148d-a32e-b76b-3edee9da28f7",
"name": "Cloud API",
"owner": "631643",
"uid": "631643-dac5eac9-148d-a32e-b76b-3edee9da28f7"
},
{
"id": "f2e66c2e-5297-e4a5-739e-20cbb90900e3",
"name": "Sample Collection",
"owner": "631643",
"uid": "631643-f2e66c2e-5297-e4a5-739e-20cbb90900e3"
},
{
"id": "f695cab7-6878-eb55-7943-ad88e1ccfd65",
"name": "Postman Echo",
"owner": "631643",
"uid": "631643-f695cab7-6878-eb55-7943-ad88e1ccfd65"
}
]
}

余談

記事の最初にリクエスト実行数には限度があると書いたが、現在の利用状況はaccount usage pageから確認できるとのこと。

余談2

リクエスト数の縛りは、有料プランで回避できそう(Plan Comparison
money.png


Viewing all articles
Browse latest Browse all 470

Trending Articles