Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions source/includes/metadata-dumps/_root.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions source/includes/oai-pmh/_root.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).

Expand Down
66 changes: 48 additions & 18 deletions source/includes/overview/_quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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()
Expand All @@ -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);
Expand All @@ -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)):

<div class="align-columns"></div>

Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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={},
Expand All @@ -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);
});
Expand Down Expand Up @@ -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": {
Expand All @@ -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
{ ... }
```
Expand All @@ -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.
'''
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand All @@ -367,7 +394,10 @@ r.status_code
<div class="align-columns"></div>
```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
Expand Down
26 changes: 25 additions & 1 deletion source/includes/rate-limit/_root.md
Original file line number Diff line number Diff line change
@@ -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 |
Expand All @@ -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
```

<aside class="notice">
To prevent automated abuse, high-volume requests using generic User-Agents (such as the default <code>curl</code> or <code>python-requests</code>) may
be rate-limited or blocked. We strongly encourage adding a custom User-Agent string to your scripts.
</aside>
4 changes: 3 additions & 1 deletion source/includes/resources/deposit-actions/_discard.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down
8 changes: 6 additions & 2 deletions source/includes/resources/deposit-actions/_edit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions source/includes/resources/deposit-actions/_newversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down
4 changes: 3 additions & 1 deletion source/includes/resources/deposit-actions/_publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down
Loading
Loading