POST Request Body

Hi,

I am trying to build a POST request body using string manipulation as I need the body to change with other fields’ values. I cannot figure out how to concatenate " with other fields values I keep getting syntax errors?

trying to build something like the below where the numbers change to a latitude and longitude. Any ideas for the double quotes?

{
“locations”: [
“123456”, “123456”,
“123456”, “123456”,
],
“options”: {
“OnetoOne”: true
}
}

Thanks

I think you may need to provide your source data table (or equivalent example) and the JSON body you want to end up with so that someone can help. It’s not 100% clear what you want to do here. I work with JSON quite a bit in my apps, so I may be able to help with a clearer definition.

String manipulation node is a last resort with JSON bodies - you should be able to get what you need from a series of Table to JSON nodes. It’s tricky at first, but most things are possible.

If you just need to remove the quotes from the JSON above, then you can use the string manipulation node. Just use the replace function with a blank as replacement. But I am fairly sure this won’t solve all your issues.

2 Likes

hi there @graeme_morrell,

welcome to KNIME Community!

So you are trying to build a POST request in some kind of a loop? I assume you are using flow variables for that purpose as well? If so topic where String Manipulation was used to build a complex query can help:

Br,
Ivan

@ipazin thanks,

Not going to lie I’m a novice on knime and completely self taught so I have yet to go into flow variables. But correct I am trying to build a post request body for each row of data and make individual requests.

I will have a look at what you suggested I tried using just the standard string manipulation but couldn’t work out how to concat double quotes onto strings/ fields using the join function

Thanks again

Hi @graeme_morrell,

I see. No problem. We all learn. So to have quotes you need to use escape character before them and that is backslash so something like this:
join("\"This is a string with quotes around it\"","Another string")

And about making POST request for each row you wanna use Table Row To Variable Loop Start node.

For more on flow variables see here: https://www.knime.com/knime-introductory-course/chapter7/section1/creation-and-usage-of-flow-variables

Give it a try and if any questions feel free to ask. Also can can make you an example if you get stuck :wink:

Br,
Ivan

Hey @ipazin

I did find an article about escape characters but I thought I was doing something wrong as I got constant errors. I copied your join in the previous post and got this error I have no idea why?

Any Ideas what this means?

Thanks for all the help

Hi @graeme_morrell,

hm. Not sure. Works for me. Maybe something was formatted differently while copying. Anyways here is wf example:
2020_02_26_Quotes_In_String_Manipulation.knwf (11.0 KB)

Br,
Ivan

@ipazin

So weird but this one worked and transferred to mine. Thanks for all the help

1 Like

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