I have been trying to use the Canvas Data API (https://portal.inshosteddata.com/docs/api), but I haven't been able to receive the data I have been requesting. 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 not receiving any data from the url that I want. I am writing my code in Java. According to the documentation I am supposed to use GET, HmacSHA256 for encoding my signature, and an Authorization and Data header. Here is some of my code:
String time = getCurrentTime();
System.out.println(time);
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;
System.out.println("Authorization header: " + authorizationHeader);
java.net.URL url = new URL("https://" + getBaseUrlData() + "api/account/self/file/latest");
System.out.println(url);
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", authorizationHeader);
con.setRequestProperty("Date", time);
System.out.println(con.getResponseCode());
I solved my issue. My url path that I was placing in the signature for the request ended with a "/" character when it should not have. I didn't realize that there was a difference in /api/account/self/file/latest and /api/account/self/file/latest/