diff --git a/source/includes/metadata-dumps/_root.md b/source/includes/metadata-dumps/_root.md index 667a5d9..15caf1d 100644 --- a/source/includes/metadata-dumps/_root.md +++ b/source/includes/metadata-dumps/_root.md @@ -12,11 +12,13 @@ List all available metadata dumps with their version history. ```python import requests -resp = requests.get('https://zenodo.org/api/exporter') +headers = {'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} +resp = requests.get('https://zenodo.org/api/exporter', headers=headers) ``` ```shell -curl https://zenodo.org/api/exporter +curl -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/exporter ``` ```json @@ -80,19 +82,23 @@ Download the latest version of a specific metadata dump. ```python import requests +headers = {'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} + # Download latest version -resp = requests.get('https://zenodo.org/api/exporter/records-xml.tar.gz') +resp = requests.get('https://zenodo.org/api/exporter/records-xml.tar.gz', headers=headers) # Download specific version -resp = requests.get('https://zenodo.org/api/exporter/records-xml.tar.gz/a1b2c3d4-e5f6-7890-abcd-ef1234567890') +resp = requests.get('https://zenodo.org/api/exporter/records-xml.tar.gz/a1b2c3d4-e5f6-7890-abcd-ef1234567890', headers=headers) ``` ```shell # Download latest version -curl -O https://zenodo.org/api/exporter/records-xml.tar.gz +curl -O -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/exporter/records-xml.tar.gz # Download specific version -curl -O https://zenodo.org/api/exporter/records-xml.tar.gz/a1b2c3d4-e5f6-7890-abcd-ef1234567890 +curl -O -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/exporter/records-xml.tar.gz/a1b2c3d4-e5f6-7890-abcd-ef1234567890 ``` #### HTTP Request @@ -142,7 +148,8 @@ import itertools import xml.etree.ElementTree as ET url = "https://zenodo.org/api/exporter/records-xml.tar.gz" -resp = requests.get(url, stream=True) +headers = {'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} +resp = requests.get(url, headers=headers, stream=True) resp.raw.decode_content = True namespaces = { @@ -170,7 +177,8 @@ with tarfile.open(fileobj=resp.raw, mode="r|gz") as tar: ```shell # List files without extracting -curl -s https://zenodo.org/api/exporter/records-xml.tar.gz | tar -tzf - | head -10 +curl -s -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/exporter/records-xml.tar.gz | tar -tzf - | head -10 # Outputs: # 12345.xml diff --git a/source/includes/oai-pmh/_root.md b/source/includes/oai-pmh/_root.md index cb12235..8e72c71 100644 --- a/source/includes/oai-pmh/_root.md +++ b/source/includes/oai-pmh/_root.md @@ -27,7 +27,8 @@ pip install Sickle ```python '''Import Sickle and initialize the client by passing the base URL''' from sickle import Sickle -sickle = Sickle('https://zenodo.org/oai2d') +sickle = Sickle('https://zenodo.org/oai2d', + headers={'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'}) ``` ## Get information about the OAI-PMH API @@ -115,7 +116,7 @@ Dublin Core — only minimal metadata is included in this format. The format is **`dcat`** -DCAT — export format based on the [DCAT Application Profile for data portals in Europe (DCAT-AP)](https://joinup.ec.europa.eu/collection/semic-support-centre/solution/dcat-application-profile-data-portals-europe). +DCAT — export format based on the [DCAT Application Profile for data portals in Europe (DCAT-AP)](https://joinup.ec.europa.eu/collection/semic-support-centre/solution/dcat-application-profile-data-portals-europe). The format is produced from the DataCite export format using the [DataCite-to-DCAT-AP XSLT](https://github.com/ec-jrc/datacite-to-dcat-ap). This is the only OAI-PMH metadata format that currently exposes direct links to each record's files content, via the [`dcat:Distribution` elements](https://www.w3.org/TR/vocab-dcat-3/#Class:Distribution). diff --git a/source/includes/overview/_quickstart.md b/source/includes/overview/_quickstart.md index 847d543..0dfa9b2 100644 --- a/source/includes/overview/_quickstart.md +++ b/source/includes/overview/_quickstart.md @@ -10,7 +10,7 @@ Zenodo, and will be using either: # Install 'requests' module for python pip install requests -# Install 'axios' module for nodejs +# Install 'axios' module for nodejs npm install axios ``` @@ -51,7 +51,9 @@ const axios = require('axios'); ```python import requests -r = requests.get("https://zenodo.org/api/deposit/depositions") +USER_AGENT = 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)' +r = requests.get("https://zenodo.org/api/deposit/depositions", + headers={'User-Agent': USER_AGENT}) r.status_code # 401 r.json() @@ -60,7 +62,14 @@ r.json() ```javascript const axios = require('axios'); -axios.get("https://zenodo.org/api/deposit/depositions").then(response => { +const USER_AGENT = 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'; + +const requestConfig = { + headers: { + 'User-Agent': USER_AGENT + } +} +axios.get("https://zenodo.org/api/deposit/depositions", requestConfig).then(response => { console.log(response); }).catch(error => { console.log(error.response.data); @@ -77,7 +86,9 @@ axios.get("https://zenodo.org/api/deposit/depositions").then(response => { } ``` -- We will try to access the API without an authentication token: +- We will try to access the API without an authentication token. Note we're +already sending a `User-Agent` header identifying our client, which we +recommend doing on every request (see [Rate Limiting and User-Agent](#rate-limiting-and-user-agent)):
@@ -88,7 +99,10 @@ axios.get("https://zenodo.org/api/deposit/depositions").then(response => { ```python ACCESS_TOKEN = 'ChangeMe' -headers = {'Authorization': f'Bearer {ACCESS_TOKEN}'} +headers = { + 'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': USER_AGENT +} r = requests.get('https://zenodo.org/api/deposit/depositions', headers=headers) r.status_code @@ -102,13 +116,14 @@ const ACCESS_TOKEN = 'ChangeMe' const requestConfig = { headers: { - 'Authorization': `Bearer ${ACCESS_TOKEN}` + 'Authorization': `Bearer ${ACCESS_TOKEN}`, + 'User-Agent': USER_AGENT } } axios.get("https://zenodo.org/api/deposit/depositions", requestConfig).then(response => { console.log(response.status); // > 200 - console.log(response.data); + console.log(response.data); // > [] }).catch(error => { console.log(error.response.data); @@ -127,7 +142,8 @@ access token): ```python headers = { "Content-Type": "application/json", - "Authorization": f"Bearer {ACCESS_TOKEN}" + "Authorization": f"Bearer {ACCESS_TOKEN}", + "User-Agent": USER_AGENT } r = requests.post('https://sandbox.zenodo.org/api/deposit/depositions', json={}, @@ -141,14 +157,15 @@ r.json() const requestConfig = { headers: { "Content-Type": "application/json", - "Authorization": `Bearer ${ACCESS_TOKEN}` + "Authorization": `Bearer ${ACCESS_TOKEN}`, + "User-Agent": USER_AGENT } } axios.post("https://zenodo.org/api/deposit/depositions", {}, requestConfig).then(response => { console.log(response.status); // 201 - console.log(response.data); + console.log(response.data); }).catch(error => { console.log(error.response.data); }); @@ -201,6 +218,7 @@ bucket_url = r.json()["links"]["bucket"] ```shell curl -H "Authorization: Bearer $ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ https://zenodo.org/api/deposit/depositions/222761 { ... "links": { @@ -213,13 +231,14 @@ curl -H "Authorization: Bearer $ACCESS_TOKEN" \ - To use the **new files API** we will do a PUT request to the `bucket` link. The bucket is a folder-like object storing the files of our record. Our bucket URL will look like this: `https://zenodo.org/api/files/568377dd-daf8-4235-85e1-a56011ad454b` and can be found under the `links` key in our records metadata. ```shell -''' +''' This will stream the file located in '/path/to/your/file.dat' and store it in our bucket. The uploaded file will be named according to the last argument in the upload URL, -'file.dat' in our case. +'file.dat' in our case. ''' $ curl --upload-file /path/to/your/file.dat \ -H "Authorization: Bearer $ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ https://zenodo.org/api/files/568377dd-daf8-4235-85e1-a56011ad454b/file.dat { ... } ``` @@ -228,9 +247,12 @@ $ curl --upload-file /path/to/your/file.dat \ ''' New API ''' filename = "my-file.zip" path = "/path/to/%s" % filename -headers = {'Authorization': f'Bearer {ACCESS_TOKEN}'} +headers = { + 'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': USER_AGENT +} -''' +''' The target URL is a combination of the bucket link with the desired filename seperated by a slash. ''' @@ -264,7 +286,8 @@ let url = `${bucketURL}/${fileName}`; let headers = { 'Content-type': 'application/zip', - 'Authorization': `Bearer ${token}` + 'Authorization': `Bearer ${token}`, + 'User-Agent': USER_AGENT } const requestConfig = { @@ -311,7 +334,10 @@ Get the deposition id from the previous response deposition_id = r.json()['id'] data = {'name': 'myfirstfile.csv'} files = {'file': open('/path/to/myfirstfile.csv', 'rb')} -headers = {'Authorization': f'Bearer {ACCESS_TOKEN}'} +headers = { + 'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': USER_AGENT +} r = requests.post('https://zenodo.org/api/deposit/depositions/%s/files' % deposition_id, headers=headers, data=data, files=files) @@ -349,7 +375,8 @@ data = { } headers = { 'Content-Type': 'application/json', - 'Authorization': f'Bearer {ACCESS_TOKEN}' + 'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': USER_AGENT } r = requests.put('https://zenodo.org/api/deposit/depositions/%s' % deposition_id, data=json.dumps(data), @@ -367,7 +394,10 @@ r.status_code
```python -headers = {'Authorization': f'Bearer {ACCESS_TOKEN}'} +headers = { + 'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': USER_AGENT +} r = requests.post('https://zenodo.org/api/deposit/depositions/%s/actions/publish' % deposition_id, headers=headers) r.status_code diff --git a/source/includes/rate-limit/_root.md b/source/includes/rate-limit/_root.md index 68464a2..474a1e2 100644 --- a/source/includes/rate-limit/_root.md +++ b/source/includes/rate-limit/_root.md @@ -1,6 +1,6 @@ # Rate Limiting -For our content and services to be available to everyone we have to make sure that our resources are being distributed fairly. +For our content and services to be available to everyone we have to make sure that our resources are being distributed fairly. To achieve this, we have rate-limiting measures in place which limit the number of requests users can perform in a time window. Depending on the complexity and load of each request, different endpoints have different limits configured. | Pages | Limitations | @@ -18,3 +18,27 @@ When you are making requests to any of our endpoints, you can inspect the follow |`X-RateLimit-Limit`| Current rate-limit policy, i.e. maximum number of requests per minute | |`X-RateLimit-Remaining`| Number of requests remaining in the current rate limit | |`X-RateLimit-Reset`| Reset time of the current rate limit | + +## User-Agent + +When performing requests via APIs, please use a clear and identifiable `User-Agent`. We recommend a format such as: + +`MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)` + +which allows us to identify the source of traffic, apply appropriate measures, or contact you in case of need. + +```python +import requests +headers = {'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} +r = requests.get('https://zenodo.org/api/records', headers=headers) +``` + +```shell +curl -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/records +``` + + diff --git a/source/includes/resources/deposit-actions/_discard.md b/source/includes/resources/deposit-actions/_discard.md index 6125e9a..ed74668 100644 --- a/source/includes/resources/deposit-actions/_discard.md +++ b/source/includes/resources/deposit-actions/_discard.md @@ -4,12 +4,14 @@ Discard changes in the current editing session. ```shell curl -i -X POST -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ https://zenodo.org/api/deposit/depositions/1234/actions/discard ``` ```python import requests -headers = {'Authorization': f'Bearer {ACCESS_TOKEN}'} +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} r = requests.post('https://zenodo.org/api/deposit/depositions/1234/actions/discard', headers=headers) ``` diff --git a/source/includes/resources/deposit-actions/_edit.md b/source/includes/resources/deposit-actions/_edit.md index e8d9971..6b82f7d 100644 --- a/source/includes/resources/deposit-actions/_edit.md +++ b/source/includes/resources/deposit-actions/_edit.md @@ -3,13 +3,17 @@ Unlock already submitted deposition for editing. ```shell -curl -i -H "Authorization: Bearer ACCESS_TOKEN" -X POST https://zenodo.org/api/deposit/depositions/1234/actions/edit +curl -i -X POST -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/deposit/depositions/1234/actions/edit ``` ```python import requests +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} r = requests.post('https://zenodo.org/api/deposit/depositions/1234/actions/edit', - headers={'Authorization': f'Bearer {ACCESS_TOKEN}'}) + headers=headers) ``` #### HTTP Request diff --git a/source/includes/resources/deposit-actions/_newversion.md b/source/includes/resources/deposit-actions/_newversion.md index d90901c..0b4f583 100644 --- a/source/includes/resources/deposit-actions/_newversion.md +++ b/source/includes/resources/deposit-actions/_newversion.md @@ -7,19 +7,21 @@ The new version deposit will have a state similar to a new, unpublished deposit, Only one unpublished new version deposit can be available at any moment, i.e.: calling new version action multiple times will have no effect, as long as the resulting new version deposit from the first call is not published or deleted. -NOTES: +NOTES: - The response body of this action is NOT the new version deposit, but the original resource. The new version deposition can be accessed through the ``"latest_draft"`` under ``"links"`` in the response body. - The ``id`` used to create this new version has to be the ``id`` of the latest version. It is not possible to use the global id that references all the versions. ```shell curl -i -X POST -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ https://zenodo.org/api/deposit/depositions/1234/actions/newversion ``` ```python import requests -headers = {'Authorization': f'Bearer {ACCESS_TOKEN}'} +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} r = requests.post('https://zenodo.org/api/deposit/depositions/1234/actions/newversion', headers=headers) ``` diff --git a/source/includes/resources/deposit-actions/_publish.md b/source/includes/resources/deposit-actions/_publish.md index ef5fa09..e38742d 100644 --- a/source/includes/resources/deposit-actions/_publish.md +++ b/source/includes/resources/deposit-actions/_publish.md @@ -5,12 +5,14 @@ delete it. ```shell curl -i -X POST -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ https://zenodo.org/api/deposit/depositions/1234/actions/publish ``` ```python import requests -headers = {'Authorization': f'Bearer {ACCESS_TOKEN}'} +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} r = requests.post('https://zenodo.org/api/deposit/depositions/1234/actions/publish', headers=headers) ``` diff --git a/source/includes/resources/deposit-files/_create.md b/source/includes/resources/deposit-files/_create.md index 973dd88..97a187a 100644 --- a/source/includes/resources/deposit-files/_create.md +++ b/source/includes/resources/deposit-files/_create.md @@ -3,7 +3,9 @@ Upload a new file. ```shell -curl -i -H "Authorization: Bearer ACCESS_TOKEN" https://zenodo.org/api/deposit/depositions/1234/files +curl -i -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/deposit/depositions/1234/files -F name=myfirstfile.csv -F file=@path/to/local_file.csv @@ -14,7 +16,8 @@ import json import requests url = 'https://zenodo.org/api/deposit/depositions/1234/files' -headers = {'Authorization': f'Bearer {ACCESS_TOKEN}'} +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} data = {'name': 'myfirstfile.csv'} files = {'file': open('path/to/local_file.csv', 'rb')} r = requests.post(url, data=data, files=files, headers=headers) diff --git a/source/includes/resources/deposit-files/_delete.md b/source/includes/resources/deposit-files/_delete.md index ed3df7a..f53fa54 100644 --- a/source/includes/resources/deposit-files/_delete.md +++ b/source/includes/resources/deposit-files/_delete.md @@ -4,13 +4,17 @@ Delete an existing deposition file resource. Note, only deposition files for unpublished depositions may be deleted. ```shell -curl -i -H "Authorization: Bearer ACCESS_TOKEN" -X DELETE https://zenodo.org/api/deposit/depositions/1234/files/21fedcba-9876-5432-1fed-cba987654321 +curl -i -X DELETE -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/deposit/depositions/1234/files/21fedcba-9876-5432-1fed-cba987654321 ``` ```python import requests +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} r = requests.delete('https://zenodo.org/api/deposit/depositions/1234/files/21fedcba-9876-5432-1fed-cba987654321', - headers={'Authorization': f'Bearer {ACCESS_TOKEN}'}) + headers=headers) ``` #### HTTP Request diff --git a/source/includes/resources/deposit-files/_list.md b/source/includes/resources/deposit-files/_list.md index 90e2460..f6de5e9 100644 --- a/source/includes/resources/deposit-files/_list.md +++ b/source/includes/resources/deposit-files/_list.md @@ -3,13 +3,17 @@ List all deposition files for a given deposition. ```shell -curl -i -H "Authorization: Bearer ACCESS_TOKEN" https://zenodo.org/api/deposit/depositions/1234/files +curl -i -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/deposit/depositions/1234/files ``` ```python import requests +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} r = requests.get('https://zenodo.org/api/deposit/depositions/1234/files', - headers={'Authorization': f'Bearer {ACCESS_TOKEN}'}) + headers=headers) ``` #### HTTP Request diff --git a/source/includes/resources/deposit-files/_retrieve.md b/source/includes/resources/deposit-files/_retrieve.md index ce95f87..c29ff70 100644 --- a/source/includes/resources/deposit-files/_retrieve.md +++ b/source/includes/resources/deposit-files/_retrieve.md @@ -3,14 +3,18 @@ Retrieve a single deposition file. ```shell -curl -i -H "Authorization: Bearer ACCESS_TOKEN" https://zenodo.org/api/deposit/depositions/1234/files/12345678-9abc-def1-2345-6789abcdef12 +curl -i -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/deposit/depositions/1234/files/12345678-9abc-def1-2345-6789abcdef12 ``` ```python import requests +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} r = requests.get('https://zenodo.org/api/deposit/depositions/1234/files/12345678-9abc-def1-2345-6789abcdef12', - headers={'Authorization': f'Bearer {ACCESS_TOKEN}'}) + headers=headers) ``` #### HTTP Request diff --git a/source/includes/resources/deposit-files/_sort.md b/source/includes/resources/deposit-files/_sort.md index 11938cf..b0e456e 100644 --- a/source/includes/resources/deposit-files/_sort.md +++ b/source/includes/resources/deposit-files/_sort.md @@ -6,6 +6,7 @@ preview. ```shell curl -i -H "Authorization: Bearer ACCESS_TOKEN" https://zenodo.org/api/deposit/depositions/1234/files -X PUT -H "Content-Type: application/json" + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" --data '[{"id":"21fedcba-9876-5432-1fed-cba987654321"}, {"id":"12345678-9abc-def1-2345-6789abcdef12"}]' ``` @@ -14,7 +15,8 @@ import json import requests url = 'https://zenodo.org/api/deposit/depositions/1234/files' -headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ACCESS_TOKEN}"} +headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ACCESS_TOKEN}", + "User-Agent": "MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)"} data = [{'id': '21fedcba-9876-5432-1fed-cba987654321'}, {'id': '12345678-9abc-def1-2345-6789abcdef12'}] r = requests.put(url, data=json.dumps(data), headers=headers) diff --git a/source/includes/resources/deposit-files/_update.md b/source/includes/resources/deposit-files/_update.md index a69918f..9b68234 100644 --- a/source/includes/resources/deposit-files/_update.md +++ b/source/includes/resources/deposit-files/_update.md @@ -7,6 +7,7 @@ upload a new file. ```shell curl -i -H "Authorization: Bearer ACCESS_TOKEN" https://zenodo.org/api/deposit/depositions/1234/files/21fedcba-9876-5432-1fed-cba987654321 -X PUT -H "Content-Type: application/json" + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" --data '{"filename": "someothername.csv"}' ``` @@ -15,7 +16,8 @@ import json import requests url = 'https://zenodo.org/api/deposit/depositions/1234/files/21fedcba-9876-5432-1fed-cba987654321' -headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ACCESS_TOKEN}"} +headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ACCESS_TOKEN}", + "User-Agent": "MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)"} data = {"name": "someothername.csv"} r = requests.put(url, data=json.dumps(data), headers=headers) ``` diff --git a/source/includes/resources/deposit/_create.md b/source/includes/resources/deposit/_create.md index c29ef3a..f137d43 100644 --- a/source/includes/resources/deposit/_create.md +++ b/source/includes/resources/deposit/_create.md @@ -3,12 +3,14 @@ Create a new deposition resource. ```shell -curl -i -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" -X POST +curl -i -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" -X POST --data '{}' /api/deposit/depositions/ # or -curl -i -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" -X POST +curl -i -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" -X POST --data '{"metadata": {"title": "My first upload", "upload_type": "poster", "description": "This is my first upload", "creators": [{"name": "Doe, John", "affiliation": "Zenodo"}]}}' /api/deposit/depositions/ ``` @@ -17,7 +19,8 @@ import json import requests url = "/api/deposit/depositions/" -headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ACCESS_TOKEN}"} +headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ACCESS_TOKEN}", + "User-Agent": "MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)"} r = requests.post(url, data="{}", headers=headers) ``` diff --git a/source/includes/resources/deposit/_delete.md b/source/includes/resources/deposit/_delete.md index 6c9f294..fd4b22e 100644 --- a/source/includes/resources/deposit/_delete.md +++ b/source/includes/resources/deposit/_delete.md @@ -5,13 +5,17 @@ Delete an existing deposition resource. Note, only unpublished depositions may be deleted. ```shell -curl -i -H "Authorization: Bearer ACCESS_TOKEN" https://zenodo.org/api/deposit/depositions/1234 -X DELETE +curl -i -X DELETE -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/deposit/depositions/1234 ``` ```python import requests +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} r = requests.delete('https://zenodo.org/api/deposit/depositions/1234', - headers={'Authorization': f'Bearer {ACCESS_TOKEN}'}) + headers=headers) ``` #### HTTP Request diff --git a/source/includes/resources/deposit/_list.md b/source/includes/resources/deposit/_list.md index 61adfb3..221fc66 100644 --- a/source/includes/resources/deposit/_list.md +++ b/source/includes/resources/deposit/_list.md @@ -4,14 +4,18 @@ List all depositions for the currently authenticated user. ```python import requests +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} response = requests.get('/api/deposit/depositions', params={'q': 'my title'}, - headers={'Authorization': f'Bearer {ACCESS_TOKEN}'}) + headers=headers) print(response.json()) ``` ```shell -curl -i -H "Authorization: Bearer ACCESS_TOKEN" /api/deposit/depositions/ +curl -i -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + /api/deposit/depositions/ ``` #### HTTP Request diff --git a/source/includes/resources/deposit/_retrieve.md b/source/includes/resources/deposit/_retrieve.md index 50218d2..b43c109 100644 --- a/source/includes/resources/deposit/_retrieve.md +++ b/source/includes/resources/deposit/_retrieve.md @@ -3,12 +3,16 @@ Retrieve a single deposition resource. ```shell -curl -i -H "Authorization: Bearer ACCESS_TOKEN" /api/deposit/depositions/1234 +curl -i -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + /api/deposit/depositions/1234 ``` ```python import requests -r = requests.get("/api/deposit/depositions/1234", headers={'Authorization': f'Bearer {ACCESS_TOKEN}'}) +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} +r = requests.get("/api/deposit/depositions/1234", headers=headers) ``` #### HTTP Request diff --git a/source/includes/resources/deposit/_update.md b/source/includes/resources/deposit/_update.md index 7e3734d..92b1f32 100644 --- a/source/includes/resources/deposit/_update.md +++ b/source/includes/resources/deposit/_update.md @@ -4,7 +4,8 @@ Update an existing deposition resource. ```shell -curl -i -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" -X PUT +curl -i -H "Content-Type: application/json" -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" -X PUT --data '{"metadata": {"title": "My first upload", "upload_type": "poster", "description": "This is my first upload", "creators": [{"name": "Doe, John", "affiliation": "Zenodo"}]}}' https://zenodo.org/api/deposit/depositions/1234 ``` @@ -23,7 +24,8 @@ data = { } } url = "https://zenodo.org/api/deposit/depositions/1234" -headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ACCESS_TOKEN}"} +headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ACCESS_TOKEN}", + "User-Agent": "MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)"} r = requests.put(url, data=json.dumps(data), headers=headers) ``` diff --git a/source/includes/resources/licenses/_list.md b/source/includes/resources/licenses/_list.md index 86fe97e..403739a 100644 --- a/source/includes/resources/licenses/_list.md +++ b/source/includes/resources/licenses/_list.md @@ -4,12 +4,14 @@ Search through licenses. ```python import requests -response = requests.get('/api/licenses/') +headers = {'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} +response = requests.get('/api/licenses/', headers=headers) print(response.json()) ``` ```shell -curl /api/licenses/ +curl -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + /api/licenses/ ``` #### HTTP Request diff --git a/source/includes/resources/licenses/_retrieve.md b/source/includes/resources/licenses/_retrieve.md index ad6e0d1..cdd936c 100644 --- a/source/includes/resources/licenses/_retrieve.md +++ b/source/includes/resources/licenses/_retrieve.md @@ -4,11 +4,13 @@ Retrieve a single license resource. ```python import requests -r = requests.get("/api/licenses/cc-by-nc-4.0") +headers = {'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} +r = requests.get("/api/licenses/cc-by-nc-4.0", headers=headers) ``` ```shell -curl /api/licenses/cc-by-nc-4.0 +curl -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + /api/licenses/cc-by-nc-4.0 ``` #### HTTP Request diff --git a/source/includes/resources/records/_list.md b/source/includes/resources/records/_list.md index 51ccb64..9ed7706 100644 --- a/source/includes/resources/records/_list.md +++ b/source/includes/resources/records/_list.md @@ -4,14 +4,18 @@ List all open access records. ```python import requests +headers = {'Authorization': f'Bearer {ACCESS_TOKEN}', + 'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} response = requests.get('https://zenodo.org/api/records', params={'q': 'my title'}, - headers={'Authorization': f'Bearer {ACCESS_TOKEN}'}) + headers=headers) print(response.json()) ``` ```shell -curl -i -H "Authorization: Bearer ACCESS_TOKEN" /api/records/ +curl -i -H "Authorization: Bearer ACCESS_TOKEN" \ + -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + /api/records/ ``` #### HTTP Request diff --git a/source/includes/resources/records/_retrieve.md b/source/includes/resources/records/_retrieve.md index 9be71af..c610349 100644 --- a/source/includes/resources/records/_retrieve.md +++ b/source/includes/resources/records/_retrieve.md @@ -3,12 +3,14 @@ Retrieve a single record. ```shell -curl -i https://zenodo.org/api/records/1234 +curl -i -H "User-Agent: MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)" \ + https://zenodo.org/api/records/1234 ``` ```python import requests -r = requests.get("https://zenodo.org/api/records/1234) +headers = {'User-Agent': 'MyToolName/1.0 (+https://changeme.com; ChangeMe@changeme.com)'} +r = requests.get("https://zenodo.org/api/records/1234", headers=headers) ``` #### HTTP Request