Get Token API giving "Bad Request" response.

Get Token API giving “Bad Request” response.
I am using C# language to consume the API. Below is the code. Please check if I am doing anything wrong?

C# Code:
code = “gSI7qB”;

        Dictionary<string, string> param = new Dictionary<string, string> ();
        param.Add ( "code", code );
        param.Add ( "client_id", clientID );
        param.Add ( "client_secret", clientSecret );
        param.Add ( "redirect_uri", redirectURI );
        param.Add ( "grant_type", grantType );

        using ( httpClient = new HttpClient () )
        {
            HttpRequestMessage httpRequestMessage = new HttpRequestMessage ( HttpMethod.Post, "https://api.upstox.com/v2/login/authorization/token" );
            httpRequestMessage.Headers.Add ( "Accept", "application/json" );

            StringContent stringContent = new StringContent ( JsonConvert.SerializeObject ( param ) );
            stringContent.Headers.ContentType = new MediaTypeHeaderValue ( "application/x-www-form-urlencoded" );
            httpRequestMessage.Content = stringContent;
            HttpResponseMessage response = httpClient.SendAsync ( httpRequestMessage ).Result;
            response.EnsureSuccessStatusCode ();
            string ss = response.Content.ReadAsStringAsync ().Result;
        }

Could you use the sample curl request provided on this example code page?

If it doesn’t work, please share your curl request here, omitting the secret. We will review it and get back to you.

I have tested Get access token API in postman, its is working fine. I am getting the below message.
{
“status”: “error”,
“errors”: [
{
“errorCode”: “UDAPI100058”,
“message”: “No segments for these users are active. Manual reactivation is recommended from Upstox app/web.”,
“propertyPath”: null,
“invalidValue”: null,
“error_code”: “UDAPI100058”,
“property_path”: null,
“invalid_value”: null
}
]
}

I am passing the same with the C# code but its not working. Whats wrong with mu code ?

Now, I have changed my code… see the updated code below. Now, the API response is Unauthorized.

What is wrong with my C# code. Please advise.
code = “3RMGB8”;

        using ( httpClient = new HttpClient () )
        {
            var formData = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string> ("code", code),
                new KeyValuePair<string, string> ("client_id", clientID),
                new KeyValuePair<string, string> ("client_secret", clientSecret),
                new KeyValuePair<string, string> ("redirect_uri", redirectURI),
                new KeyValuePair<string, string> ("grant_type", grantType)
            };

            HttpContent content = new FormUrlEncodedContent ( formData );

            HttpRequestMessage httpRequestMessage = new HttpRequestMessage ( HttpMethod.Post, "https://api.upstox.com/v2/login/authorization/token" );
            httpRequestMessage.Headers.Add ( "Accept", "application/json" );
            content.Headers.ContentType = new MediaTypeHeaderValue ( "application/x-www-form-urlencoded" );
            httpRequestMessage.Content = content;

            HttpResponseMessage response = httpClient.SendAsync ( httpRequestMessage ).Result;
            response.EnsureSuccessStatusCode ();
            string ss = response.Content.ReadAsStringAsync ().Result;
        }

To begin using your Client ID, you must enable at least one segment. Currently, no segment is enabled for your client ID.

For instructions on how to enable a segment, please visit this page: How do I activate segments from the Upstox web platform?