ckanaction

package_revise

Revise a dataset (package) selectively with match, filter, and update parameters.

You must be authorized to edit the dataset and the groups that it belongs to.

match and update parameters may also be passed as "flattened keys", using either the item numeric index or its unique id (with a minimum of 5 characters), e.g. update__resource__1f9ab__description="guidebook" would set the description of the resource with id starting with "1f9ab" to "guidebook", and update__resource__-1__description="guidebook" would do the same on the last resource in the dataset.

The extend suffix can also be used on the update parameter to add a new item to a list, e.g. update__resources__extend=[{"name": "new resource", "url": "https://example.com"}] will add a new resource to the dataset with the provided name and url.

Usage examples:

  • Change description in dataset, checking for old description:
match={"notes": "old notes", "name": "xyz"}
update={"notes": "new notes"}
  • Identical to above, but using flattened keys:
match__name="xyz"
match__notes="old notes"
update__notes="new notes"
  • Replace all fields at dataset level only, keep resources (note: dataset id and type fields canโ€™t be deleted)
match={"id": "1234abc-1420-cbad-1922"}
filter=["+resources", "-*"]
update={"name": "fresh-start", "title": "Fresh Start"}
  • Add a new resource (__extend on flattened key):
match={"id": "abc0123-1420-cbad-1922"}
update__resources__extend=[{"name": "new resource", "url": "http://example.com"}]
  • Update a resource by its index:
match={"name": "my-data"}
update__resources__0={"name": "new name, first resource"}
  • Update a resource by its id (provide at least 5 characters):
match={"name": "their-data"}
update__resources__19cfad={"description": "right one for sure"}
  • Replace all fields of a resource:
match={"id": "34a12bc-1420-cbad-1922"}
filter=["+resources__1492a__id", "-resources__1492a__*"]
update__resources__1492a={"name": "edits here", "url": "http://example.com"}
PUT
package_revise

Authorization

apiTokenHeader
Authorization<token>

CKAN API token

In: header

Request Body

application/json

match?

a dict containing "id" or "name" values of the dataset to update, all values provided must match the current dataset values or a ValidationError will be raised. e.g. {"name": "my-data", "resources": {["name": "big.csv"]}} would abort if the my-data dataset's first resource name is not "big.csv".

filter?array<string>

a list of string patterns of fields to remove from the current dataset. e.g. "-resources__1" would remove the second resource, "+title, +resources, -*" would remove all fields at the dataset level except title and all resources (default: [])

update?

a dict with values to update/create after filtering e.g. {"resources": [{"description": "file here"}]} would update the description for the first resource

include?array<string>

a list of string pattern of fields to include in response e.g. "-*" to return nothing (default: [] all fields returned)

curl -X PUT "http://localhost:5000/api/3/action/package_revise" \  -H "Content-Type: application/json" \  -d '{}'