This is a typical question and would require knowledge of Vericred medicare API to some extent. Calling the API through .NET Core application. Already registered with the developers account and have relevant key stored in json file.
Here's the calling code:
[Route("GetMedicineData/med_name")]
[HttpGet]
public async Task<ActionResult<DrugsModel>> GetMedicineData(string med_name)
{
APIRequestMaker objAPI = new APIRequestMaker(_config);
DrugsModel drugsModel = new DrugsModel();
string apivalue = _config.GetSection("Vericred:API_Key").ToString();
try
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("api.vericred.com")); *** this line
client.DefaultRequestHeaders.Add("Authorization", "API Key" + apivalue);
var streamTask = client.GetStreamAsync("api.vericred.com/drugs?search_term=" + med_name.ToString());
var drugData = await JsonSerializer.DeserializeAsync<DrugsModel>(await streamTask);
return (drugData);
}
}
catch(Exception exp)
{
throw exp.GetBaseException();
}
}
Here DrugsModel is the corresponding mapped model
When you run it, the exception thrown on the line marked is The format of value 'api.vericred.com' is invalid.
Not sure why that pops up. Things look like I did more or less correctly. If you test via Postman, the API endpoint, you need to select API Key as 'Type' and provide Key-Value as Vericred-Api-Key - blablaablablaaawhatever.
Simply put I have tried to replicate that in my code. The official docs at Vericred Developer don't contain relevant instructions/guiline.
Thanks.
There are more wonders in this world of ours than you can wonder; and it is nice to sometimes wonder at them.
Firstly,you need to know the MediaTypeWithQualityHeaderValue constructor needs a string which is a media type.As mgebhard said,if you request
a REST API it is probably application/json.
.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today.
I am getting the error --> The format of value 'key=blablablaaabla' is invalid. See the screen shot for idea. If you inspect that attributes stack of client, you can see Authorization=null.
Tried several permutation combinations of quotation marks around the "key=" + apivalue, as initial hunch was, that could have been the case.
link --> https://imagebin.ca/v/5LpPZklVc0Md
There are more wonders in this world of ours than you can wonder; and it is nice to sometimes wonder at them.
Your first issue has been solved. This is a new question.
PGChoudhury
I am getting the error --> The format of value 'key=blablablaaabla' is invalid. See the screen shot for idea. If you inspect that attributes stack of client, you can see Authorization=null.
Tried several permutation combinations of quotation marks around the "key=" + apivalue, as initial hunch was, that could have been the case.
link --> https://imagebin.ca/v/5LpPZklVc0Md
Usually your application authenticates with a server and receives an access token. The token (bearer) is send in subsequent requests which authorizes access to secured resources. The community has no idea how this service works. You are asking the wrong
audience. Contact the service owners or read the service documentation to figure out what you're supposed to do. Guessing is not the answer.
Member
51 Points
307 Posts
The format of value 'api.vericred.com' is invalid API Endpoint in .Net Core --
May 07, 2020 03:50 PM|PGChoudhury|LINK
Hi All.
This is a typical question and would require knowledge of Vericred medicare API to some extent. Calling the API through .NET Core application. Already registered with the developers account and have relevant key stored in json file.
Here's the calling code:
Here DrugsModel is the corresponding mapped model
When you run it, the exception thrown on the line marked is The format of value 'api.vericred.com' is invalid.
Not sure why that pops up. Things look like I did more or less correctly. If you test via Postman, the API endpoint, you need to select API Key as 'Type' and provide Key-Value as Vericred-Api-Key - blablaablablaaawhatever.
Simply put I have tried to replicate that in my code. The official docs at Vericred Developer don't contain relevant instructions/guiline.
Thanks.
All-Star
53001 Points
23596 Posts
Re: The format of value 'api.vericred.com' is invalid API Endpoint in .Net Core --
May 07, 2020 04:20 PM|mgebhard|LINK
You'll need to read the documentation for service you are calling but if this is a REST API it is probably application/json.
Contributor
2690 Points
874 Posts
Re: The format of value 'api.vericred.com' is invalid API Endpoint in .Net Core --
May 08, 2020 08:08 AM|Rena Ni|LINK
Hi PGChoudhury,
Firstly,you need to know the MediaTypeWithQualityHeaderValue constructor needs a string which is a media type.As mgebhard said,if you request a REST API it is probably application/json.
Reference:
https://stackoverflow.com/a/47176966/11398810
And for adding the request header of authorization,it should be:
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "key=xxx");
Reference:
https://stackoverflow.com/a/49819111/11398810
https://stackoverflow.com/a/15242095/11398810
Best Regards,
Rena
Member
51 Points
307 Posts
Re: The format of value 'api.vericred.com' is invalid API Endpoint in .Net Core --
May 08, 2020 03:03 PM|PGChoudhury|LINK
Hi @mgebhard
Yes, it returns JSON response.
For eg.
Reading the fdocu. to find if there are more hints.
Hi @RenaNi - thanks for suggesting the modif. Will try it out. Revert back accordingly.
Thanks.
Member
51 Points
307 Posts
Re: The format of value 'api.vericred.com' is invalid API Endpoint in .Net Core --
May 08, 2020 04:10 PM|PGChoudhury|LINK
Hi again -- an update:
I am getting the error --> The format of value 'key=blablablaaabla' is invalid. See the screen shot for idea. If you inspect that attributes stack of client, you can see Authorization=null.
Tried several permutation combinations of quotation marks around the "key=" + apivalue, as initial hunch was, that could have been the case.
link --> https://imagebin.ca/v/5LpPZklVc0Md
All-Star
53001 Points
23596 Posts
Re: The format of value 'api.vericred.com' is invalid API Endpoint in .Net Core --
May 08, 2020 05:27 PM|mgebhard|LINK
Your first issue has been solved. This is a new question.
Usually your application authenticates with a server and receives an access token. The token (bearer) is send in subsequent requests which authorizes access to secured resources. The community has no idea how this service works. You are asking the wrong audience. Contact the service owners or read the service documentation to figure out what you're supposed to do. Guessing is not the answer.
Member
51 Points
307 Posts
Re: The format of value 'api.vericred.com' is invalid API Endpoint in .Net Core --
May 10, 2020 01:40 PM|PGChoudhury|LINK
yeah I know that flow.
Will ask n seek precise necessary answers on this elsewhere for this specific case.
Thanks.