Skip to content

Instantly share code, notes, and snippets.

@slint
Last active April 6, 2024 03:31
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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.
@AZaitzeff
Copy link

As a note, to get the curl commands to work for me, I had to wrap the URLs in quotes.

@ElisabethKugler
Copy link

Brief "How-To" Guide for Windows10 uploading data via cURL to Zenodo - from a biologist.

Extends the above: https://gist.github.com/slint/2263b2212743a68b2851b2cb7865675e
CAPITAL_WORDING: refers to things that need to be replaced with YOUR individual ones

Step 1: Create an access token at "https://zenodo.org/account/settings/applications/tokens/new/" with the "deposit:write" and "deposit:actions" scopes.
Make sure you keep it somewhere safe. It is a combination of letters and numbers, something like "sqh791dig345fyuh"

Step 2: If you haven't yet, 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).
Click "Save".
On your browser's URL, you will now see the deposit ID in the form "https://zenodo/deposit/ID".

Step 3: Check whether you have cURL (e.g. if you have Git "C:\Program Files\Git\mingw64\bin"; or for Windows check: https://www.addictivetips.com/windows-tips/use-curl-on-windows-10/)

Step 4: Open command line by typing "cmd" into the Windows search. This should open up a command line window.

Step 5: Type "set token=sqh791dig345fyuh" into the cmd to store your token in an environment variable.
i.e. set token=YOUR_TOKEN_HERE

Step 6: Next get deposit information using your token >> "curl "https://zenodo.org/api/deposit/depositions/1234567?access_token=%token%""
i.e. curl "https://zenodo.org/api/deposit/depositions/YOUR_DEPOSIT?access_token=%token%

This will produce on output > look for something along the lines of: "bucket": "https://zenodo.org/api/files/568377dd-daf8-4235-85e1-a56011ad454b" - we call this YOUR_BUCKET_LINK

Step 7: Copy that link and type:
curl --upload-file "/path/to/your/file.dat" "https://zenodo.org/api/files/14b1818f-7449-4e24-b32b-23f0cd449104/file.dat?access_token=%token%"
curl --upload-file "FILEPATH.FILETYPE" "YOUR_BUCKET_LINK/FILEPATH.FILETYPE?access_token=%token%"

Step 8: Your data should now be uploading. Once this is finished, you can upload more data or go back to the Zenodo Browser, check Metadata, and publish the data.

OVERVIEW:
set token=YOUR_TOKEN_HERE
curl "https://zenodo.org/api/deposit/depositions/YOUR_DEPOSIT?access_token=%token%"
curl --upload-file "FILEPATH.FILETYPE" "YOUR_BUCKET_LINK/FILEPATH.FILETYPE?access_token=%token%"

@jkabisch
Copy link

And another comment from a biologist for a simple "for loop" to only upload specific file-types defined by a wildcard:

for file in *.fastq; do curl --upload-file $file YOUR_BUCKET_LINK/$file?access_token=${ZENODO_TOKEN}; done

@Svito-zar
Copy link

Did anyone get the following error before:
{"message":"The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.","status":404}

@jolespin
Copy link

This doesn't work for me:

(base) curl "https://zenodo.org/deposit/7485114?access_token=${ZENODO_TOKEN}"
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: <a href="/login/?next=https%3A%2F%2Fzenodo.org%2Fdeposit%2F7485114%3Faccess_token%3DStrgDgEZ12vJD0GRQEkiXmRSUrqdXehPoKexoKDlN4rBSFI5PnIhxKuTbMxg">/login/?next=https%3A%2F%2Fzenodo.org%2Fdeposit%2F7485114%3Faccess_token%3DStrgDgEZ12vJD0GRQEkiXmRSUrqdXehPoKexoKDlN4rBSFI5PnIhxKuTbMxg</a>.  If not click the link.(base)

I've deleted this access token.

@progsi
Copy link

progsi commented Feb 24, 2023

I get this response. Any idea why?

{"message":"You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.","status":403}

@clarkbab
Copy link

clarkbab commented Apr 12, 2023

Hi there!

I performed the curl to retrieve links.bucket:

$ curl "https://zenodo.org/api/deposit/depositions/7800783?access_token=$ZENODO_TOKEN"
{...,"links":{"bucket":"https://zenodo.org/api/files/9a2ec150-1d5c-463d-a5ae-dee09865a10e",...}

However when I try to upload to this URL, I get the following error message:

$ curl --upload-file "public-localiser-models.zip" "https://zenodo.org/api/files/9a2ec150-1d5c-463d-a5ae-dee09865a10e?access_to
ken=$ZENODO_TOKEN"
{"message":"The method is not allowed for the requested URL.","status":405}

It seems like the server doesn't like the --upload-file (POST) method at this address. My file is around 21GB so not sure if that's too large?

@naik-aakash
Copy link

naik-aakash commented Apr 12, 2023

Hi there!

I performed the curl to retrieve links.bucket:

$ curl "https://zenodo.org/api/deposit/depositions/7800783?access_token=$ZENODO_TOKEN"
{...,"links":{"bucket":"https://zenodo.org/api/files/9a2ec150-1d5c-463d-a5ae-dee09865a10e",...}

However when I try to upload to this URL, I get the following error message:

$ curl --upload-file "public-localiser-models.zip" "https://zenodo.org/api/files/9a2ec150-1d5c-463d-a5ae-dee09865a10e?access_to
ken=$ZENODO_TOKEN"
{"message":"The method is not allowed for the requested URL.","status":405}

It seems like the server doesn't like the --upload-file (POST) method at this address. My file is around 21GB so not sure if that's too large?
Can you try this:

curl --upload-file "public-localiser-models.zip" "https://zenodo.org/api/files/9a2ec150-1d5c-463d-a5ae-dee09865a10e/public-localiser-models.zip?access_to
ken=$ZENODO_TOKEN"

@clarkbab
Copy link

Thanks, was simply missing the filename in the upload URL. Also, there are some helpful tools that simplify this process e.g: https://github.com/jhpoelen/zenodo-upload.

@BoZenKhaa
Copy link

BoZenKhaa commented Jun 9, 2023

Brief "How-To" Guide for Windows10 uploading data via cURL to Zenodo - from a biologist.

Extends the above: https://gist.github.com/slint/2263b2212743a68b2851b2cb7865675e CAPITAL_WORDING: refers to things that need to be replaced with YOUR individual ones

Step 1: Create an access token at "https://zenodo.org/account/settings/applications/tokens/new/" with the "deposit:write" and "deposit:actions" scopes. Make sure you keep it somewhere safe. It is a combination of letters and numbers, something like "sqh791dig345fyuh"

Step 2: If you haven't yet, 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). Click "Save". On your browser's URL, you will now see the deposit ID in the form "https://zenodo/deposit/ID".

Step 3: Check whether you have cURL (e.g. if you have Git "C:\Program Files\Git\mingw64\bin"; or for Windows check: https://www.addictivetips.com/windows-tips/use-curl-on-windows-10/)

Step 4: Open command line by typing "cmd" into the Windows search. This should open up a command line window.

Step 5: Type "set token=sqh791dig345fyuh" into the cmd to store your token in an environment variable. i.e. set token=YOUR_TOKEN_HERE

Step 6: Next get deposit information using your token >> "curl "https://zenodo.org/api/deposit/depositions/1234567?access_token=%token%"" i.e. curl "https://zenodo.org/api/deposit/depositions/YOUR_DEPOSIT?access_token=%token%

This will produce on output > look for something along the lines of: "bucket": "https://zenodo.org/api/files/568377dd-daf8-4235-85e1-a56011ad454b" - we call this YOUR_BUCKET_LINK

Step 7: Copy that link and type: curl --upload-file "/path/to/your/file.dat" "https://zenodo.org/api/files/14b1818f-7449-4e24-b32b-23f0cd449104/file.dat?access_token=%token%" curl --upload-file "FILEPATH.FILETYPE" "YOUR_BUCKET_LINK/FILEPATH.FILETYPE?access_token=%token%"

Step 8: Your data should now be uploading. Once this is finished, you can upload more data or go back to the Zenodo Browser, check Metadata, and publish the data.

OVERVIEW: set token=YOUR_TOKEN_HERE curl "https://zenodo.org/api/deposit/depositions/YOUR_DEPOSIT?access_token=%token%" curl --upload-file "FILEPATH.FILETYPE" "YOUR_BUCKET_LINK/FILEPATH.FILETYPE?access_token=%token%"

Thank you for this great writeup! One small addition, to show progress meter with large uploads, modify the upload command with -o upload.txt, so:

curl -o upload.txt --upload-file "FILEPATH.FILETYPE" "YOUR_BUCKET_LINK/FILEPATH.FILETYPE?access_token=%token%"

This is based on man for the PROGRESS METER,

If you want a progress meter for HTTP POST or PUT requests, you need to redirect the response output to a file, using shell redirect (>), -o, --output or similar.

To show a progress bar instead of the progress meter, also use the --progress-bar option.

To upload multiple files (e.g. bunch of zip files in a folder), do: for %i in (*.zip) do curl ... and use %i instead of the filename in the curl command.

@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