简体   繁体   中英

Getting “Bad Request” for Postman API

I simply took an example from Postman API Documentation for Create Collection and removed the extra request outside the folder.

My intention is to create just a folder with 1 request in it.

Here is the request:

{
    "collection":{
       "variables":[

       ],
       "info":{
          "name":"Sample Collection",
          "description":"This is just a sample collection.",
          "schema":"https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
       },
       "item":[
          {
             "name":"This is a folder",
             "description":"",
             "item":[
                {
                   "name":"Sample POST Request",
                   "request":{
                      "url":"echo.getpostman.com/post",
                      "method":"POST",
                      "header":[
                         {
                            "key":"Content-Type",
                            "value":"application/json",
                            "description":""
                         }
                      ],
                      "body":{
                         "mode":"raw",
                         "raw": "{
                            \"data\": \"123\"
                        }"
                      },
                      "description":"This is a sample POST Request"
                   },
                   "response":[

                   ]
                }
             ]
          }
       ]
    }
 }

But for this, I am getting "Bad Request" error, what exactly is wrong with my request?

EDIT - Here's what it looks like in Postman

To me, it looks like you're trying to send the whole collection json file back to that route.

The JSON in the request body on the image is what you would import into Postman to get the Sample Collection folder. This contains a request called Sample POST Request

Copy the request body JSON and save it as a .json file - Then import this using the Import feature in the top left on the application.

进口

This will then create the folder for you in the application with the sample POST request.

If you send it to the echo URL, you will receive a response telling you that the URL has now changed to https://postman-echo.com/post - Add this new URL into the address bar and hit Send .

邮递员

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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