Getting Error 401 with error_code UDAPI100050 to get Profile

Hi,

I am trying to get profile details using Upstox API in C#. I do following steps:

  1. Call the login URL and get authentication code
  2. use this code to get access_tocken (a very long alphanumeric string)
  3. 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

Hi @AlokDamle, could you please share the cURL request where you faced this issue? Additionally, could you provide your 6-digit Upstox ID for further investigation?

Thank you.

Hi Ketan,

I am making a DOT NET application. Above code is all that I am using to send the request. Not sure how to generate CURL request.

Nonetheless, I sorted the issue. The problem was the parenthesis in Authorization header value. Removed them and all working fine now.

Thanks and Regards,

Alok.

2 Likes

Thanks for the update @AlokDamle