- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2023 10:08 AM
@haiderpasha mohammed :
I see. In that case, it's possible that the getContext() method does not exist in the version of the Databricks runtime that the shared Unity Catalog cluster is running on.
One workaround you could try is to instead use the REST API to get the notebook ID. You can do this by sending an HTTP GET request to the following endpoint:
https://<databricks-instance>/api/2.0/workspace/get?path=<notebook-path>;Replace <databricks-instance> with the URL of your Databricks instance, and
<notebook-path> with the path to your notebook, including the notebook name and extension. The response from this endpoint will include a notebook_id field with the ID of the notebook. You can extract this ID from the JSON response and use it in your code. Here's an example of how you could make this request in Python:
import requests
import json
# Set the endpoint URL and path to your notebook
endpoint = "https://<databricks-instance>/api/2.0/workspace/get"
notebook_path = "/path/to/notebook"
# Set up the request parameters
params = {
"path": notebook_path
}
# Send the GET request
response = requests.get(endpoint, params=params)
# Extract the notebook ID from the response
response_json = json.loads(response.content)
notebook_id = response_json["object_id"]
# Print the notebook ID
print(notebook_id)Let me know if this helps!