-
Notifications
You must be signed in to change notification settings - Fork 1
Home
The opendata library used in this project is CKAN API version 3. The data are part of Opendata Trentino and we want to save and update them in the new portal.
We want to add dataset to Trentino organization with resources and a specific group that belongs to a member of this organization. The group is:
| Parameters | Data |
|---|---|
| name | ambiente |
| id | 7b86ac83-cfa6-44f1-9be8-8075754934e5 |
| title | Ambiente |
| description | qualita' dell'aria, risparmio energetico, raccolta differenziata, fotovoltaico, ecc. |
| type | group |
| state | active |
| approval_status | approved |
| extras | [] |
| groups | [] |
| users | [] |
| display_name | Ambiente |
| package_count | 0 |
| created | 2014-09-11T10:53:55.382538 |
| is_organization | False |
| revision_id | cf74f83c-7fe3-4162-b8ba-a265b0b4686c |
| num_followers | 0 |
| tags | [] |
The request for creation of a dataset is:
POST domain/api/3/action/package_create
Authorization code
dataset
The dataset is a json that has the following fields:
| Parameters | Data |
|---|---|
| name | abitazioni |
| title | Abitazioni |
| author | Servizio Statistica |
| author_email | serv.statistica@provincia.tn.it |
| maintainer | Servizio Statistica |
| maintainer_email | serv.statistica@provincia.tn.it |
| license_id | cc-by |
| notes | Settore: Edilizia e opere pubbliche. Algoritmo: Numero delle abitazioni rilevate ai censimenti. Tipo di indicatore: rapporto. Livello geografico minimo: Comune. |
| url | http://www.statweb.provincia.tn.it/INDICATORISTRUTTURALISubPro/ |
| version | None |
| state | active |
| type | dataset |
| resources | id: f58e4b9d-1cfb-4063-b9f1-4826583a9566, url: http://www.statweb.provincia.tn.it/indicatoristrutturalisubpro/exp.aspx?idind=133&info=d&fmt=json, revision_id: a047de70-6326-49b6-b1ef-31d3a99940d0, description: Abitazioni,format: JSON, name: abitazioni, mimetype: application/json, created: 2014-07-08T17:47:33.593092 |
| tags | [] |
| extras | {value: Numero delle abitazioni rilevate ai censimenti, key: Algoritmo}, {value: 1961, key: Anno di inizio}, {value: Servizio Statistica Provincia Autonoma di Trento, key: Fonte}, {value: Decennale, key: Frequenza di aggiornamento}, {value: Comune, key: Livello Geografico Minimo}, {value: Edilizia e opere pubbliche, key: Settore}, {value: Stock, key: Tipo di Fenomeno}, {value: R, key: Tipo di Indicatore}, {value: 16/04/2014, key: Ultimo aggiornamento}, {value: Unita', key: Unita' di misura}, {value: statistica_subpro:133, key: _harvest_source} |
| relationships_as_object | [] |
| relationships_as_subject | [] |
| groups | id: 7b86ac83-cfa6-44f1-9be8-8075754934e5, name: ambiente |
| owner_org | 1ca43c96-db71-4ffd-9f5b-d95c9263f652 |
The attributes are as follows:
| Attribute | Description |
|---|---|
| name (string) | The name of the new dataset |
| title (string) | The title of the dataset (optional) |
| author (string) | The name of the dataset's author (optional) |
| author_email (string) | The email address of the dataset's author (optional) |
| maintainer (string) | The name of the dataset's maintainer (optional) |
| maintainer_email (string) | The emai address of the dataset's mainainer (optional) |
| license_id (string) | The id of the dataset's license (optional) |
| notes (string) | A description of the dataset (optional) |
| url (string) | A URL for the dataset's source (optional) |
| version (string) | (optional) |
| state (string) | The current state of the dataset (active or deleted) |
| type (string) | The type of the dataset (optional) |
| resources (list of resources dictionaries) | The dataset's resources (optional) |
| tags (list of tags dictionaries) | The dataset's tags (optional) |
| extras (list of dataset extra dictionaries) | The dataset's extras (optional), extras are arbitrary (key:value) metadata items that can be added to datasets, each extra dictionary should have keys key (string), value (string) |
| relationships_as_object (list of relationship dictionaries) | The dataset's relationships dictionaries (optional) |
| relationships_as_subject (list of relationship dictionaries) | The dataset's relationships dictionaries (optional) |
| groups (list of dictionaries) | The groups to which the dataset belongs (optional), each group dictionary should have one or more of the following keys which identify an existing group: id (id of group, string) or name (name of the group, string) |
| owner_org (string) | The id of dataset's owning organization |
An example of create request in python with CKAN API version 3:
#Request
request = urllib2.Request(domain+'/api/3/action/package_create')
#Add authorization header
request.add_header('Authorization', authorizationCode)
#HTTP request
response = urllib2.urlopen(request, dataset)We want to update the same dataset as the create request section adding a new resource. The request is:
POST domain/api/3/action/package_update
Authorization code
dataset
The dataset is a json that has the following fields:
| Parameters | Data |
|---|---|
| name | abitazioni |
| title | Abitazioni |
| author | Servizio Statistica |
| author_email | serv.statistica@provincia.tn.it |
| maintainer | Servizio Statistica |
| maintainer_email | serv.statistica@provincia.tn.it |
| license_id | cc-by |
| notes | Settore: Edilizia e opere pubbliche. Algoritmo: Numero delle abitazioni rilevate ai censimenti. Tipo di indicatore: rapporto. Livello geografico minimo: Comune. |
| url | http://www.statweb.provincia.tn.it/INDICATORISTRUTTURALISubPro/ |
| version | None |
| state | active |
| type | dataset |
| resources | {id: f58e4b9d-1cfb-4063-b9f1-4826583a9566, url: http://www.statweb.provincia.tn.it/indicatoristrutturalisubpro/exp.aspx?idind=133&info=d&fmt=json, revision_id: a047de70-6326-49b6-b1ef-31d3a99940d0, description: Abitazioni,format: JSON, name: abitazioni, mimetype: application/json, created: 2014-07-08T17:47:33.593092}, {id: 5997a2c4-d008-46ae-bdd2-00a3c074b356, url: http://www.statweb.provincia.tn.it/indicatoristrutturalisubpro/exp.aspx?ntab=Sub_Numero_Abitazioni&info=d&fmt=json, revision_id: a047de70-6326-49b6-b1ef-31d3a99940d0, description: Numero di abitazioni, format: JSON, name: numero-di-abitazioni-metadati, mimetype: application/json, created: 2014-07-08T17:47:33.593124 } |
| tags | [] |
| extras | {value: Numero delle abitazioni rilevate ai censimenti, key: Algoritmo}, {value: 1961, key: Anno di inizio}, {value: Servizio Statistica Provincia Autonoma di Trento, key: Fonte}, {value: Decennale, key: Frequenza di aggiornamento}, {value: Comune, key: Livello Geografico Minimo}, {value: Edilizia e opere pubbliche, key: Settore}, {value: Stock, key: Tipo di Fenomeno}, {value: R, key: Tipo di Indicatore}, {value: 16/04/2014, key: Ultimo aggiornamento}, {value: Unita', key: Unita' di misura}, {value: statistica_subpro:133, key: _harvest_source} |
| relationships_as_object | [] |
| relationships_as_subject | [] |
| groups | id: 7b86ac83-cfa6-44f1-9be8-8075754934e5, name: ambiente |
| owner_org | 1ca43c96-db71-4ffd-9f5b-d95c9263f652 |
The attributes are as follows:
| Attribute | Description |
|---|---|
| id (string) | The name or id of the dataset to update |
The other parameters are the same of creation.
An example of update request in python with CKAN API version 3:
#Request
request = urllib2.Request(domain+'/api/3/action/package_update')
#Add authorization header
request.add_header('Authorization', authorizationCode)
#HTTP request
response = urllib2.urlopen(request, dataset)