Skip to content

Instantly share code, notes, and snippets.

@sleitner
Last active August 29, 2015 14:23
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 sleitner/e222a0499a8290f64db7 to your computer and use it in GitHub Desktop.
Save sleitner/e222a0499a8290f64db7 to your computer and use it in GitHub Desktop.
Interacting with datastore API
API_KEY='<INSERT YOUR API KEY>'
SITE_API='<CKAN WEBSITE:PORT>/api/3/action/'
RES_ID='<INSERT CREATED RESOURCE ID>'
#create
echo '----------------create'
curl -X POST ${SITE_API}/datastore_create -H "Authorization: ${API_KEY}" -d '{"force":"true", "resource_id":"'${RES_ID}'", "primary_key":["name"], "fields": [{"id":"name"},{"id":"tab", "type":"json"}],"records" : [ {"name": "datadict", "tab": [{"item1_int":1,"item2_txt":"xyz"}] } ]}'; echo '';
curl -X POST ${SITE_API}/datastore_create -H "Authorization: ${API_KEY}" -d '{"force":"true", "resource_id":"'${RES_ID}'", "records" : [ {"name": "otherdata", "tab": [{"k1":1,"k2":2}] } ]}'; echo '';
#show
echo '----------------show'
curl -X GET ${SITE_API}/datastore_search?resource_id=${RES_ID} -H "Authorization: ${API_KEY}"; echo '';
#update
echo '----------------update'
curl -X POST ${SITE_API}/datastore_upsert -H "Authorization: ${API_KEY}" -d '{"force":"true", "resource_id":"'${RES_ID}'", "method":"upsert", "records" : [ {"name": "datadict", "tab": [{"item1_int":4444,"item2_txt":1111}] } ]}'; echo '';
#show
echo '----------------show'
curl -X GET ${SITE_API}/datastore_search?resource_id=${RES_ID} -H "Authorization: ${API_KEY}"; echo '';
#delete
echo '----------------delete otherdata'
curl -X POST ${SITE_API}/datastore_delete -H "Authorization: ${API_KEY}" -d '{ "force":"true", "resource_id":"'${RES_ID}'", "filters":{"name":"otherdata"} }'; echo '';
#show
echo '----------------show'
curl -X GET ${SITE_API}/datastore_search?resource_id=${RES_ID} -H "Authorization: ${API_KEY}"; echo '';
#delete
echo '----------------delete'
curl -X POST ${SITE_API}/datastore_delete -H "Authorization: ${API_KEY}" -d '{ "force":"true", "resource_id":"'${RES_ID}'", "filters":{} }'; echo '';
@sleitner
Copy link
Author

output

----------------create
{"help": "http://127.0.0.1:8080/api/3/action/help_show?name=datastore_create", "success": true, "result": {"primary_key": ["name"], "resource_id": "09487ca6-3859-4787-95ad-e8b6cd52fab6", "fields": [{"type": "text", "id": "name"}, {"type": "json", "id": "tab"}], "records": [{"name": "datadict", "tab": [{"item1_int": 1, "item2_txt": "xyz"}]}], "method": "insert"}}
{"help": "http://127.0.0.1:8080/api/3/action/help_show?name=datastore_create", "success": true, "result": {"records": [{"name": "otherdata", "tab": [{"k2": 2, "k1": 1}]}], "method": "insert", "resource_id": "09487ca6-3859-4787-95ad-e8b6cd52fab6"}}
----------------show
{"help": "http://127.0.0.1:8080/api/3/action/help_show?name=datastore_search", "success": true, "result": {"resource_id": "09487ca6-3859-4787-95ad-e8b6cd52fab6", "fields": [{"type": "int4", "id": "_id"}, {"type": "text", "id": "name"}, {"type": "json", "id": "tab"}], "records": [{"_id": 1, "name": "datadict", "tab": [{"item1_int": 1, "item2_txt": "xyz"}]}, {"_id": 2, "name": "otherdata", "tab": [{"k2": 2, "k1": 1}]}], "_links": {"start": "/api/3/action/datastore_search?resource_id=09487ca6-3859-4787-95ad-e8b6cd52fab6", "next": "/api/3/action/datastore_search?offset=100&resource_id=09487ca6-3859-4787-95ad-e8b6cd52fab6"}, "total": 2}}
----------------update
{"help": "http://127.0.0.1:8080/api/3/action/help_show?name=datastore_upsert", "success": true, "result": {"records": [{"name": "datadict", "tab": ["[{\"item1_int\": 4444, \"item2_txt\": 1111}]", ""]}], "method": "upsert", "resource_id": "09487ca6-3859-4787-95ad-e8b6cd52fab6"}}
----------------show
{"help": "http://127.0.0.1:8080/api/3/action/help_show?name=datastore_search", "success": true, "result": {"resource_id": "09487ca6-3859-4787-95ad-e8b6cd52fab6", "fields": [{"type": "int4", "id": "_id"}, {"type": "text", "id": "name"}, {"type": "json", "id": "tab"}], "records": [{"_id": 2, "name": "otherdata", "tab": [{"k2": 2, "k1": 1}]}, {"_id": 1, "name": "datadict", "tab": [{"item1_int": 4444, "item2_txt": 1111}]}], "_links": {"start": "/api/3/action/datastore_search?resource_id=09487ca6-3859-4787-95ad-e8b6cd52fab6", "next": "/api/3/action/datastore_search?offset=100&resource_id=09487ca6-3859-4787-95ad-e8b6cd52fab6"}, "total": 2}}
----------------delete otherdata
{"help": "http://127.0.0.1:8080/api/3/action/help_show?name=datastore_delete", "success": true, "result": {"filters": {"name": "otherdata"}, "resource_id": "09487ca6-3859-4787-95ad-e8b6cd52fab6"}}
----------------show
{"help": "http://127.0.0.1:8080/api/3/action/help_show?name=datastore_search", "success": true, "result": {"resource_id": "09487ca6-3859-4787-95ad-e8b6cd52fab6", "fields": [{"type": "int4", "id": "_id"}, {"type": "text", "id": "name"}, {"type": "json", "id": "tab"}], "records": [{"_id": 1, "name": "datadict", "tab": [{"item1_int": 4444, "item2_txt": 1111}]}], "_links": {"start": "/api/3/action/datastore_search?resource_id=09487ca6-3859-4787-95ad-e8b6cd52fab6", "next": "/api/3/action/datastore_search?offset=100&resource_id=09487ca6-3859-4787-95ad-e8b6cd52fab6"}, "total": 1}}
----------------delete
{"help": "http://127.0.0.1:8080/api/3/action/help_show?name=datastore_delete", "success": true, "result": {"resource_id": "09487ca6-3859-4787-95ad-e8b6cd52fab6"}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment