Question

I am using Cleartrip Flight API to get flight fare details. When request the URL with API key, i am getting "Not authorized to access the service" error. Here is my Java code using Apache HttpComponents

HttpHost proxy = new HttpHost("My IP", Port No, "http");

String url = "https://api.cleartrip.com/air/1.0/search?from=BOM&to=DEL&depart-date=2013-06-06&return-date=2013-06-06";

    //String url = "http://www.google.com/search?q=developer";

    HttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    HttpGet request = new HttpGet(url);

    // add request header
    request.addHeader("X-CT-API-KEY", "My API Key");
    request.addHeader("User-Agent", "Mozilla/5.0");



    System.out.println(" header "+request.getHeaders("X-CT-API-KEY")[0]);
    HttpResponse response = client.execute(request);

    System.out.println("\nSending 'GET' request to URL : " + url);
    System.out.println("Response Code : " + 
                   response.getStatusLine().getStatusCode());

    BufferedReader rd = new BufferedReader(new  InputStreamReader(response.getEntity().getContent()));

    StringBuffer result = new StringBuffer();
    String line = "";
    while ((line = rd.readLine()) != null) {
        result.append(line);
    }

    System.out.println(result.toString());
}

Can anyone help me !!!

Was it helpful?

Solution

Even i had the same issue. Later i came to know that all the api (which you get during singn up process) are blocked by default. You have to write a mail to api.support@cleartrip.com

They will ask your company details, business model and business case. If they are satisfied with those details then they will unblock your api key.

Since my project is for my final semester they have rejected my api key query.

Here i am sharing my java code. So that it might be useful for some one.

        HttpClient client = new DefaultHttpClient();
        String getURL =URL;
        Log.d("URL",getURL);
        HttpGet get = new HttpGet(getURL);
        get.setHeader("X-CT-API-KEY", (my api key));
        HttpResponse responseGet = client.execute(get);
        HttpEntity resEntityGet = responseGet.getEntity();
        if (resEntityGet != null)
        {
            Log.i("GET ", EntityUtils.toString(resEntityGet));
        }

Since i was not authorized to use this api i got the following response.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><faults xmlns="http://www.cleartrip.com/apigateway/common"><fault><fault-message>Not authorized to access the service</fault-message></fault></faults>

HTTP URL is as follows

https://api.cleartrip.com/air/1.0/search?from=BOM&to=DEL&depart-date=2013-11-11&return-date=2013-12-12
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top