Hi,
I am trying to get profile details using Upstox API in C#. I do following steps:
- Call the login URL and get authentication code
- use this code to get access_tocken (a very long alphanumeric string)
- Then use this token to get profile.
However in the third step I am getting “Error 401 with error_code UDAPI100050”. I have Logged in and have generated the access token just a couple of minutes before sending the profile request (about at time 18:05).
Following is my code:
var client = new HttpClient();
var Request = new HttpRequestMessage(HttpMethod.Get,
"https://api.upstox.com/v2/user/profile");
Request.Headers.Add("Accept", "application/json");
Request.Headers.Add("Authorization", "Bearer {" + access_key+ "}");
Request.Headers.Add("Api-Version", "2.0");
var response = await client.SendAsync(Request);
string respStr = await response.Content.ReadAsStringAsync();
dynamic respJson = JsonConvert.DeserializeObject(respStr);
Following are the details of Request variable:
{Method: GET, RequestUri: ‘https://api.upstox.com/v2/user/profile’, Version: 1.1, Content: , Headers:
{
Accept: application/json
Authorization: Bearer {xxxxxxxxxxx}
Api-Version: 2.0
}}
Following is the response I am getting:
“{"status":"error","errors":[{"errorCode":"UDAPI100050","message":"Invalid token used to access API","propertyPath":null,"invalidValue":null,"error_code":"UDAPI100050","property_path":null,"invalid_value":null}]}”
Please help.
Regards,
Alok