Universal
Universal

Reputation: 45

Getting null when sending string to API from Postman URL

My issue is, when I try to pass a single string to my API I receive it as a null value in the API, but when I try to pass an integer to another controller it works fine, I guess it's a syntax issue. Bellow two controllers as example:

[HttpGet("amostra/get/id/{id}")]
public Amostra GetAmostraId(int id) => _amostra.GetById(id);

[HttpGet("amostra/get/cli/{nomeFantasia}")]
public Dictionary<int, Amostra> getByFantasia(string nF) => _amostra.GetByCliente(nF);

The first one works without an issue, the other one never works, later in the "GetByCliente(nF)" function I check the length of the string and then get the error: "System.NullReferenceException: 'Object reference not set to an instance of an object.'", "nF was null".

Postman example Postman example

Upvotes: 1

Views: 575

Answers (1)

Kahbazi
Kahbazi

Reputation: 15015

Your variable name and your route must match.

Try this

[HttpGet("amostra/get/cli/{nf}")]
public Dictionary<int, Amostra> getByFantasia(string nF) => _amostra.GetByCliente(nF);

Upvotes: 3

Related Questions