Updating dataset from Javascript

zasadamaciej
Level 1
Updating dataset from Javascript

Hi all,

I'm creating an webapp in Dataiku. The problem I'm currently facing is that I want to create function in JS that allow user to edit Dataset. I know that it can be done through Python / Flask and I have already that solution however I would like to not use Python in my webapp.

So far I managed to create following with REST API:

  • read function
$.ajax({
    url: "/projects/{projectKey}/datasets/{datasetName}/data",
    headers : {"Authorization" : "Basic " + btoa("PersonalAPIKey:")},
    contentType: "application/json",
    type: "GET",
    
    success: function(response) {
        result.innerHTML = JSON.stringify(response)
    }, 
    error: function(response) {
        result.innerHTML = JSON.stringify(response)
    }
    
  • Delete function
$.ajax({
    url: "/projects/{projectKey}/datasets/{datasetName}/data",
    headers : {"Authorization" : "Basic " + btoa("PersonalAPIKey:")},
    contentType: "application/json",
    type: "Delete",
    
    success: function(response) {
        alert("Data Deleted")
    }, 
    error: function(response) {
        alert(JSON.stringify(response))
    }

However, I'm facing issues when I try to add a row to the dataset:

$.ajax({
    url: "/projects/{projectKey}/datasets/{datasetName}/data",
    headers : {"Authorization" : "Basic " + btoa("PersonalAPIKey:")},
    contentType: "application/json",
    data: {'col1':'val1'},
    type: "POST",
    
    success: function(response) {
        result.innerHTML = JSON.stringify(response)
    }, 
    error: function(response) {
        result.innerHTML = JSON.stringify(response)
    }

When I try to send POST request I receive following error:

 Expected BEGIN_OBJECT but was STRING at line 1 column 1

Which makes no sense as I'm attaching object as a data (JSON Table).

When parsed data as a string like that: data: "{'col1':'val21'}" than I receive following error:

Format name is mandatory

But I'm not sure on how I can add format in data request.

Any advise on how this can be resolved? Do you know other methods on how you can add data to dataset through JS?

Thanks,
Maciej

0 Kudos
1 Reply
HenriC
Dataiker

Hello @zasadamaciej,

Unfortunately, it is currently not possible to edit a dataset using the public API.

The message you get from the API is because POST method on this endpoint is only for large and complex requests (See https://doc.dataiku.com/dss/api/8.0/rest/#datasets-dataset-data-post).

The only way to edit your dataset is indeed to use Python with Flask.

Have a nice day,

Henri

0 Kudos