Reputation: 900
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();
Upvotes: 0
Views: 2664
Reputation: 1687
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
Upvotes: 1
Reputation: 30087
I see few mistakes in your sample:
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
Upvotes: 0