AnsweredAssumed Answered

401 Response with Canvas Data API

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

I am building an Java application that will communicate with the Canvas Data API and receive the data. I have followed other tutorials and the documentation from the Canvas community. The current code I have receives a 401 HTTP error when I make the request. The current request URL is " ,but if I change the url to request /api/schema then the response is 200 and I receive data from the API. Here is my current code:


String time = getCurrentTime();
String signature = "GET\n" + getBaseUrlData() + "\n\n\n" + "/api/account/self/dump?after=45&limit=100/\n\n" + time + "\n" +    getSecret();
SecretKeySpec signingKey = new SecretKeySpec(getSecret().getBytes(), "HmacSHA256");
Mac mac = Mac.getInstance("HmacSHA256");
byte [] rawHmac = mac.doFinal(signature.getBytes());
String result = Base64.encode(rawHmac);


String authorizationHeader = "HMACAuth " + getApiKey() + ":" + result;
System.out.println("Authorization header: \n" + authorizationHeader); url = new URL("https://" + getBaseUrlData()+"/api/account/self/dump");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setRequestProperty("Authorization", authorizationHeader);
con.setRequestProperty("Date", time);