Celebrate Excellence in Education: Nominate Outstanding Educators by April 15!
Found this content helpful? Log in or sign up to leave a like!
I've used Postman and am able to get data from Canvas Data Portal 2. I'm trying to do the same thing in Python. I'm able to get all the preliminary steps (GetJWT, Dispatch query, get status of query) in python, but get a bad request format when trying to get request object url. I suspect the issue is what I'm sending as data. The following is the code I'm using to try to get the request object url.
url = "https://api-gateway.instructure.com/dap/object/url"
data = {"id":[str(queryid)]}
userinfo = requests.post(url, headers=token, json=data).json()
I've attempted [{"id":str(queryid)}] , ["id":str(queryid)] , and {"id": str(queryid)} with no luck. Any idea where I'm going wrong or have an example of it working? With [{"id":str(queryid)}], the error changes to Unsupported query objects format.
Hi, Are you using Instructure provided Python Library/CLI
or are you writing your own vanilla code?
I am writing my own code, but I will take a look and see if it has anything I can use.
You can check the source code by downloading it from here: https://pypi.org/project/instructure-dap-client/#files
Hi @steven_hill , not sure that this will help you with your code but may give you some ideas on what could be wrong with yours perhaps. I wrote this code a while ago in nodejs, and it's still working fine as far as I understand. Here is the function that retrieves the object URLs:
const retrieveObjectURLs = async (responseData, authResponse)=> {
const {id, status, at, objects} = responseData
if (authResponse) {
authResponse = await ensureValidToken(authResponse)
} else {
authResponse = await ensureValidToken(currentlyValidToken)
}
if (authResponse) {
let jwt = authResponse.access_token ? authResponse.access_token : authResponse
let authHeaders = { "x-instauth": jwt }
console.log("Will now retrieve data for completed job: " + id + " which has ended at: " + at)
let endpointObjectsList = dap_URL + "/object/url"
try {
let response = await axios( { method: 'POST', url: endpointObjectsList, headers: authHeaders,
data: objects})
if (response && response.data) {
console.log("Obtained object URLs response as follows: ", response.data)
return response.data.urls
}
} catch(error) {
console.log("Oops! Could NOT retrieve object URLs !:", responseData)
console.log("Obtained error from Axios when retrieving object URLs: ", error)
console.error(error, error.stack)
throw error
}
}
}
You can also find the complete code at GitHub - pgoldweic/DAP-nodescripts-beta: Repository containing nodejs scripts for downloading Canvas...
Thanks for the help. I haven't figured it out yet and will continue to work on it as time allows. In the meantime, since we're able to get the data through Postman, we will be using that.
To participate in the Instructure Community, you need to sign up or log in:
Sign In