Coding Away Coding Away - 2 months ago 42
JSON Question

how to send in call to Web Api with postman when it expects a complex object

I need to send data to a Web Api Controller in which it wants an Object ..

I tend to use Postman ( so its like Fiddler )

URL

http://localhost:42822/api/Manifest/VerifyChain/ // PUT


Web Api Controller Method

[Route("api/Manifest/VerifyChain/")]
[ResponseType(typeof (VerifyManifestChainResponse))]
public IHttpActionResult PutVerifyManifestChain([FromBody] VerifyManifestChainRequest message)
{
//....
}


VerifyManifestChainRequest // Object that is to be passed in

public class VerifyManifestChainRequest
{
public byte[] CalculatedMeasurement { get; set; }
public string DeviceId { get; set; }
}


example
as converted byte array to string say all zeros
"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"


DeviceID = "00022B9E000000060001"

In Postman, there is a header / body extra

If I send in nothing,.. null then it does hit the method but returns error messages...

UPDATE

For example with Postman , what I what done before on another project is
POST --> use "Body" then select "raw" and "JSON"

example data to send in

{
"GlobalAssetId": 1790,
"IncludeFiledata": true,
"UserId": "1",
"Roles": [
"ContentAdmin",
"Admin"
],
"ClientId": 1
}

Answer

You are close, you just did not attempt to do the work :/ Yes - use PUT , raw, JSON and Body .. with Postman

Then with your 32 byte array of zeros and that deviceid this JSON should work

{
  "DeviceId": "00022B9E000000060001",
  "CalculatedMeasurement": [
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0
  ]

}

I believe that I have pasted 32 zero's ...

Cheers