# Testing a POST request using a GET request

**URL:** <https://community.postman.com/t/testing-a-post-request-using-a-get-request/60501>\
**Category:** Help Hub\
**Tags:** tests, json, validation\
**Created:** [April 30, 2024, 4:41pm UTC](https://community.postman.com/t/testing-a-post-request-using-a-get-request/60501 "2024-04-30T16:41:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![docking-module-astr5](https://avatars.discourse-cdn.com/v4/letter/d/7ea924/32.png) [@docking-module-astr5](https://community.postman.com/u/docking-module-astr5)\
**Post date:** [April 30, 2024, 4:41pm UTC](https://community.postman.com/t/testing-a-post-request-using-a-get-request/60501/1 "2024-04-30T16:41:45Z")

</div>

I am new to API testing and looking to validate a POST request. The request creates a user account and I am trying to write a test to GET the user details and confirm they match the POST body.

I used the Postman bot tool and it suggested the below script, however the GET request keeps coming back empty. Is this test even possible? Am I approaching this the wrong way? Any help greatly appreciated as the bot is putting me round in circles!

```auto
// Test for status code 200
pm.test("Response status code is 200", function () {
  pm.response.to.have.status(200);
});

// POST request expected response data
const expectedUser = {
    "id": "API123",
    "name": "API Test User",
    "email": "api_user_test@email.com",
    "role": 0
};

// Send GET request to retrieve new user details
pm.sendRequest({
    url: 'https://xxxxx/api/User?Email=api_user_test@email.com',
    method: 'GET'
}, function (err, response) { 
    if (err) {
        console.error(err);
        return;
    }
    // Parse the response body
    const responseBody = response.json();

// POST request expected response data
const expectedUser = {
    "oid": "API123",
    "name": "API Test User",
    "email": "api_user_test@email.com",
    "role": 0
};

    // Compare the retrieved data with the expectedUser
    pm.test('User details match', function () {
        pm.expect(responseBody.oid).to.eql(expectedUser.id);
        pm.expect(responseBody.name).to.eql(expectedUser.name);
        pm.expect(responseBody.email).to.eql(expectedUser.email);
        pm.expect(responseBody.role).to.eql(expectedUser.role);
    });
});

```

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [May 1, 2024, 8:37am UTC](https://community.postman.com/t/testing-a-post-request-using-a-get-request/60501/2 "2024-05-01T08:37:51Z")

</div>

Craft a normal GET request using the GUI and get that working first.

Once you have that working, look at the console log to see what is being sent and compare to the console log for the sendRequest().

This should show you if there are any differences or whether you’ve missed something in the GET request.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [May 31, 2024, 8:38am UTC](https://community.postman.com/t/testing-a-post-request-using-a-get-request/60501/3 "2024-05-31T08:38:43Z")

</div>

Closed on May 31, 2024, 8:38am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
