Home > Back-end >  Issue when sending Parameters update by postman put method Web Api?
Issue when sending Parameters update by postman put method Web Api?

Time:11-25

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

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"
}

CodePudding user response:

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.

  • Related