Skip to content

Instantly share code, notes, and snippets.

@slint
Last active May 29, 2024 14:25
Show Gist options
  • Save slint/2263b2212743a68b2851b2cb7865675e to your computer and use it in GitHub Desktop.
Save slint/2263b2212743a68b2851b2cb7865675e to your computer and use it in GitHub Desktop.
  1. Create an access token at "https://zenodo.org/account/settings/applications/tokens/new/" with the "deposit:write" and "deposit:actions" scopes, and keep it somewhere safe (we'll refer to this token as ZENODO_TOKEN)
  2. Create your deposit via the web interface at "https://zenodo.org/deposit/new", fill in the minimum metadata (title, authors, description, access rights and license) and click "Save".
  3. On your browser's URL, you will now see the deposit ID in the form "https://zenodo/deposit/".
  4. Next step is to get the file upload URL. Via curl (or your HTTP client of preference) you can do:
$ # Store the Zenodo token in an envionrment variable
$ read -s ZENODO_TOKEN
$ curl "https://zenodo.org/api/deposit/depositions/222761?access_token=${ZENODO_TOKEN}"
{ ...  
  "links": { "bucket": "https://zenodo.org/api/files/568377dd-daf8-4235-85e1-a56011ad454b", ... },
... }
  1. Now you can use the URL from the links.bucket field from the response, and perform the following request to upload your file:
# This does a file stream PUT request to the "links.bucket" link
$ curl --upload-file "/path/to/your/file.dat" "https://zenodo.org/api/files/568377dd-daf8-4235-85e1-a56011ad454b/file.dat?access_token=${ZENODO_TOKEN}"
{ ... }
  1. After the upload has finished, you can click the "Publish" button on the upload's page.
@patrick-broos
Copy link

patrick-broos commented Sep 23, 2023

After being confused by the instructions above, I wrote yet another description of the procedure ...

The command syntax below is for the csh/tcsh shells under Unix/Linux.

  1. In a command line shell, move to the directory holding the files to upload.

  2. At https://zenodo.org/account/settings/applications/tokens/new/ create an "access token" with the "deposit:write" and "deposit:actions" scopes. Save the token in your notes, and in an environment variable, e.g.
    setenv ZENODO_TOKEN kLbOoMwEiDZDdfLOJ6oJX4UlQS4fwyzjWxTA9ZTcSCsBh3Ti7QC1LtqfFGbp

  3. At https://zenodo.org/deposit/new fill in the required fields (red) for a new upload in the usual way:

  4. Press the Save button, then look for a 7-digit "deposit ID" at the end of the URL shown in that browser window. Save that ID in your notes and in an environment variable, e.g.
    setenv DEPOSIT_ID 8371329

  5. In the shell where you've defined those environment variables, run the following curl query:
    curl "https://zenodo.org/api/deposit/depositions/${DEPOSIT_ID}?access_token=${ZENODO_TOKEN}"

  6. In the long string returned by that query, look for a URL following the word "bucket", and save that URL in your notes and in an environment variable, e.g.
    setenv UPLOAD_URL "https://zenodo.org/api/files/dcabeb90-3791-462d-ae83-d29dd2f32e4e"

  7. Use your shell's looping mechanism to upload a list of files, e.g.

foreach file (pointsource.tar.gz observations.tar.gz particle_background.tar.gz diffuse.tar.gz)
   printf "\nUploading ${file} ...\n"
   set file_basename=`basename ${file} .tar.gz`
   set       logfile=curl_${file_basename}.log
   curl --retry 12 --retry-all-errors -o ${logfile} --verbose --include --no-clobber  --upload-file ${file}   "${UPLOAD_URL}/${file}?access_token=${ZENODO_TOKEN}"

end

For my unreliable Internet connection, the --retry 12 --retry-all-errors options were absolutely required.

  1. Confirm that all files were uploaded:
    curl "https://zenodo.org/api/deposit/depositions/${DEPOSIT_ID}/files?access_token=${ZENODO_TOKEN}"

  2. AFTER EVERYTHING IS UPLOADED, press the Publish button on the upload page created in step #2.

My experience has been that once an Zenodo archive has been published, another upload attempt with curl will fail, with the message:

{"status": 403, "message": "Bucket is locked for modifications."}

Within the first 30 days, Zenodo Support can help you make modifications to a published archive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment