Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Issue when sending Parameters update by postman put method Web Api?

I work on .net core 6.0 web api . i face issue on

testing web api by post man .

my issue how to send paramters to web api update

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

method .

so How to send id with object on body to update action .

{
    "itemId": 4,
    "itemNameAR": "قلم",
    "itemNameEN": "pen2",
    "costTypeId": 1,
    "minLimitQunatity": 1,
    "costAccountID": 1,
    "departmentID": 1,
    "itemCategoryId": 1,
    "description": "1",
    "hasExpireDate": true,
    "isActive": true,
    "createdBy": 1,
    "modifiedBy": 1,
    "createdDate": "0001-01-01T00:00:00",
    "modifiedDate": "0001-01-01T00:00:00",
    "itemattribute": null
}

when send api as below

https://localhost:7235/api/items?id=4

so How to solve issue please ?

   [HttpPut("{id}")]
          public async Task<IActionResult> Update(int id, UpdateItemCommand command)
          {
              if (id != command.Id)
              {
                  return BadRequest();
              }
              return Ok(await Mediator.Send(command));
          }

what i try to send api request Web Api Not catched or hitted although i run my web api .

Api not hit

Updated post
i change url on post man as below

https://localhost:7235/api/4

but still issue not solved

error display 400 bad request
details error

{
    "errors": {
        "Fax": [
            "The Fax field is required."
        ],
        "City": [
            "The City field is required."
        ],
        "Phone": [
            "The Phone field is required."
        ],
        "Region": [
            "The Region field is required."
        ],
        "Address": [
            "The Address field is required."
        ],
        "Country": [
            "The Country field is required."
        ],
        "PostalCode": [
            "The PostalCode field is required."
        ],
        "ContactName": [
            "The ContactName field is required."
        ],
        "ContactTitle": [
            "The ContactTitle field is required."
        ],
        "CustomerName": [
            "The CustomerName field is required."
        ]
    },
    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "traceId": "00-efde167cb6a7fa5af42abff9d055e2db-92ff55a318cb7a29-00"
}

>Solution :

Change your request URL to,

https://localhost:7235/api/items/4

because your controller has been configured as,

[HttpPut("{id}")]

which indicates a path parameter rather than query parameter.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading