AnsweredAssumed Answered

How to use the Data API

Question asked by Matthew Sorrell on Aug 10, 2018
Latest reply on Aug 13, 2018 by James Jones

I have been reading different Canvas forms and how to on how to do this, but I am still not figuring it out. I am reading the documentation at Canvas Data Portal ,but it is really confusing. Whenever I make my API request, all I receive is the HTML data of the homepage of the Canvas Data Portal. I am writing my code in Java.  Here is some of my code:

 

            String time = getCurrentTime();
            String signature = "GET\n" + getBaseUrlData() + "\n\n\n" + "/api/account/self/file/latest\n" + time + "\n" + getSecret();

 

            SecretKeySpec signingKey = new SecretKeySpec(getSecret().getBytes(), "HmacSHA256");
            Mac mac = Mac.getInstance("HmacSHA256");
            mac.init(signingKey);
            byte [] rawHmac = mac.doFinal(signature.getBytes());
            String result = Base64.encode(rawHmac);
            System.out.println(result);

 

            String authorizationHeader = "HMACAuth " + getApiKey() + ":" + result;
            java.net.URL url = new URL("https://" + getBaseUrlData() + "api/account/self/file/latest");
            HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
            con.setRequestMethod("GET");
            con.setRequestProperty("Authorization", authorizationHeader);
            con.setRequestProperty("Date", time);

 

            System.out.println(con.getResponseCode());

Outcomes