Postman PUT returns success, but parameters are null in response body



  • I am trying to update employee details on following URI http://dummy.restapiexample.com/api/v1/update/24

    The request body is:

    {
        "employee_name": "DorisWan",
        "employee_salary": "50000",
        "employee_age": "25"
    }
    

    and the actual response looks like this:

    {
        "status": "success",
        "data": {
            "id": "24",
            "employee_name": null,
            "employee_salary": null,
            "employee_age": null,
            "profile_image": ""
        }
    }
    

    I am expecting response like:

    {
        "status": "success",
        "data": {
            "id": "24",
            "employee_name": DorisWan,
            "employee_salary": 50000,
            "employee_age": 25,
            "profile_image": ""
        }
    }
    

    Why the actual response contains "null" values though the status is success.

    I have added content-type as application/json in the request header parameters. Also tried passing the request via form-data still getting same response.



  • Welcome.

    You need to read the documentation in detail, it shows an example of a request body for PUT method:

    {
        "name":"test1",
        "salary":"1123",
        "age":"23"
    }
    

    There is no employee_ in the names of the attributes.

    So an example flow could look like this:

    1) create an employee with POST method:

    URL: /api/v1/create

    req body:

    {
        "name": "DorisWan",
        "salary": "50000",
        "age": "25"
    }
    

    res body:

    {   
        "status":"success",
        "data":{
           "name":"DorisWan",
           "salary":"50000",
           "age":"25",
           "id":47
        }
    }
    

    2) update the employee with PUT method:

    URL: /api/v1/update/47 See how I took the id from the previous response body and put it into the URL.

    req body:

    {
        "name": "Doris",
        "salary": "60000",
        "age": "26"
    }
    

    res body:

    {   
        "status":"success",
        "data":{
           "employee_name":"Doris",
           "employee_salary":"60000",
           "employee_age":"26",
           "id":47
        }
    }
    


Suggested Topics

  • 2
  • 2
  • 6
  • 2
  • 2
  • 2
  • 2
  • 2