Help with HTTP-Retriever

Hello,
I’m trying to post a datafile in csv format utilizing an API. I can get it to work in CURL but I’m struggling to translate it to KNIME. The API I have been trying to post to is CDD or Collaborative Drug Discovery. I’ve seen a few threads and workflows that attempt this but It’s not clear if any of these prior cases have been successful.

The scenario is that there is a mapping template that had project info, maps the column headers for uploading into the database etc.

The error I’m getting is the following

{
“error” : “Illegal parameter(s): BinaryObject”,
“code” : 404
}

I thought OK, maybe something is wrong with my file so I stripped it all back to a very simple file with 4 columns etc. but I am getting the same results.

I’m really stuck and I’m not savvy enough to know how to find the illegal parameters.

Any help would be super appreciated and I plan to put the solution on the HUB so others can benefit. I’ve uploaded a modified version of a workflow that @qqilihq has previously developed.
Palladium_HTTP_Retriever_Multipart_Example_JMO.knwf (35.3 KB)

Thanks!
Jason

Here is the abbreviated file which I’m trying to post. Happy to provide the token and JSON if someone is willing to take a look!

Thanks :slight_smile:
Jason
testfile.txt (40.4 KB)

Hi Json,

are you sure that the parameter name for the binary data should be BinaryObject? (see Multipart Encoded HTTP Entity Creator node)

Could you share a completely runnable workflow at mail@palladian.ws ?

–Philipp

Hi @qqilihq,

Just dropped you a line at the email you provided. I looked at the creator node and I patterned it after you image example. You took the URI of the image and went from file to binary object. I did the same with my csv file.

image

Thanks!
Jason

I have just replied via email, but I thought I keep this thread up-to-date as well. At the end, it was indeed the parameter name which needed to be changed:

This is the name of the field which submits the binary data / file.

–Philipp

4 Likes

Thanks @qqilihq Very interesting and tricky… As that “Name” auto populates when the input column is selected. I wonder how many different names there could be that would need to be set when they are wrapped / converted into a BinaryObject.

Anyway, look forward to posting this version of your workflow on the HUB so others can benefit!

Thanks,
Jason

2 Likes

OK almost there! @qqilihq I posted on another thread showing the examples I used to build the valid JSON to make the POST call for CDD here.

Build JSON for CDD POST request

The only trick left is how to properly pass the file name information to the HTTP Entity Creator node from a variable. I have tried list and set and string (set shown here) → [file_0.csv, none.json]

but if throws the following error.

{ “error” : “no implicit conversion of ActionDispatch::Http::UploadedFile into String”, “code” : 400 }

Passing the file name is very useful as that is recorded by the application and allows for checking to make sure the right files get uploaded.

Thanks,
Jason

Whoups. Probably we have too much pseudo-intelligence here in the UI. Minor detail, but let me see if we can improve that. Thanks for the hint

I’d think a list resp. array with ['variable.name_of_the_file.csv', null] or ['variable.name_of_the_file.csv', ''] (empty string) should do the trick?

1 Like

@qqilihq Thanks for looking into this again! I did try both of those but not with the single quotes. I think I tried double quotes. I’ll try now and reply back.

Thanks again so much,
Jason

OK here is what I’ve tried and they all give this response:

{
  "error" : "no implicit conversion of ActionDispatch::Http::UploadedFile into String",
  "code" : 400
}

So taking in the filename and adding single quotes with null in single quotes or empty string doesn’t work

[‘filename.csv,‘null’]
[‘filename.csv’,null]
[‘filename.csv’,’’]
[filename.csv,null]

Here is how I’m building that list.

Filename value comes in, java snippet adds the single quotes around it, constant value adds the ‘null’, null, or ‘’ and then the list is built using the column aggregator and then passed as a variable to the muliti creator node and the variable is selected for filename.

image

image

@j_ochoada First, thanks for the patience!

I have just inspected this in our example workflow which we shared before. To figure out the proper structure of the flow variables, I first used the configured node and passed the data into a newly created flow variable (if anybody who reads this actually wonders what these fields without any title are for: these allow to create a new flow variable based on data entered in the dialog :clown_face: ).

So, I created a variable fileNames to output the current configuration:

Save the dialog, show the node output, and switch to the “Flow Variables” tab:

So the node should allow to pass a string array (if I interpret the icon correctly) flow variable, where empty fields from the dialog are just filled with null.

Thus, I assume that the structure or data type which you feed to the node through the variable is probably wrong. Could you @j_ochoada show a screenshot of your “Table Row to Variable” output with the “Flow Variables” tab? And also your “Flow Variables” configuration of the Multipart Encoded HTTP Entity Creator node?

-Philipp

2 Likes

Thanks for looking at this again @qqilihq
Here is a screenshot of the column aggregator to make the list (is this different from string array?):

image

Here is the config of the HTTP creator:

image

image

And finally the pass through of that created variable as HTTP_output variable

I also tried this node passing in testfile.csv and null but that gave the same error also.

image

image

Hope this helps,
Jason

Hi Jason,

I just had the opportunity to try this locally, and the problem is, that the “Create String Array Variable” meta node will obviously not allow null values. If you enter “null”, it will be a literal “null” (as a string, and not as null).

The Table Row to Variable node which I tried next insists on replacing missing values with a string placeholder. :exploding_head:

Other nodes (such as the Java snippet ones) do not even seem to support array-typed flow variables. Not really satisfying and KNIME probably needs to do some more of their homework to finish that half-baked flow variable support :point_up:

So, the question: How can we create a string array flow variable with null values? I have no clue to be honest, so we’re somewhat back to zero now.

Fortunately I came up with a different solution:

  1. Leave the Multipart Encoded HTTP Entity Creator node as it is. No flow variables. Just configure a static placeholder filename such as file.svg as this point.

  2. After this node, I put a Binary Objects to Strings node to temporarily convert the BLOB into a string. For decoding I set ISO-8859-1 (other ones will destroy the payload!).

  3. This enables you to manipulate the payload using a String Manipulation node. At this point, you can put an expression like so which will set the desired filename: replace($multipartEntity$, "filename=\"file.svg\"", "filename=\"renamed.svg\"") (backslashes are needed to escape the inner " quotes).

  4. Afterwards you can transform the string back to a BLOB using a Strings to Binary Objects node. Ensure to use ISO-8859-1 as well.

  5. From there on, continue as before and input the result into the HTTP Retriever.

Hope this helps!

–Philipp

Hey @qqilihq ! Wow thanks so much for continuing to keep on this. Bummer on one hand but fantastic that there is a work around. I’m glad I wasn’t making a careless mistake. But on the other hand, that would have been much easier. :slight_smile: :slight_smile:

Let me give it a try and I’ll report back!

Thanks,
Jason

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.