0

Learning Postman, and got some trouble making DELETE call with POST call in pre-request script. Aim is to make only DELETE call without having to make POST call each time. Endpoint is swagger petstore. So, DELETE is for deleting pet by ID and POST (in pre-request) is for creating a pet with required ID. When I make a POST call separately - it works okay. When POST call is in pre-request - pet is not created. What may be wrong?

Body of separated POST call:

{
"name": "Volodya",
"photoUrls": [
    "www.parrots.org/photo1"
],
"id": 202207,
"category": {
    "id": 12675,
    "name": "Buzza"
    },
"tags": [
{
        "id": 5566,
        "name": "A Scary Mummy"
    }
],
"status": "yes"
}

image of POST call

And my pre-request code:

const createPet = {
  url: 'https://petstore.swagger.io/v2/pet/202207',
  method: 'POST',
 header: {
    'Content-Type': 'application/json',
    'Accept': '*/*'
  },
  body: {
    mode: 'raw',
    raw: JSON.stringify({
"name": "Volodya",
  "photoUrls": [
    "www.parrots.org/photo1"
     ],
  "id": 202207,
  "category":   {
  "id": 12675,
  "name": "Buzza"
    },
  "tags": [
    {
        "id": 5566,
       "name": "A Scary Mummy"
    }
],
"status": "yes"
    })
    }
};

pm.sendRequest(createPet);

Image of pre-request

Thanks for your help.

andrtvrd
  • 1
  • 3

1 Answers1

0

Found the answer =) The problem was simple - mistake in endpoint. In original POST request endpoint was https://petstore.swagger.io/v2/pet. But in pre-request code endpoint was https://petstore.swagger.io/v2/pet/202207. So that was the reason.

andrtvrd
  • 1
  • 3