0

We are trying to connect to omniture rest API 1.4 using Java for report.Get. We are unable to create connection. The user id and password are working fine on UI but while making HTTP connection we are getting 400 bad request. Same code works fine with rest API 1.3 for company.reportSuites method. Code if failing while creating input stream. We did checked HTTP response code for connection at it is also coming 400.

public class OMTR_REST {
        private static String USERNAME = "XXXXXXX";
    private static String PASSWORD = "xXXXXXXXX";
    private static String ENDPOINT = "https://api.omniture.com/admin/1.4/rest/"; //san jose endpoint, change for your company's datacenter

    private OMTR_REST() {}

    public static String callMethod(String method, String data) throws IOException {
        URL url = new URL(ENDPOINT + "?method=" + method);
        URLConnection connection = url.openConnection();
        connection.addRequestProperty("X-WSSE", getHeader());

        connection.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
        wr.write(data);
        wr.flush();

        InputStream in = connection.getInputStream();
        BufferedReader res = new BufferedReader(new InputStreamReader(in, "UTF-8"));

        StringBuffer sBuffer = new StringBuffer();
        String inputLine;
        while ((inputLine = res.readLine()) != null)
            sBuffer.append(inputLine);

        res.close();

        return sBuffer.toString();
rene
  • 41,474
  • 78
  • 114
  • 152
Tanveer
  • 890
  • 12
  • 22
  • Contact customer care. I had the same problem at my previous company 2 months ago and I think there was a bug. I was working directly with a developer to figure it out. I wish I had access to those emails but unfortunately, timing is everything. – BrettAHale Jun 26 '14 at 15:46
  • Thanks Brett. I was wondering if anybody else was facing similar issues for this. We tried all possible things but no luck. Will get in touch with the customer care. – Tanveer Jun 26 '14 at 18:02
  • last i heard there's a bug w/ the oauth authentication. The traditional username:company and secret key/token (you get this from adobe analytics user admin) works. I haven't used it with java but I've used it plenty v1.3 and v1.4) with php – CrayonViolent Jun 26 '14 at 23:33
  • Thanks Crayon. We were facing issue with traditional password digest method with java for 1.4 api. Its working fine with api 1.3. – Tanveer Jun 27 '14 at 09:35

2 Answers2

1

There was a change in the API from version 1.3 to 1.4. The Get method now returns a status of 400 if the report in not ready. To me, it was a bad choice to return a HTTP 400 error (Bad request) when the report in not ready but that is what they are doing. See page 13 in the document below.

https://github.com/AdobeDocs/analytics-1.4-apis

Divyesh Kanzariya
  • 3,629
  • 3
  • 43
  • 44
rwsimmo
  • 1,657
  • 1
  • 13
  • 10
  • The Get method returns a status of 400 even if the report is delivered. the error message shows as delivery complete, but still the status code is 400. Is this expected? `com.spr.exceptions.HTTPRequestFailedException: {ERROR_BODY={"error":"delivery_complete","error_description":"Delivery complete","error_uri":null}` – Saket Mehta May 08 '17 at 14:00
0

I see few mistakes in your sample:

  1. you should not use api.omniture.com for every request. First request should call api.omniture.com using Company.GetEndpoint method in order to get the correct endpoint, then use it for next requests.
  2. when a wrong endpoint is used you could receive an HTTP 301 response. I'm not sure your implementation handle this case.
  3. when you receive a HTTP 400 error (bad request). Well, that's exactly what has happened, in your example you're JSON writing directly into the body and many things could go wrong. Wrong type for a value, wrong upper/lower case for a key. Using a JAX-RS or another REST client should make your life simpler.

I have built a working Omniture REST API sample with JAX-RS where the model is clear easy to debug/modify.

Update

Recently I have found this:

https://github.com/Adobe-Marketing-Cloud/analytics-java-library

freedev
  • 25,946
  • 8
  • 108
  • 125