Skip to content

Instantly share code, notes, and snippets.

@fawcett
Last active December 30, 2015 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fawcett/7772061 to your computer and use it in GitHub Desktop.
Save fawcett/7772061 to your computer and use it in GitHub Desktop.
A quick example on how to purge a group from a CKAN instance via the CKAN API. You will need to edit the code to set the values for your CKAN URI, API key, and the name of the group that you wish to purge. Note that this example requires the ckanap Python module: https://github.com/open-data/ckanapi
import ckanapi
ckanUrl = 'http://uri.to.your.ckan.instance'
apiKey='apiKeyForCkanSysadmin'
groupName='nameOfGroupToBePurged'
def purgeCkanGroup(ckanUrl,apiKey,groupId):
"""
This function purges an organization from a CKAN instance via the CKAN API.
Args: ckanUrl - string The URL for the CKAN instance that will receive the request.
apiKey - string The authorization key for a CKAN user with rights to delete or purge orgs
groupId - string The name or guid associated with the group to be purged
Requires: CKAN version >=2.2
ckanapi Python module: https://github.com/open-data/ckanapi
"""
ckan = ckanapi.RemoteCKAN(ckanUrl, apikey=apiKey)
ckan.action.group_purge(id=groupId)
purgeCkanGroup(ckanUrl,apiKey,groupName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment