update a document using the curl -X PUT command
Hello,
I wanted to update the "name" field in a document using a curl command.
I used the 2 following command:
- curl --user API_KEY_SECRET: -H 'Content-Type: application/json' -X PUT URL -d '{"login": "sa55", "name": "camille"}'
- curl --user API_KEY_SECRET: -H 'Content-Type: application/json' -X PUT URL/sa55/ -d '{"name": "camille"}'
the first displays no error but does not update the document and the second displays this error
{"errorType": "com.dataiku.common.server. DKUControllerBase$MalformedRequestException", "message": "User login does not match requested URL", "detailedMessage": "User login does not match requested URL", "detailedMessageHTML": "\u003cspan\u003e\u003cspan class\u003d\"err-msg\"\u003eUser login does not match requested URL\u003c/span\u003e\u003c/span\u003e", "stackTrace":[]}.
knowing that the GET command works fine.
here's the schematic of my json file.
[
{
"login": "sa55",
"name": "sara"
},
{
"login": "sa56",
"name": "Sophie"
}
]
hope you can help me
Best Answer
-
HELLO,
finally I used this query which can have the results of a GET command and modify a specific field via a curl PUT request:
curl -X GET '<GET_URL>' | sed 's/<old_value>/<NEW_VALUE>/g' | curl -X PUT -H "Content-Type: application/json" -d @- '<PUT_URL>'
In this example, I used the curl command to send a curl GET request to the URL <GET_URL>, then the sed command to replace the specified value <old_value> with the new value <NEW_VALUE>.
Thank you.
Answers
-
tgb417 Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 1,601 Neuron
Welcome to the dataiku community. We are so glad to have you here.
In reading your post I have a few thoughts
- it looks like you are working with a REST API. Although you could also use curl to access this API I personally would tend to use the API connect plugin provided by Dataiku. I invite you to take a look at this plugin. https://www.dataiku.com/product/plugins/api-connect/ I use this plugin daily. It makes my life a bunch easier. You will need administrator access to your dataiku instance but once installed it works well for me. The plugin can do GET, PUT and a number of other types of commands on single records and more importantly on bulk data sets based on records in the downstream dataset.
- In your code sample here in the community you reference “API_KEY_SECRET”. It is great not to show your API key on this public site. But you will, of course, need to replace this with your actual API key provided by the API provider.
- As I work through challenges like this I tend to use the wonderful Postman application to make sure that I understand how to use the API before integrating the API into my project flow.
Hope that one of these might be of a little help to you.
-
tgb417 Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 1,601 Neuron
Finally in rereading your post. You note that the GET command works but the PUT command does not work. That makes me wonder if your API key has write access in the destination database. I check with the API provider to make sure that my API key has the ability to do a PUT. These kind of things I tend to do from Postman. Because most folks who work with API know the tool and it’s error messages are fairly good.
Again I hope that some of these ideas might be useful.
-
Hello,
thank you for your reply.yes I have already used this plugin and it works well with the GET and it displayed the same errors in the case of PUT
-
Hello,
I just found the problem, you have to write all the fields + the field to update in the request ( -d '{"key1": "value1", "key2": "value2", ....}' ) but it's not very useful because I have a lot of field. I want a query where I can modify the specific field without writing all the other fields.
-
tgb417 Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 1,601 Neuron
Check with your api provider. It is typical in my experience that one does not need to include all values, but often need to include more values than you might want.
you can often do a get, put, get sequence.
get all of the values from the api
put all the values back with the changes you need to make
get all the values to confirm that your changes have been made
good luck.
-
thank you!!
-
tgb417 Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 1,601 Neuron
looking forward to hearing more about how you get on with this.
-
tgb417 Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS ML Practitioner, Dataiku DSS Core Concepts, Neuron 2020, Neuron, Registered, Dataiku Frontrunner Awards 2021 Finalist, Neuron 2021, Neuron 2022, Frontrunner 2022 Finalist, Frontrunner 2022 Winner, Dataiku Frontrunner Awards 2021 Participant, Frontrunner 2022 Participant, Neuron 2023 Posts: 1,601 Neuron