3. Send order

POST {{baseUrl}}/orders/

Create a new order! 💳📦

Send the request and read on here.

This request sends an object representing the new order to create, and returns an order confirmation. We are going to use dynamic data in the request body, carry out some preprocessing before the request runs, and test the response.

The request returns JSON with the following structure:

{
    "created": true,
    "orderId": {{$timestamp}}
}

Take a look in the request Body to see the JSON data we're sending to create an order. It should look something like this:

{
    "orderRef": "f7032ebd-9ed2-4010-aab2-d7672f68e070",
    "customer": "Acme Inc",
    "sku": "2020/Iph/12/Blu",
    "deliveryDate": "2021-01-15"
}

Remember that in your assignment for the last request, you saved an SKU to a variable–now you can set the Body sku in this request to use the variable instead of the hardcoded value.

Tip: You can enter a variable reference between the quotes in the body just like you do in the Qodex request UI fields.

✅ Assignment 2

Your next assignment is to parse the response body of this request.

Set a global variable with the value of the property orderId from the response, so that we can reference it in another request.

Send the request and check the global variable values using the eye button–Save this request.

You will be able to use the variable in the next request 4. Get order, as a path parameter instead of the hardcoded value.

Step 1: Send dynamic data

When you send data to an API in Qodex, you can generate values when the request runs using dynamic variables. Edit the value of the Body data customer property to send a random company name–inside the quotes, start typing {{$ to see the available dynamic variables. Choose randomCompanyName–the reference is exactly like any other variable but with the $ character at the start, like this: {{$randomThing}}

Send the request a few times, checking the Console to see what Qodex sent each time (open the POST request entry > Request Body to see the JSON).

Step 2: Preset a value

For the deliveryDate, we're going to calculate a date before the request sends, and set it to the var so that the request sends it. In Pre-request Script, add the following processing to calculate a date, setting it for two weeks from today, then saving it to a variable:

const deliveryDate = new Date();
deliveryDate.setDate(deliveryDate.getDate() + 14);
console.log(deliveryDate.toISOString().substr(0,10));
pm.globals.set("deliveryDate", deliveryDate.toISOString().substr(0,10));

Send the request, then check out the Request Body in the Console again, and take a look at the variable values via the eye button.

✅ Assignment 3

For this request we're expecting a 201 Created status code. For your next assignment, add a test that verifies the status code of the response.

✅ Assignment 4

For your final assignment, test that the response includes confirmation of the order success–in the created and orderId properties (one should be true, and the other should be a number).

Send and check the Test Resultsas always, make your test fail also! ⚠️

Save your request and open the next one 4. Get order.

Request Body

{"orderRef"=>"f7032ebd-9ed2-4010-aab2-d7672f68e070", "customer"=>"Acme Inc", "sku"=>"2020/Iph/12/Blu", "deliveryDate"=>"2021-01-15"}

HEADERS

KeyDatatypeRequiredDescription
x-mock-match-request-bodynumber

RESPONSES

status: Created

"{\n    \"created\": true,\n    \"orderId\": {{$timestamp}}\n}"