简体   繁体   English

使用 POSTMAN 或任何其他方式批量 POST/PUT API 请求

[英]Bulk POST/PUT API requests using POSTMAN or any other means

I have a list of API requests which are already in URL format.我有一个已经采用 URL 格式的 API 请求列表。 I just need to POST them one after the other automatically and log their results.我只需要自动一个接一个地发布它们并记录它们的结果。

The only way I could do is to copy each url and send them using postman.我能做的唯一方法是复制每个网址并使用邮递员发送。 But its really time consuming.但是真的很费时间。 I tried looking at task runner but that seemed hard to set the variable equal to the data file with all my requests我尝试查看任务运行程序,但似乎很难将变量设置为与我所有请求的数据文件相等

https://someApi/clientAssign?auth=123|asdf&otherParamsList=123Params
https://someApi/clientAssign?auth=123|asdf&otherParamsList=456Params
https://someApi/clientAssign?auth=123|asdf&otherParamsList=899Params

I am not sure of a way to fire the above urls one after the other using postman.我不确定使用邮递员一个接一个地触发上述网址的方法。 I have around 60 POST requests and 60 PUT requests我有大约 60 个 POST 请求和 60 个 PUT 请求

Can anyone suggest a way to achieve this.任何人都可以提出一种方法来实现这一目标。 I can do it by copying over the urls and manually posting them.我可以通过复制网址并手动发布它们来做到这一点。 I am just not in a position to spend so much time doing this very often.我只是不能经常花这么多时间做这件事。 And I have already spent time preparing the url with proper values being substituted and ready to to go.而且我已经花时间准备 url,并用适当的值替换并准备好使用。 Any help is appreciated.任何帮助表示赞赏。

Never mind I figured out a way to use postman's collection runner to accomplish the same.没关系,我想出了一种方法来使用邮递员的收集跑步者来完成同样的事情。 For those who struggled like the way I did, here is how to use that feature and its even easier to substitute values to your url on the go.对于那些像我一样挣扎的人,这里是如何使用该功能,并且更容易在旅途中将值替换为您的 url。

First create a request in Postman:首先在 Postman 中创建一个请求:

Below is a screenshot for Example :下面是示例的屏幕截图:

在此处输入图像描述

Now the requirement is to post the below url: https://someApiPOSTRequest/clientAssign?auth=123|asdf&otherParamsList=123Params&someOtherParams={{VariableFromFile}}&additionalParams=hardcodedOnURL现在要求发布以下网址: https://someApiPOSTRequest/clientAssign?auth=123|asdf&otherParamsList=123Params&someOtherParams={{VariableFromFile}}&additionalParams=hardcodedOnURL

with values being substituted for {{VariableFromFile}} from the csv file you will need to upload.用您需要上传的 csv 文件中的{{VariableFromFile}}替换值。 Your csv should be formatted as below, where the header should have the same variable name used on your url:您的 csv 格式应如下所示,其中标头应与您的 url 上使用的变量名称相同:

在此处输入图像描述

Click on the '>' button shown below beside Example folder and click on 'Run' to open the same on Collection runner window of postman:单击示例文件夹旁边显示的“>”按钮,然后单击“运行”以在邮递员的Collection runner窗口中打开相同的内容:

在此处输入图像描述

Once the Collection Runner window opens up, click on select file option to upload your csv file, and the Iterations field is pre-filled with the number of records on the csv file by default.一旦 Collection Runner 窗口打开,单击选择文件选项以上传您的 csv 文件, Iterations字段默认预填充 csv 文件上的记录数。 You can change the number and when you do make sure of the number of iterations you want to run as its directly related to number of rows in your uploaded csv.您可以更改数字,并确定要运行的迭代次数与上传的 csv 中的行数直接相关。

在此处输入图像描述

You can also preview your uploaded csv file:您还可以预览上传的 csv 文件:

在此处输入图像描述

If you click on Run Example button, the collection runner posts the url 9 times with {{VariableFromFile}} being substituted with value from csv file for each iteration.如果您单击“运行示例”按钮,则集合运行程序会发布 9 次 url,其中 {{VariableFromFile}} 将被替换为每次迭代的 csv 文件中的值。

You can have more variables substituted by just having one more column with the relevant variable name and using the same on your api call.您可以通过多一列具有相关变量名称并在您的 api 调用中使用相同的名称来替换更多变量。 Its just that simple.就是这么简单。 It did reduce a lot of manual work for me!!它确实为我减少了很多体力劳动!!

You can also refer to the below link which guided me to use this feature in Postman.您还可以参考以下链接,该链接指导我在 Postman 中使用此功能。 Link 关联

Hope this will be helpful for someone.希望这对某人有帮助。

I found the solution adding raw data as JSON .我找到了将原始数据添加为JSON的解决方案。 from Body > rawBody > raw

[
  {
    "text": "Buy Milk",
    "completed": true
  },
  {
    "text": "Check updated of wall street",
    "completed": false
  },
  {
    "text": "Play game with team",
    "completed": true
  }
]

Lots of developer will use the answer of chethandb but the problem (if like me) is not only to execute requests in mass but also save the reponses somewhere.许多开发人员会使用 chethandb 的答案,但问题(如果像我一样)不仅要大量执行请求,还要将响应保存在某处。

  • initial request初始请求

在此处输入图像描述

The RECIPIENTACCOUNT is a variable/parameter used in CSV and passed into each request. RECIPIENTACCOUNT 是 CSV 中使用的变量/参数,并传递到每个请求中。

  • updating the initial request更新初始请求

Add the following code into the tab Tests:将以下代码添加到选项卡测试中:

let responses = pm.collectionVariables.get('collectionResponses')
if(responses) {
  responses = JSON.parse(responses);
} else {
  responses = []
}

responses.push(pm.response.json());
pm.collectionVariables.set('collectionResponses', JSON.stringify(responses));

在此处输入图像描述

Make a csv containing the parameters (in my case the ibans of the customers).制作一个包含参数的 csv(在我的例子中是客户的 ibans)。

/home/rudy/Desktop/recipientaccount.csv /home/rudy/Desktop/recipientaccount.csv

I do not disclose the recipient accounts of our customers.我不会透露我们客户的收款人帐户。

在此处输入图像描述

Important to notice that RECIPIENTACCOUNT is used into the request as a parameter.重要的是要注意 RECIPIENTACCOUNT 作为参数用于请求中。
Then you are ready to go.然后你准备好了。

  • Execution of the requests请求的执行

在此处输入图像描述

Click on the arrow on the right (not displayed because it disappears).单击右侧的箭头(未显示,因为它消失了)。

在此处输入图像描述

Click on run.点击运行。 A new windows is opened.打开一个新窗口。

在此处输入图像描述

Click on 'select File' to make a file selection and choose (for example) recipientaccount.csv.单击“选择文件”以选择文件并选择(例如)recipientaccount.csv。
Click on 'Save reponses'.点击“保存回复”。
Change 'Iterations' (if needed).更改“迭代”(如果需要)。
You can 'preview' if you want.如果需要,您可以“预览”。
Click on the blue button (Run Customer reachability in my example).单击蓝色按钮(在我的示例中为运行客户可达性)。
The requests are executed (sequentially).请求被执行(按顺序)。

I have limited the number of requests to 3 (the picture displayed '1', sorry)我已将请求数限制为 3(图片显示为“1”,抱歉) 在此处输入图像描述 All the 3 requests were executed correctly.所有 3 个请求均已正确执行。

  • Now time to get the results.现在是时候得到结果了。

Close the 'collection runner' window.关闭“收集运行器”窗口。
Back to 'Customer Reachability'返回“客户可达性”

在此处输入图像描述
Click on the 3 dots on the right and on 'edit'单击右侧的 3 个点,然后单击“编辑” 在此处输入图像描述

Click on variables and make a selection and copy the results from 'CURRENT VALUE':单击变量并进行选择并从“当前值”复制结果:

[{"data":{"id":"NOT DISCLOSED","type":"zoomitCustomerSearch","attributes":{"customerReference":"0193:IBN_BE_NOT DISCLOSED","status":"not-reachable"}}},{"data":{"id":"NOT DISCLOSED","type":"zoomitCustomerSearch","attributes":{"customerReference":"0193:IBN_BE_NOT DISCLOSED","status":"not-reachable"}}},{"data":{"id":"NOT DISCLOSED","type":"zoomitCustomerSearch","attributes":{"customerReference":"0193:IBN_BE_NOT DISCLOSED","status":"not-reachable"}}}] [{"data":{"id":"NOT DISCLOSED","type":"zoomitCustomerSearch","attributes":{"customerReference":"0193:IBN_BE_NOT DISCLOSED","status":"not-reachable"} }},{"data":{"id":"NOT DISCLOSED","type":"zoomitCustomerSearch","attributes":{"customerReference":"0193:IBN_BE_NOT DISCLOSED","status":"not-reachable "}}},{"data":{"id":"NOT DISCLOSED","type":"zoomitCustomerSearch","attributes":{"customerReference":"0193:IBN_BE_NOT DISCLOSED","status":"not -可达"}}}]

The results are one one big line.结果是一条大线。 You have to make usage of sed/awk/... to format the resuls as desired.您必须使用 sed/awk/... 来根据需要格式化结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM