1
I understand that the Frombody is coming null and I don’t know why.
That’s my Postman payload
{
"ChannelCode" : "TS",
"Name" : "Teste",
"Celphone" : "(11)999999999",
"Endpoint" : "www.teste.com.br",
"TokenLogin" : "1234567890",
"TokenLoginExpiration" : "2018-06-13T00:00:00.000Z",
"Active" : "true"
}
In this controller I get the request
[HttpPost]
[Authorize("Bearer")]
public async Task<IActionResult> Create([FromBody]ChannelCreateRequest channel)
{
if (channel == null) throw new WhatsAppApiException("Favor informar os dados do Canal!");
var result = await _channelCreateService.Process(new ChannelCreateCommand(channel.ChannelCode, channel.Name,
channel.Celphone, channel.Endpoint,
channel.TokenLogin,
channel.TokenLoginExpiration ,
channel.Active.GetValueOrDefault(true)));
return Ok(new ApiReturnItem<ChannelResult> { Item = result, Success = true });
}
everything will be recorded on Mongodb
Channelcreaterequest class
public class ChannelCreateRequest
{
[JsonProperty("codigo_canal")]
public string ChannelCode { get; set; }
[JsonProperty("nome")]
public string Name { get; set; }
[JsonProperty("celular")]
public string Celphone { get; set; }
[JsonProperty("url")]
public string Endpoint { get; set; }
//------ Remover-----------
[JsonProperty("token_canal")]
public string TokenLogin { get; set; }
[JsonProperty("token_canal_expiracao")]
public DateTime? TokenLoginExpiration { get; set; }
//--------Fim remover---------
[JsonProperty("ativo")]
public Boolean? Active { get; set; }
}
responding to Pagotti, this is Postman
Usually this occurs when it fails to parse the body message for the object "Channelcreaterequest".
– Reiksiel
You can add the class code: Channelcreaterequest?
– Reiksiel
@Reiksiel, added
– pnet
You debugged the code to see which point the exception is being thrown?
– Jéf Bueno
Object Reference not set to an instance of an Object.. All fields in Frombody are null. That is, I get nothing in the request.
– pnet
Your
Request
comes with thecontent-type
correct to report that it is ajson
?– Pagotti