Updating dataset from Javascript

Options
zasadamaciej
zasadamaciej Registered Posts: 3 ✭✭✭✭

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

Answers

Setup Info
    Tags
      Help me…