Our application from previous lesson can request simple requests like /connect/shema which are not required authentication. For other requests authentication is required. You must have an authentication token for each cTrader ID you use in your application. Let's create an authentication token and try to request list of trading accounts.
If you want to get an authentication token for cTrader ID, you should run actions described in OAuth Services Description section of API Reference.
But for testing our Open API you can use steps, described in Playground section. This authentication token will be requested for our test application "Test Partner" registered in sandbox connect site.
- At first click to "Send Accounts API OAuth Request" link. You will see a page requesting rights for your token.
- After you clicked "Allow Access" you would be redirected to the Playground page with short-time live authorization code in URL string. This code you have to exchange to authentication token. Within 10 seconds click the link "Exchange the Code with Access Token" on the Playground page. Your token will be displayed in separate tab/window like:
- Then you can open Java project from previous lesson and modify it. In our project we created a wrapper for Account API services, moved method for URL requesting to it and added a method for building string URLs for requests according to Accounts API Guide. You should replace static field ACCOUNTS_API_TOKEN in file App.java by your token requested above.
Sources of this lesson you can find at GitHub