Help with JSON format For HTTP POST request

Hi Everyone,

Thanks for looking at this. I am trying to replicate the following curl script:

curl -H “X-CDD-Token:apitoken” --form-string ‘json={“project”: “TPD”, “autoreject”:“false”, “mapping_template”: “19032”,“runs”:[{“run_date”: “2022-01-21”,“place”: “lab”}]}’ -F ‘file=@file.csv’ ‘https://app.collaborativedrug.com/api/v1/vaults/0001/slurps

I can confirm that the syntax here works and the script is able to post the data from the file to the site successfully.

I am trying to replicate this using one of the palladium HTTPS Retriever like in this post to post data from a file to the site.

HTTP POST

I’m getting a 404 error and unfortunately the node is not very verbose on what I did wrong. I tried to work backwards and modify the string in my curl script and I get a 404 error when I run the curl script in verbose mode. So I suspect that there is something wrong with my JSON that I’m sending. Here is what the JSON I’m trying to send over the HTTP Request node looks like:

[ {
“project” : “T”,
“mapping_template” : 19032,
“runs” : “run_date:2022-01-21”,
“autoreject” : “false”
} ]

OR

[ {
“project” : “T”,
“mapping_template” : 19032,
“runs” : “[{“run_date”:“2022-01-21”}]”,
“autoreject” : “false”
} ]

I’ve even cut out the “nested part” to simplify like this

[{
“project”: “T”,
“mapping_template”: 19032,
“autoreject”: “false”
}]

JSONlint says all of these are vaild but I can’t get it to work so I’m really stumped.

Thanks in advance for any thoughts you might have

Jason

OK some more info. If I uncheck the “fail with non success” I get the following response

image

and this is the JSON that was sent over which from all I can tell is valid. But it appears to me that parameters means something is wrong with the JSON.

{
“project” : “T”,
“autoreject” : “false”,
“mapping_template” : “19032”,
“runs” : [ {
“run_date” : “2022-01-21”
} ]
}

Are you sure you are using the correct quotes (") ? Those in the post don’t seem to be valid
br

1 Like

Hi @Daniel_Weikert,

Thanks for taking a look. If I think the quotes are OK as I get the same error with or without them. The error seems to be pointing to the data that I’m sending not the JSON as I play with it more.

Thanks,
Jason

Hi @j_ochoada , when pasting code, please use the Preformatted Text option:
image

That way, the quotes in your JSON code will not be transformed as Opening quotes and Closing quotes, cause that’s how your quotes look like, and we can’t tell if that’s how they are in your JSON code or if it’s the Forum platform that converted them - and that’s probably why @Daniel_Weikert asked that question to make sure you are NOT using the opening and closing quotes as we can’t tell how they really are in your code.

The error that you are getting is what the api is returning. Your JSON is a valid JSON in that it’s the correct syntax and format, so that is not the issue. The parameter here refers to the parameter you are sending via JSON. You are not sending some parameter as the api instructed to, so this is something that we can’t help without knowing what the api accepts and does not.

From your curl command, you are passing the data as ‘json=…’, but I don’t see this in any of the examples you showed.

EDIT: Just to add, the reason why apis are not very verbose is to protect against hacking. As an api, you don’t want to be telling an intruder why it’s failing. That is why, for example, when you fail at a login, it does not tell you whether specifically it’s your login or if it’s specifically your password that’s wrong. It simply says “invalid login or password”. They never say what specifically is the issue, and that’s on purpose

1 Like

@j_ochoada maybe this post can help you https://support.collaborativedrug.com/hc/en-us/articles/115005685006-API-via-Knime-the-basics.

1 Like

@bruno29a Apologies for not knowing about the formatting options. Here is a current version of the JSON after clicking preformatted text and pasting it in. This JSON works and there was actually an issue with the data I was passing which @qqilihq helped me sort out

{
  "project" : "TEST",
  "autoreject" : "false",
  "mapping_template" : "XXXXX",
  "runs" : [ {
    "run_date" : "2022-01-21"
  } ]
}

Thanks for explaining why the failures are so obtuse, that makes sense!

@duristef Thanks for the link! Yes I have been through all that documentation and believe it or not I have exhausted CDD’s support current expertise in KNIME. Everything I learn here though I am posting to the HUB so others can have an easier time than I have :slight_smile:

Jason

4 Likes

@bruno29a was right about my assumption. Glad that you fixed it. Thanks for sharing your findings and contribute to the community.
br

1 Like

For those who are interested in building JSON to POST data to CDD (Collaborative Drug Discovery)

Here is my examples where you can just put in the exact string to get going and then later convert column values or variables into a valid JSON statement.

Build JSON for CDD POST request

1 Like