dkan icon indicating copy to clipboard operation
dkan copied to clipboard

Create a distribution for an existing dataset via the Metastore API

Open Katsivelisp opened this issue 2 years ago • 3 comments

Hello,

I am working with the DKAN (v2.11) API and I would like to automate things a little bit when it comes to distribution creation. Currently, it looks like the API supports creating (POST) new distributions and also updating datasets (PATCH). However, creating a distribution for a specific dataset does not seem to be supported. Neither is updating datasets to reference an existing distribution.

So, my question is: how can I use the API to create a distribution for an existing dataset?

Thanks in advance!

Katsivelisp avatar Apr 18 '22 15:04 Katsivelisp

@Katsivelisp if you mean using the file upload then yes this will not work, but if you host your files on some other publicly accessible server (S3), or rsync your files to sites/default/files/data-files/... then you can use your site as the 'remote' server

PATCH https://{your.domain}/api/1/metastore/schemas/dataset/items/{uuid-of-your-dataset}

{
  "modified": "2022-04-18",
  "distribution": [
      {
        "title": "My new file",
        "format": "csv",
        "downloadURL": "https://{your.domain}/sites/default/files/data-files/data.csv"
      }
    ],
}

janette avatar Apr 18 '22 18:04 janette

@Katsivelisp to add to this -- while distributions and datasets are stored as separate entities in DKAN and this is reflected in both of them existing as separate resources in the API, in real-life use there aren't a lot of reasons to create distributions on their own. Generally you will be best-served by treating distributions as part of the dataset entity. Make changes to the distribution array in the dataset and DKAN's referencing logic will take care of the distribution entities behind the scenes.

dafeder avatar Apr 18 '22 18:04 dafeder

Thanks @janette and @dafeder.

Sorry for not making it clear, but yeah. I wanted the new distribution to point to a remote URL, which is actually a Drupal Views CSV export of my own site. I will try the above solution and let you know.

Katsivelisp avatar Apr 18 '22 18:04 Katsivelisp