export tgz of notebook from command line

I’m trying to download a tgz of a private notebook from the command line, following the documentation:

curl https://api.observablehq.com/d/bbcf2ac87f678321@339.tgz?v=3&api_key=my_api_key

I get a {"errors":[]} response. If I make the notebook public, I get the tgz response.

I’ve tried with the api key as a query parameter (as shown) and also as an HTTP header, but get the same response when the notebook is private.

I’d appreciate any help with troubleshooting!

Looks like you are following the instructions in the documentation, but just checking whether your notebook is shared with the while team (in the notebook sharing settings). There is a note in the docs:

Note
For private Teams notebooks, the notebook has to be shared with the whole team for the API key to have access.

I have tried changing the Team permissions to “Can view and edit” but after I Save and re-open “share” it still is listed as “Can view”.

I’m realizing I don’t understand what it means for a notebook to be a private Teams notebook (I am on the Starter Team tier, and there is no one else on a team)

That does look like you have team view access (for your team of 1 :slight_smile: ), so that is probably not the issue. BTW, don’t forget to hit ‘Save’ after changing the access to ‘Can view or edit’… that is probably why that setting is not changing for you.

I tried both methods with a private notebook and an api key in a starter tier and it works for me. Could you try enclosing the full url (with the api_key) in quotes?

Thank you so much for your help! I was not expecting responses so quickly (and please feel free not to reply on the weekend!).

Here’s a screencap of trying different methods (with api key redacted). It’s showing the first call using a query parameter that doesn’t return the tgz, a second call using the header that doesn’t return the tgz, and a third call after changing the public permissions that is successful (the warnings are just because I didn’t save the result to a file):

Also, in case it’s helpful, here’s a screen recording of trying to change the Team permissions and having them always revert to “can view” (even if it’s not relevant in this situation):

Kapture 2024-08-24 at 09.45.54

@stringertheory How and (roughly) when did you create the API key, and did you give it the “View notebooks” scope?

I first tried with one I created several months ago, but also with one I created yesterday.

The api keys don’t have the “view notebooks” scope — that sounds like the problem, but how do I give that scope? In https://observablehq.com/settings/api-keys, the only options I get when in “New API Key” for the scopes are “create new projects” and “deploy new versions of projects”

This creates a personal API key. For notebooks you’ll have to create the key via the workspace settings, then grant the team view access to the notebook.

Alternatively you can create a key only for this particular notebook:

  1. open the notebook’s embed modal,
  2. create a notebook key via the right pane in the modal,
  3. change the preview to “Runtime with JavaScript”,
  4. copy the URL after import define from
  5. replace “.js” in the URL with “.tgz”

If you don’t pin the key this should allow you to also download future versions.

Ah, didn’t notice the difference between personal settings and workspace settings. I made a new API key there, gave it the “view notebooks” scope, and was able to download the tgz.

Thank you!!

1 Like