DataPress
Search…
Updating a Dataset
You'll need to supply an API key in the Authorization header read a private dataset or to make any edits.
A dataset is a JSON document. It contains object keys, such as resources, and string keys such as the title and description. The fields "id" and "readonly" are immutable.
get
https://data.website
/api/dataset/:slug
Read a dataset
patch
https://data.website
/api/dataset/:slug
Update a dataset

Patching a dataset title using Python requests

1
import requests
2
import json
3
import os
4
5
site = 'https://data.london.gov.uk'
6
dataset='my-dataset-slug'
7
8
patch = [{
9
'op': 'add',
10
'path': '/title',
11
'value': 'Dataset has a new title!',
12
}]
13
14
# Python 2.4.2 onward has the keyword `json=patch`
15
requests.patch('%s/api/dataset/%s' % (site, dataset),
16
headers={
17
'Authorization': os.environ['API_KEY'],
18
'Content-type': 'application/json',
19
},
20
data=json.dumps(patch))
Copied!
post
https://data.website
/api/dataset
Create a new dataset

Creating a dataset using Python requests

1
import requests
2
import json
3
import os
4
5
site = 'https://data.london.gov.uk'
6
7
# Look up team IDs on /api/orgs
8
team_gla = '5b858cb2-5c92-4b2b-8c1d-141cfc330d9c'
9
10
my_new_dataset = {
11
# Required to create a dataset:
12
'title': 'Created via the API',
13
'slug': 'api-test-1',
14
'parent': team_gla,
15
16
# Optional:
17
'sharing': 'private',
18
'description': '...',
19
}
20
21
# Python 2.4.2 onward has the keyword `json=my_new_dataset`
22
requests.post('%s/api/dataset' % site,
23
headers={
24
'Authorization': os.environ['API_KEY'],
25
'Content-type': 'application/json',
26
},
27
data=json.dumps(my_new_dataset))
Copied!

File Uploads

The file upload API uses multipart/form-data to upload files. All other API endpoints deal purely in application/json.
post
https://data.website
/api/dataset/:slug/resources
Append a file to a dataset

Uploading a file from the command line, using CURL

1
SITE=https://data.london.gov.uk
2
DATASET=your-slug-here
3
API_KEY=..
4
SRC_FILE="/path/to/src/file"
5
6
URL="${SITE}/api/dataset/${DATASET}/resources"
7
curl "${URL}" -H "Authorization: ${API_KEY}" -F "[email protected]${SRC_FILE}"
Copied!

Uploading a file using Python Requests

1
import requests
2
import os
3
4
site='https://data.london.gov.uk'
5
dataset='your-slug-here'
6
api_key=os.environ['API_KEY']
7
src_file='/path/to/src/file'
8
title='Title of resource'
9
10
url='%s/api/dataset/%s/resources' % (site, dataset)
11
requests.post(url,
12
files={'file': open(src_file, 'rb')},
13
headers={'Authorization': api_key},
14
data={'title': title})
Copied!
post
https://data.website
/api/dataset/:slug/resources/:id
Replace a file in a dataset
Last modified 1yr ago