cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
tyler_clair
Community Champion

Storing Custom Data

So for the past few years I have seen the custom data API that is attached to a user's account: https://canvas.instructure.com/doc/api/users.html#method.custom_data.set_data. This seems like it could have limitless potential as you can store as much JSON data as you want and I was wondering if anyone has used it?

Labels (1)
Tags (2)
13 Replies
tomtullio
New Member

Hi Tyler.  For the last couple of weeks I've been attempting to make sense of this API, but with little success.

Since adopting Canvas last fall, I've had a ton of fun figuring out ways to use the API (via PowerShell) to automate & customize, but this one has me stumped.

The best I get is an "invalid namespace" error -- but more often, "The specified resource does not exist."

Has anyone else made better progress?

aclement
New Member

 @tyler_clair  and tomtullio,

I have used the User Custom Data endpoint to let our teachers set their own default due date time.. The work flow is a little complicated, but the gist of it is:

  • All data must be namespaced. This is to keep the data from different services and tools separate even if they might share a key.
    • If you try to GET a namespace that has not been created, it will tell you that there is no data
    • To create/change a namespace you must make a PUT request with a ns parameter in the body of the request
  • When you PUT, you overwrite all of the keys that you send, so make sure to save anything that you need

If you want to see some example code you can look at my repo on Github​.

Hi Alex!

I was so intrigued by your post here, so I've got to make a follow-up question:

- How is this custom due date data used?

yaach
Community Member

Hi All,

I started playing with custom data APIs. Storing data as the API documentation dictates does not give me any issues, however in order to verify and/or retrieve what I have store, I got the message "invalid namespace". I am sure I am using the same namespace I used for the store api call.

Any thought?

samuel_malcolm
Community Participant

At our institution we want to make a custom global dashboard item that goes smaller once a user has clicked on it once. I thought this API would be a good way of cross checking if a user has done so but I cant seem to get the API to return anything other than a 422 error when making the request

0 Kudos

I don't have any trouble with a simple store and retrieve with curl.

Can you give an example of what gives the 422?

samuel_malcolm
Community Participant

For some reason i was unable to do it with boilerplate JS, However im successfully using it with Jquery now

0 Kudos
jack0x539
Community Member

We use it without issues, other than the fact that it's additional calls, which through large numbers of updates slow things down. Currently, we store an additional unique identifier for every user, and their primary role at the institution.

robotcars
Community Champion

jack0x539‌,

I assume your doing this on the backend with ruby, python or something similar and not in JavaScript?

This is the part that annoys me the most. I've been working on a project and I do not seem to have a definitive way in Canvas to identify what type of user they are in our institution. I want to store an explicit 'employee' or 'student' value somewhere, but I do not want to run an API call for 350,000 users or the logic to keep it updated.

The api has a field for 'title', but there seems to be no way to set it without using the API.

We prefix an E to all employee SISID's, but when non-root-admin users pull the api request, sis_user_id is excluded.

0 Kudos
phanley
Community Contributor

We've been looking at it as an option for decreasing the load on our in-house SIS/LMS middleware (Course Tools) but in a lot of the use cases we would like the ability to search the custom data (hypothetically search for adjunct users: 

curl -H "Authorization: Bearer dfhs~hfefhblahblahblhablah"\
-X GET "https://instance.instructure.com/api/v1/users/custom_data/search/" \ [note - this API url is not real]
-F 'ns=edu.university.support' \
-F 'data[is_adjunct]=true' \
| jq --raw-output  

)

We're moving from Blackboard Learn (almost done!) and one thing our group really misses is the ability to give users institutional roles that are functional (yes, Canvas has account roles, but they don't really replace Bb Learn's roles -- quick example that seems trivial until you depend on it would be that we could mark users as instructors from SIS data, but they wouldn't have to be enrolled in any courses to see instructor-appropriate options in the UI). 

We are still looking at it to mark who gets the Course Tools button injected into the global nav, instead of the ajax check we have now that hits our middleware server.  

0 Kudos
jperkins
Instructure
Instructure

Here is a working script for this API endpoint. https://github.com/unsupported/canvas/tree/master/api/custom_user_data .

Boekenoogen
Community Contributor

This script looks promising. I will have to get my team to look at it. 

0 Kudos
maguire
Community Champion

I have used user custom data to be able to customize an LTI tool to collect information about a student's degree project. Currently, students fill out a form describing the degree project that they want to do. The course code that students have to sign up for differs depending upon which program of study the student is in (and perhaps even their specialization (track within this program). I have examined how to use the custom data to store the information about the student's program of study. For example for two test students (the text for the major/track is in Swedish):

custom data for user James FakeStudent is {'data': {'programs': [{'code': 'TIVNM', 'name': "Master's Programme, ICT Innovation, 120 credits", 'major': 'Datalogi och datateknik', 'track': 'HCID', 'start': 2016}]}}
user name=Karolin FakeStudent with id=27 and sis_id=z11


custom data for user Karolin FakeStudent is {'data': {'programs': [{'code': 'TIVNM', 'name': "Master's Programme, ICT Innovation, 120 credits", 'major': 'Elektroteknik', 'track': 'INSY', 'start': 2016}]}}

When the student provides their information via a dynamic survey, the student's questions and alternatives for answers are adapted based upon the student's program. The code for this (SinatraTest21.rb) and documentation can be found at  https://github.com/gqmaguirejr/E-learning

Extensive details about this can be found in a recent Bachelor's thesis:

Reshad Sarwar and Nathan Manzi, More tools for Canvas : Realizing a Digital Form with Dynamically Presented Questions and Alternatives. Stockholm, Sweden: KTH, Communication Systems, CoS, 2019, TRITA-EECS-EX-2019:93 [Online]. Available: http://urn.kb.se/resolve?urn=urn%3Anbn%3Ase%3Akth%3Adiva-251021http://urn.kb.se/resolve?urn=urn%3Anbn%3Ase%3Akth%3Adiva-251021

Unfortunately, to automatically populate the custom data requires information from another system that I do not yet have access to - so my prototype works only with fake data.

0 Kudos