Canvas Data 2: A Guide to Understanding Namespaces

kyle_cole
Instructure
Instructure
0
224

Canvas.png

Intro:

When accessing your data via the DAP CLI or the API, it is important to understand where your data lives. DAP has a few different namespaces to break out the different data points that are available. A namespace is an abstract container or environment created to hold a logical grouping of unique identifiers. With DAP a namespace is used to contain the different areas of data that are being used. At the time of writing this post, there are three different namespaces:

  • canvas - holds the Canvas tables
  • canvas_logs - holds the tables for access logs
  • catalog - holds the Catalog tables (If you do not have a Catalog instance, the tables will be blank)


Here is the link to the documentation about available namespaces: Dap Datasets. Below, I am going to go over how to access the different namespaces via the API and CLI tool and what errors may occur when not using an available name space.


API:
Let's break down where to set the namespace in the API URL:

 

 

{{base_url}}/dap/query/{{namespace}}/table/{{table_name}}/data

 

 


As you can see, after "query" we declare the namespace of where you want the table to be located. For example, if we wanted to get the web_logs table, this is what the URL would look like:

 

 

https://api-gateway.instructure.com/dap/query/canvas_logs/table/web_logs/data

 

 

 

If you were to use a namespace that is not available, you would receive an “Object Not Found” type error. Below is a sample of the error you will encounter:

 

 

{

   "error": {

       "uuid": "5da0c0f3-0ff6-41dd-a2bc-2d0b8ff2a0a0",

       "kind": "namespace",

       "id": "something",

       "message": "The namespace 'someting' specified in the request is not valid.",

       "type": "ObjectNotFound"

   }

}

 

 


CLI:

Here is an example of that shows where to set the namespace when using the DAP CLI tool with your credentials set as environment variables:

 

 

dap initdb --connection-string postgresql://kyle:password@server.example.com/testdb --namespace canvas_logs --table web_logs

 

 

 

After the “--namespace” declaration, that is where you set the namespace in which the table you want is located. In the example above, we are using the canvas_logs namespace to access the web_logs table. As of v1.0 of the DAP CLI, you must declare a namespace; if you do not declare a namespace, you will receive the following error:

 

 

error: the following arguments are required: --namespace

 

 



If you declare a namespace that is not available, you will receive this error:

 

 

ERROR - namespace something not supported

 

 


Outro:

Just to recap, understanding and using the correct namespaces is important when it comes to accessing the data you want. If I have missed anything or if you have any questions, feel free to comment below!