...
Code Block | ||
---|---|---|
| ||
$ curl https://demo.ckan.org/api/rest/dataset/dataset-has-a-tail --header 'Content-Type: application/json' -H "Authorization:<API_KEY>" -d'{ "name": "dataset-has-a-tail", "title": "OMG its a dataset with a tail", "extras": { "Metadata": "{\\r\\n \\\"apiVersion\\\": \\\"1.0.0\\\",\\r\\n \\\"swaggerVersion\\\": \\\"1.2\\\",\\r\\n \\\"basePath\\\": \\\"http:\\/\\/petstore.swagger.io\\/api\\\",\\r\\n \\\"resourcePath\\\": \\\"\\/store\\\",\\r\\n \\\"produces\\\": [\\r\\n \\\"application\\/json\\\"\\r\\n ],\\r\\n \\\"apis\\\": [\\r\\n {\\r\\n \\\"path\\\": \\\"\\/store\\/order\\/{orderId}\\\",\\r\\n \\\"operations\\\": [\\r\\n {\\r\\n \\\"method\\\": \\\"GET\\\",\\r\\n \\\"summary\\\": \\\"Find purchase order by ID\\\",\\r\\n \\\"notes\\\": \\\"For valid response try integer IDs with value <= 5. Anything above 5 or nonintegers will generate API errors\\\",\\r\\n \\\"type\\\": \\\"Order\\\",\\r\\n \\\"nickname\\\": \\\"getOrderById\\\",\\r\\n \\\"authorizations\\\": {},\\r\\n \\\"parameters\\\": [\\r\\n {\\r\\n \\\"name\\\": \\\"orderId\\\",\\r\\n \\\"description\\\": \\\"ID of pet that needs to be fetched\\\",\\r\\n \\\"required\\\": true,\\r\\n \\\"type\\\": \\\"string\\\",\\r\\n \\\"paramType\\\": \\\"path\\\"\\r\\n }\\r\\n ],\\r\\n \\\"responseMessages\\\": [\\r\\n {\\r\\n \\\"code\\\": 400,\\r\\n \\\"message\\\": \\\"Invalid ID supplied\\\"\\r\\n },\\r\\n {\\r\\n \\\"code\\\": 404,\\r\\n \\\"message\\\": \\\"Order not found\\\"\\r\\n }\\r\\n ]\\r\\n },\\r\\n {\\r\\n \\\"method\\\": \\\"DELETE\\\",\\r\\n \\\"summary\\\": \\\"Delete purchase order by ID\\\",\\r\\n \\\"notes\\\": \\\"For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors\\\",\\r\\n \\\"type\\\": \\\"void\\\",\\r\\n \\\"nickname\\\": \\\"deleteOrder\\\",\\r\\n \\\"authorizations\\\": {\\r\\n \\\"oauth2\\\": [\\r\\n {\\r\\n \\\"scope\\\": \\\"test:anything\\\",\\r\\n \\\"description\\\": \\\"anything\\\"\\r\\n }\\r\\n ]\\r\\n },\\r\\n \\\"parameters\\\": [\\r\\n {\\r\\n \\\"name\\\": \\\"orderId\\\",\\r\\n \\\"description\\\": \\\"ID of the order that needs to be deleted\\\",\\r\\n \\\"required\\\": true,\\r\\n \\\"type\\\": \\\"string\\\",\\r\\n \\\"paramType\\\": \\\"path\\\"\\r\\n }\\r\\n ],\\r\\n \\\"responseMessages\\\": [\\r\\n {\\r\\n \\\"code\\\": 400,\\r\\n \\\"message\\\": \\\"Invalid ID supplied\\\"\\r\\n },\\r\\n {\\r\\n \\\"code\\\": 404,\\r\\n \\\"message\\\": \\\"Order not found\\\"\\r\\n }\\r\\n ]\\r\\n }\\r\\n ]\\r\\n },\\r\\n {\\r\\n \\\"path\\\": \\\"\\/store\\/order\\\",\\r\\n \\\"operations\\\": [\\r\\n {\\r\\n \\\"method\\\": \\\"POST\\\",\\r\\n \\\"summary\\\": \\\"Place an order for a pet\\\",\\r\\n \\\"notes\\\": \\\"\\\",\\r\\n \\\"type\\\": \\\"void\\\",\\r\\n \\\"nickname\\\": \\\"placeOrder\\\",\\r\\n \\\"authorizations\\\": {\\r\\n \\\"oauth2\\\": [\\r\\n {\\r\\n \\\"scope\\\": \\\"test:anything\\\",\\r\\n \\\"description\\\": \\\"anything\\\"\\r\\n }\\r\\n ]\\r\\n },\\r\\n \\\"parameters\\\": [\\r\\n {\\r\\n \\\"name\\\": \\\"body\\\",\\r\\n \\\"description\\\": \\\"order placed for purchasing the pet\\\",\\r\\n \\\"required\\\": true,\\r\\n \\\"type\\\": \\\"Order\\\",\\r\\n \\\"paramType\\\": \\\"body\\\"\\r\\n }\\r\\n ],\\r\\n \\\"responseMessages\\\": [\\r\\n {\\r\\n \\\"code\\\": 400,\\r\\n \\\"message\\\": \\\"Invalid order\\\"\\r\\n }\\r\\n ]\\r\\n }\\r\\n ]\\r\\n }\\r\\n ],\\r\\n \\\"models\\\": {\\r\\n \\\"Order\\\": {\\r\\n \\\"id\\\": \\\"Order\\\",\\r\\n \\\"description\\\": \\\"an order in the system\\\",\\r\\n \\\"properties\\\": {\\r\\n \\\"id\\\": {\\r\\n \\\"type\\\": \\\"integer\\\",\\r\\n \\\"format\\\": \\\"int64\\\"\\r\\n },\\r\\n \\\"petId\\\": {\\r\\n \\\"type\\\": \\\"integer\\\",\\r\\n \\\"format\\\": \\\"int64\\\"\\r\\n },\\r\\n \\\"quantity\\\": {\\r\\n \\\"type\\\": \\\"integer\\\",\\r\\n \\\"format\\\": \\\"int32\\\"\\r\\n },\\r\\n \\\"status\\\": {\\r\\n \\\"type\\\": \\\"string\\\",\\r\\n \\\"description\\\": \\\"Order Status\\\",\\r\\n \\\"enum\\\": [\\r\\n \\\"placed\\\",\\r\\n \\\" approved\\\",\\r\\n \\\" delivered\\\"\\r\\n ]\\r\\n },\\r\\n \\\"shipDate\\\": {\\r\\n \\\"type\\\": \\\"string\\\",\\r\\n \\\"format\\\": \\\"date-time\\\"\\r\\n }\\r\\n }\\r\\n }\\r\\n }\\r\\n}" } }' -H "Authorization:<API_KEY>" { { "license_title": null, "maintainer": null, "private": false, "maintainer_email": null, "num_tags": 0, "id": "a09f9319-bf4c-48a0-8d98-a8d066d6636d", "metadata_created": "2018-08-13T18:00:48.853260", "relationships": [], "license": null, "metadata_modified": "2018-08-13T22:19:02.606453", "author": null, "author_email": null, "state": "active", "version": null, "creator_user_id": "28fb4558-3686-4b24-96d9-8d935190d962", "type": "dataset", "resources": [], "num_resources": 0, "tags": [], "groups": [], "license_id": null, "organization": null, "name": "dataset-has-a-tail", "isopen": false, "notes_rendered": "", "url": null, "ckan_url": "https://demo.ckan.org/dataset/dataset-has-a-tail", "notes": null, "owner_org": null, "ratings_average": null, "extras": { "Metadata": "{\\r\\n \\\"apiVersion\\\": \\\"1.0.0\\\",\\r\\n \\\"swaggerVersion\\\": \\\"1.2\\\",\\r\\n \\\"basePath\\\": \\\"http:\\/\\/petstore.swagger.io\\/api\\\",\\r\\n \\\"resourcePath\\\": \\\"\\/store\\\",\\r\\n \\\"produces\\\": [\\r\\n \\\"application\\/json\\\"\\r\\n ],\\r\\n \\\"apis\\\": [\\r\\n {\\r\\n \\\"path\\\": \\\"\\/store\\/order\\/{orderId}\\\",\\r\\n \\\"operations\\\": [\\r\\n {\\r\\n \\\"method\\\": \\\"GET\\\",\\r\\n \\\"summary\\\": \\\"Find purchase order by ID\\\",\\r\\n \\\"notes\\\": \\\"For valid response try integer IDs with value <= 5. Anything above 5 or nonintegers will generate API errors\\\",\\r\\n \\\"type\\\": \\\"Order\\\",\\r\\n \\\"nickname\\\": \\\"getOrderById\\\",\\r\\n \\\"authorizations\\\": {},\\r\\n \\\"parameters\\\": [\\r\\n {\\r\\n \\\"name\\\": \\\"orderId\\\",\\r\\n \\\"description\\\": \\\"ID of pet that needs to be fetched\\\",\\r\\n \\\"required\\\": true,\\r\\n \\\"type\\\": \\\"string\\\",\\r\\n \\\"paramType\\\": \\\"path\\\"\\r\\n }\\r\\n ],\\r\\n \\\"responseMessages\\\": [\\r\\n {\\r\\n \\\"code\\\": 400,\\r\\n \\\"message\\\": \\\"Invalid ID supplied\\\"\\r\\n },\\r\\n {\\r\\n \\\"code\\\": 404,\\r\\n \\\"message\\\": \\\"Order not found\\\"\\r\\n }\\r\\n ]\\r\\n },\\r\\n {\\r\\n \\\"method\\\": \\\"DELETE\\\",\\r\\n \\\"summary\\\": \\\"Delete purchase order by ID\\\",\\r\\n \\\"notes\\\": \\\"For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors\\\",\\r\\n \\\"type\\\": \\\"void\\\",\\r\\n \\\"nickname\\\": \\\"deleteOrder\\\",\\r\\n \\\"authorizations\\\": {\\r\\n \\\"oauth2\\\": [\\r\\n {\\r\\n \\\"scope\\\": \\\"test:anything\\\",\\r\\n \\\"description\\\": \\\"anything\\\"\\r\\n }\\r\\n ]\\r\\n },\\r\\n \\\"parameters\\\": [\\r\\n {\\r\\n \\\"name\\\": \\\"orderId\\\",\\r\\n \\\"description\\\": \\\"ID of the order that needs to be deleted\\\",\\r\\n \\\"required\\\": true,\\r\\n \\\"type\\\": \\\"string\\\",\\r\\n \\\"paramType\\\": \\\"path\\\"\\r\\n }\\r\\n ],\\r\\n \\\"responseMessages\\\": [\\r\\n {\\r\\n \\\"code\\\": 400,\\r\\n \\\"message\\\": \\\"Invalid ID supplied\\\"\\r\\n },\\r\\n {\\r\\n \\\"code\\\": 404,\\r\\n \\\"message\\\": \\\"Order not found\\\"\\r\\n }\\r\\n ]\\r\\n }\\r\\n ]\\r\\n },\\r\\n {\\r\\n \\\"path\\\": \\\"\\/store\\/order\\\",\\r\\n \\\"operations\\\": [\\r\\n {\\r\\n \\\"method\\\": \\\"POST\\\",\\r\\n \\\"summary\\\": \\\"Place an order for a pet\\\",\\r\\n \\\"notes\\\": \\\"\\\",\\r\\n \\\"type\\\": \\\"void\\\",\\r\\n \\\"nickname\\\": \\\"placeOrder\\\",\\r\\n \\\"authorizations\\\": {\\r\\n \\\"oauth2\\\": [\\r\\n {\\r\\n \\\"scope\\\": \\\"test:anything\\\",\\r\\n \\\"description\\\": \\\"anything\\\"\\r\\n }\\r\\n ]\\r\\n },\\r\\n \\\"parameters\\\": [\\r\\n {\\r\\n \\\"name\\\": \\\"body\\\",\\r\\n \\\"description\\\": \\\"order placed for purchasing the pet\\\",\\r\\n \\\"required\\\": true,\\r\\n \\\"type\\\": \\\"Order\\\",\\r\\n \\\"paramType\\\": \\\"body\\\"\\r\\n }\\r\\n ],\\r\\n \\\"responseMessages\\\": [\\r\\n {\\r\\n \\\"code\\\": 400,\\r\\n \\\"message\\\": \\\"Invalid order\\\"\\r\\n }\\r\\n ]\\r\\n }\\r\\n ]\\r\\n }\\r\\n ],\\r\\n \\\"models\\\": {\\r\\n \\\"Order\\\": {\\r\\n \\\"id\\\": \\\"Order\\\",\\r\\n \\\"description\\\": \\\"an order in the system\\\",\\r\\n \\\"properties\\\": {\\r\\n \\\"id\\\": {\\r\\n \\\"type\\\": \\\"integer\\\",\\r\\n \\\"format\\\": \\\"int64\\\"\\r\\n },\\r\\n \\\"petId\\\": {\\r\\n \\\"type\\\": \\\"integer\\\",\\r\\n \\\"format\\\": \\\"int64\\\"\\r\\n },\\r\\n \\\"quantity\\\": {\\r\\n \\\"type\\\": \\\"integer\\\",\\r\\n \\\"format\\\": \\\"int32\\\"\\r\\n },\\r\\n \\\"status\\\": {\\r\\n \\\"type\\\": \\\"string\\\",\\r\\n \\\"description\\\": \\\"Order Status\\\",\\r\\n \\\"enum\\\": [\\r\\n \\\"placed\\\",\\r\\n \\\" approved\\\",\\r\\n \\\" delivered\\\"\\r\\n ]\\r\\n },\\r\\n \\\"shipDate\\\": {\\r\\n \\\"type\\\": \\\"string\\\",\\r\\n \\\"format\\\": \\\"date-time\\\"\\r\\n }\\r\\n }\\r\\n }\\r\\n }\\r\\n}" }, "ratings_count": 0, "title": "OMG its a dataset with a tail", "revision_id": "1f36361a-a9cf-498d-94e6-5af2431c98cd" } |
Creating or Uploading a New Resource to a Dataset
For more complex interactions such as file uploads, we may be much better off using the ckanclient in Python: https://stackoverflow.com/questions/14947468/uploading-a-file-through-ckans-api-1-8-how-to-do-it
If you're just learning or trying new things out, take a look at the CKAN FileStore docs: http://docs.ckan.org/en/ckan-2.7.3/maintaining/filestore.html#filestore-api
For example, you can upload a file using curl
with the following syntax:
Code Block | ||
---|---|---|
| ||
$ curl 'https://demo.ckan.org/api/action/resource_create' -H "Authorization:<API_KEY>" --form upload=@<FILE_TO_UPLOAD> --form package_id=<DATASET_NAME_TO_ATTACH_FILE>
{
"help": "https://demo.ckan.org/api/3/action/help_show?name=resource_create",
"success": true,
"result": {
"cache_last_updated": null,
"cache_url": null,
"mimetype_inner": null,
"hash": "",
"description": "",
"format": "PNG",
"url": "https://demo.ckan.org/dataset/a09f9319-bf4c-48a0-8d98-a8d066d6636d/resource/526301cc-aaa3-423c-9159-3741fef913dc/download/tux-copy.png",
"created": "2018-08-14T15:09:03.441040",
"state": "active",
"package_id": "a09f9319-bf4c-48a0-8d98-a8d066d6636d",
"last_modified": null,
"mimetype": null,
"url_type": "upload",
"position": 0,
"revision_id": "7fda82dd-b0c7-42a0-a06d-01cb9685f290",
"size": null,
"datastore_active": false,
"id": "526301cc-aaa3-423c-9159-3741fef913dc",
"resource_type": null,
"name": null
}
}
|