Jump to content
Sign in to follow this  
tigermc

Unauthorized Trying to get Token

Recommended Posts

Hello,  

I am mainly a database and desktop application developer, so REST API is new to me.

When using the below C# code I keep getting error 401 - Unauthorized back.  Is the code even remotely close to trying to obtain a valid token?  I added XXXX instead of the actual credentials. 

Do you have a full example like below that will get a token back?

            string myJson = "{'Username': 'DAXXXXXXX','Password':'XXXXXX','AppKey':'K.XXXXXX'}";
            using (var client = new HttpClient())
            {
                var response = await client.PostAsync(
                    "https://ciapipreprod.cityindextest9.co.uk/TradingAPI/session",
                     new StringContent(myJson, Encoding.UTF8, "application/json"));
            }

Share this post


Link to post

Hi Tiger,

I think the main issue with the snippet above is that you are trying to connect to the Pre-Production Environment (PPE) rather than the Live environment. Accounts are not cross compatible across environments - hence the 401 Unauthorized. 

PPE is used internally only, so your account (whether a demo or actual Live account) can only connect to the Live environment.

Try switching the URL to the Live environment: https://ciapi.cityindex.com/tradingapi/

Kind Regards, PM

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×