Leading through Chaos - Insights and Actions • Browse the resources from the keynote presented by the Academic Strategy Team.
Found this content helpful? Log in or sign up to leave a like!
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 "https://portal.inshosteddata.com/api/account/self/dump ,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");
mac.init(signingKey);
byte [] rawHmac = mac.doFinal(signature.getBytes());
String result = Base64.encode(rawHmac);
String authorizationHeader = "HMACAuth " + getApiKey() + ":" + result;
System.out.println("Authorization header: \n" + authorizationHeader);
java.net.URL url = new URL("https://" + getBaseUrlData()+"/api/account/self/dump");
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());
Solved! Go to Solution.
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/dump and /api/account/self/dump/
Thank you to everyone who replied to my question.
Hi @msorrell1 ,
Before I go too deeply into this, I wanted to check and ensure you have permissions to access Canvas Data in your instance of Canvas? When you go to the Admin page, do you see 'Canvas Data'?
The permissions are different for Canvas Data than your regular admin account, and Canvas Data is something your CSM must have set up before hand. I wanted to double check this first, as a 401 is an unauthorised code, also you will need a separate API key which you generate on the admin page for Canvas Data, you must use this key rather than your usual access token for your main Canvas account..
Please let me know if that is the case, and if you are able to download the files directly via the admin panel, have set up the API key on that page, then we can take another look.
Hope that helps!
Stuart
Hi @stuart_ryan ,
Thanks for the reply. I do have access to the Canvas Data portal section of the admin page on Canvas. This is where I generated my API key and secret that I have been using in my API requests. I have also used this section on Canvas to manually download files from Canvas.
Hi @msorrell1 ,
Thanks so much for the clarification. So that tells me you have permissions and have the download flat files permission.
I have taken a look at the API and realised that this is a new realm of authorisation I have not encountered (or tested) before. Hence I am taking the opportunity to share your enquiry into the Data and Analytics group. I hope someone in there may be able to provide additional assistance.
I hope that helps, and apologise I cannot be of further assistance.
Cheers,
Stuart
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/dump and /api/account/self/dump/
Thank you to everyone who replied to my question.
To interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign inTo interact with Panda Bot, our automated chatbot, you need to sign up or log in:
Sign in