ckan / ckanext-scheming

Easy, shareable custom CKAN schemas
Other
87 stars 163 forks source link

Error "There is a schema field with the same name" when using API #352

Closed ghost closed 1 year ago

ghost commented 1 year ago

Hi!

I am using CKAN 2.9.5 on Ubuntu and testing the extension with a very simple schema:

scheming_version: 2
dataset_type: dataset
about: A reimplementation of the default CKAN dataset schema
about_url: http://github.com/ckan/ckanext-scheming

dataset_fields:

- field_name: title
  label: Title
  form_placeholder: Name of the dataset.
  preset: title

- field_name: name
  label: URL
  preset: dataset_slug
  form_placeholder: eg. my-dataset

- field_name: owner_org
  label: Organization
  preset: dataset_organization

- field_name: test
  label: Test

resource_fields:

- field_name: url
  label: URL
  preset: resource_url_upload

I would like to be able to post data following this schema via the API (I use HTTPie). I get the following error message:

POST /api/3/action/package_create HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate, br
Authorization: <API-KEY>
Connection: keep-alive
Content-Length: 120
Content-Type: application/json
Host: myckan.com
User-Agent: HTTPie/3.1.0

{
    "extras": [
        {
            "key": "test",
            "value": "123\n456"
        }
    ],
    "name": "dataset_name4",
    "owner_org": "org",
    "title": "ffffffftle"
}

HTTP/1.1 409 CONFLICT
Cache-Control: public, max-age=0, must-revalidate
Connection: keep-alive
Content-Length: 210
Content-Type: application/json;charset=utf-8
Date: Tue, 03 Jan 2023 07:59:43 GMT
Server: nginx/1.18.0 (Ubuntu)

{
    "error": {
        "__type": "Validation Error",
        "extras": [
            {
                "key": [
                    "There is a schema field with the same name"
                ]
            }
        ]
    },
    "help": "https://myckan.com/api/3/action/help_show?name=package_create",
    "success": false
}

What is the problem here?

ghost commented 1 year ago

I found out what's wrong: with the scheming extension, there no more extras-fields. The metadata must simply be a list of key-value pairs.