User Call Report API gives incorrect results

2019-04-02 02:01发布

I am trying to use the User Call Report API from Sinch's Reporting API (from Voice REST API). Unfortunately, the response give by User Call Report API is incorrect (it indicates no calls when calls did happen).

Specifically, I am accessing the URL:

https://reportingapi.sinch.com/v1/users/username/aaa/calls/data

for username aaa. The response is:

{"start":"2016-05-18T00:00:00","duration":0,"success":0,"failed":0}

Today is June 17th, 2016.

This response is incorrect. Yesterday, June 16th, 2016 I made several app-to-app calls (i.e., over "data") using user aaa and therefore the response should have indicated a non-zero "duration" and a non-zero "success".

Note that in the Sinch Dashboard -> Reports -> GENERATE USAGE REPORTS the CSV format report does show yesterday's calls made with aaa like this:

call ID here;user space ID here ;2016-06-16T17:21:05Z;ANSWER;HUNGUP;10;aaa;bbb;headers here;application key here
call ID here;user space ID here ;2016-06-16T17:22:08Z;ANSWER;HUNGUP;35;aaa;bbb;headers here;application key here

I.e., midnight UTC and PDT have already passed and the Call Detail Records (which are generated once a day) indicate that indeed the calls have happened.

Do you have any hint to what the problem may be?

I am accessing User Call Report API using code adapted from this Sinch tutorial:

https://www.sinch.com/tutorials/sign-requests-java/

with minor modifications (e.g., GET instead of POST, connection.setDoInput(true) instead of connection.setDoOutput(true), etc). If it helps with anything, this is my exact code:

public static void send() {
    try {

        String key = "key here";
        String secret = "secret here";

        // timestamp
        Date date= new java.util.Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        String timestamp = dateFormat.format(date);

        // other items
        String httpVerb = "GET";
        String path = "/v1/users/username/aaa/calls/data";
        String contentType = "application/json";
        String canonicalizedHeaders = "x-timestamp:" + timestamp;

        String contentMd5 =""; // because it is a GET 

        // signing
        String stringToSign = httpVerb + "\n" + contentMd5 + "\n" + contentType + "\n" + canonicalizedHeaders + "\n" + path;
        String signature = signature(secret, stringToSign);
        String authorization = "Application " + key + ":" + signature;

        // make the call
        URL url = new URL("https://reportingapi.sinch.com" + path/*+"?_start=2016-06-13&_stop=2016-07-10"*/);

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.setRequestMethod("GET");
        connection.setRequestProperty("content-type", "application/json");
        connection.setRequestProperty("x-timestamp", timestamp);
        connection.setRequestProperty("authorization", authorization);

        StringBuilder response = new StringBuilder();
        BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String line;
        while ( (line = br.readLine()) != null)
            response.append(line);

        br.close();

        System.out.println(url);
        System.out.println(response.toString());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
private static String signature(String secret, String message) {
    String signature = "";
    try {
        Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
        SecretKeySpec secret_key = new SecretKeySpec(Base64.decodeBase64(secret.getBytes()), "HmacSHA256");
        sha256_HMAC.init(secret_key);
        signature = Base64.encodeBase64String(sha256_HMAC.doFinal(message.getBytes()));
    } catch (Exception e){
        System.out.println("Error");
    }
    return signature;
}

Does anybody have any suggestion about this?

Thanks!!

标签: sinch
0条回答
登录 后发表回答