发送请求而不指定 body 中的字段

Sending a request without specifying the fields in the body

我正在尝试向特定端点发送多个 PUT 请求。

我在列和值中使用 CSV 文件,不同列的名称引用 body 中的不同变量,你明白吗?

这是终点:

{{URL_API}}/products/{{sku}} --sku is the id of the product, i created that variable because i use it to pass the reference

这是我使用的 body:

{
    "price":"{{price}}",
    "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}}"
        }
    ]
}

我不想再使用body.. 有时有些产品有更多的 tan 1 组价格,我的意思是:

    "group_prices": [
        {
            "group":"{{class_a}}",
            "price":"{{price_a}}",
            "website":"{{website_a}}"
        },
        {
            "group":"{{class_b}}",
            "price":"{{price_b}}",
            "website":"{{website_b}}"
        }

是否可以在 CSV 文件中创建类似的内容?

sku,requestBody

99RE345GT, {JSON Payload}

我应该如何声明{JSON有效负载}?

你能帮帮我吗?

编辑: 这是我使用的 CSV 文件:

sku,price,tax_percentage,store_code,markup_top,status,class_a,price_a,website_a 95LB645R34ER,147000,US-21,B2BUSD,1.62,1,CLASS A,700038.79,B2BUSD

我想在 CSV 文件中传递 JSON,我的意思是

sku,requestBody

95LB645R34ER,{"price":"147000","tax_percentage":"US-21","store_code":"B2BUSD","markup_top":"1.62","status":"1","group_prices": [{ "group":"CLASS A","price":"700038.79","website":"B2BUSD"}]}

可以吗?我是否应该在请求中指定任何内容 body?我阅读了 POSTMAN 网站上发布的文档,但没有找到这样的示例。

当您使用 JSON 数据作为有效负载时,我会在 Collection 运行 中使用 JSON 文件而不是 CSV 文件。将其用作模板并将其另存为 data.json,它采用 运行ner.

接受的正确格式
[
    {
        "sku": "95LB645R34ER",
        "payload": {
            "price": "147000",
            "tax_percentage": "US-21",
            "store_code": "B2BUSD",
            "markup_top": "1.62",
            "status": "1",
            "group_prices": [
                {
                    "group": "CLASS A",
                    "price": "700038.79",
                    "website": "B2BUSD"
                }
            ]
        }
    },
    {
        "sku": "MADEUPSKU",
        "payload": {
            "price": "99999",
            "tax_percentage": "UK-99",
            "store_code": "BLAH",
            "markup_top": "9.99",
            "status": "5",
            "group_prices": [
                {
                    "group": "CLASS B",
                    "price": "88888.79",
                    "website": "BLAH"
                }
            ]
        }
    }
]

在请求的 pre-request Script 中,添加此代码。它根据数据文件中 payload 键下的数据创建一个新的 local 变量。数据需要转换为字符串,因此它使用 JSON.stringify() 来执行此操作。

pm.variables.set("JSONpayload", JSON.stringify(pm.iterationData.get('payload'), null, 2));

Request Body 中添加:

{{JSONpayload}}

Collection Runner、select 中 Collection 您想要 运行 然后 select 您之前的 data.json 文件创建。 运行 Collection.