XBlock REST API

I’m trying to use XBlock REST API endpoints listed in swagger API docs.
None of them seems to work since I am getting ‘Opaque key does not have a learning context’ error.
I have read edx docs about ‘Usage Id’ which seems to be the same to {usage_key_str} mentioned in swagger. And my {usage_key_str} looks very similar to example given there.
https://edx.readthedocs.io/projects/open-edx-building-and-running-a-course/en/latest/course_features/lti/lti_address_content.html

According to source code the error falls every time when the given key is not class or subclass of LearningContextKey or UsageKeyV2.
My key has BlockUsageLocator class which is child of UsageKey (not UsageKeyV2)

Is it bug or those endpoints work only with some specific xblocks? (I’m trying to fetch data about simple course block)

Hi @alexB,

Most likely you are trying to use the “new” XBlock API, and your guess is correct - that API only works with a subset of XBlocks, namely those stored in Blockstore. So currently that means it only works with XBlocks in Content Libraries v2, whose IDs/keys start with lb:

If you are trying to fetch data about “a simple course block”, whose ID/key starts with block-v1:, you need to use the course blocks API instead. If that doesn’t cover your use case, let us know what you’re trying to do.

1 Like

Hi @braden, thank you for your answer.

What I’m trying to do is slightly customize default xblocks (e.g. replace assessment input components with my own).
I thought it would be nice to fetch olx or at least html of specific xblock, parse it somehow and display it the way I need.
Unfortunately, the course blocks API you suggested doesn’t provide enough info to do that.

To be honest I’m struggling with choosing the best way to customize built-in xblocks since I didn’t find any info about it in docs. It would be also good if there was something like comprehensive theming for this.
Would be very grateful for every suggestion!

Hi @alexB, if you request the student_view_data from the course blocks API, it will return a JSON object which contains the data that you need to power your own UI. This is the same information that the mobile app uses to display a native UI for some XBlock types on mobile. However, that approach requires completely re-implementing the UI yourself. If you just want to make minor changes, you’d need to either just use pure CSS or subclass the XBlock and create a new XBlock that applies your modifications on the backend.

There is also an API to get the OLX of a block, but it’s only usable by staff users because the OLX contains the answers. So you can’t use it for something like this.

Thank you, @braden.
student_view_data in blocks API is something I was looking for.
Sadly, according to your post there is no support for problem blocks, which is important for me.
Will be looking for other workarounds.

Hello @alexB

I’m looking to do something similar; a rest api that returns the params on the Edit screen of an lti_consumer xblock.

If you find something, or come up with something yourself please let us know. I’ll do the same.

Thanks
David