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:
[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.