Identify xblocks used on specific pages

I am trying to determine whether it is possible to identify the individual xblocks used on specific unit pages. The use cases are things like determining whether a specific xblock has actually been used before pushing updates of that xblock, identifying which xblocks exist on a unit page seen by a student, etc.

So far, my technical team has not found a way to do this. I’m hoping someone here has solved similar problems.

Hi @mikeh1239

The course blocks API should do what you want.

For example, on devstack you can use http://localhost:18000/api/courses/v1/blocks/?course_id=course-v1:edX%2BDemoX%2BDemo_Course&username=staff&depth=all to get all the blocks in a course. (To use this API on another server, you’ll need to change the domain name, course ID, and username).

The entries will look like this:

"block-v1:OpenCraft+onboarding+course+type@html+block@open_edx_devstack_introduction_1":{
   "id":"block-v1:OpenCraft+onboarding+course+type@html+block@open_edx_devstack_introduction_1",
   "block_id":"open_edx_devstack_introduction_1",
   "lms_web_url":"https://courses.opencraft.com/courses/course-v1:OpenCraft+onboarding+course/jump_to/block-v1:OpenCraft+onboarding+course+type@html+block@open_edx_devstack_introduction_1",
   "student_view_url":"https://courses.opencraft.com/xblock/block-v1:OpenCraft+onboarding+course+type@html+block@open_edx_devstack_introduction_1",
   "type":"html",
   "display_name":"Text"
}

What you want is "type": "html" - this indicates the type of each XBlock, and the entire response will let you quickly scan to check the types of all XBlocks in the course.

If you only want to check the blocks used on a single unit, get the unit’s ID (which should include vertical) then use this similar API:

https://yourlms.com/api/courses/v1/blocks/block-v1:org+course+run+type@vertical+block@block_id/?username=your_username&depth=all

The response format is the same, but it will only return a single unit.

Thank you for your generosity and expertise!

1 Like