定义一个新变量以进行巨大的迭代给我一个错误

编程入门 行业动态 更新时间:2024-10-27 14:19:27
本文介绍了定义一个新变量以进行巨大的迭代给我一个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

I have an endpoint, you can have información about products

{{URL_API}}/products/

If i perform a GET method over that endpoint i will obtain the information of every product

BUT i can also specify the product that i want to know about, i.e:

{{URL_API}}/products/9345TERFER (the last code is the id of the product, called SKU)

The problem is that if i want to make a CSV in order to update the information of different products i have to define a variable called sku in the endpoint so i will be able to pass the corresponding SKU

I want to create the variable {{sku}} but i do not understand how to do that.. i tried so many times and i failed, i've searched a lot but i do not really understand

Also, should i use ":" before the declaration of the variable? i mean:

{{URL_API}}/products/:{{sku}}

or simply:

{{URL_API}}/ns/products/{{sku}}

Can you help me? I'm super lost :(

EDIT:

I want to perform a PUT method, i want to pass different values to the body and then.. send the request (it throws an error: 404 not found)

This is what i did:

PUT|{{URL_API}}/products/{{sku}}

body:

{ "tax_percentage":"{{tax_percentage}}", "store_code":"{{store_code}}", "markup_top":"{{markup_top}}", "status":"{{status}}", "group_prices": [ { "group":"{{class_a}}", "price":"{{price_a}}", "website":"{{website_a}}" } ] }

CSV:

POSTMAN:

解决方案

Your issue seems to be just a basic understanding of how data files work with variables in Postman, here's a simple example that will work the same way for you too.

This is a basic request I'm using to resolve the variable from the data file - It's a GET request but that doesn't matter as all we're look at here is using a data file to resolve variables. All you need to do is ensure the URL is correct and that you SAVE the request before using the runner.

Here's a simple CSV file created in a text editor. The heading sku in the name on the variable it will reference inside the Postman request. Each value under that is the value that will be used for each iteration.

In the Runner, select your Collection from the list (If you have more than one) then select the CSV file. Once imported, you will be able to see a preview of the data.

If that's correct, press the Run button. The Runner will then iterate through the file and pick up the sku value in the CSV file and use it in the request. I've expanded one of the requests so you can see that the value was used in the request.

更多推荐

定义一个新变量以进行巨大的迭代给我一个错误

本文发布于:2023-10-29 07:39:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539108.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:给我   变量   定义   错误   迭代

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!