Problems getting Oauth token for sharepoint online using POST request node

I’m trying to get an authorization token for sharepoint online using POST request node. I read all similar topics but they didn’t help me.

The problem is that knime somehow is unable to send correct data in the POST request body and i get the error - Execute failed: Wrong status: 400 Bad Request

The same request is working fine in Postman and even in knime using python script.
I added images of the Post request setup (i made the user codes on the body tab unsusable, i hope the structure is enough:

And in knime log there is only this:
2020-05-27 08:12:38,632 : ERROR : KNIME-Worker-21-POST Request 0:296 : : Node : POST Request : 0:296 : Execute failed: Wrong status: 400 Bad Request
java.lang.IllegalStateException: Wrong status: 400 Bad Request
at org.knime.core.node.NodeModel.execute(
at org.knime.core.node.NodeModel.executeModel(
at org.knime.core.node.Node.invokeFullyNodeModelExecute(
at org.knime.core.node.Node.execute(
at org.knime.core.node.workflow.NativeNodeContainer.performExecuteNode(
at org.knime.core.node.exec.LocalNodeExecutionJob.mainExecute(
at org.knime.core.node.workflow.NodeExecutionJob.internalRun(
at org.knime.core.util.ThreadUtils$RunnableWithContextImpl.runWithContext(
at org.knime.core.util.ThreadUtils$
at java.util.concurrent.Executors$
at org.knime.core.util.ThreadPool$
at org.knime.core.util.ThreadPool$

The problem is that i don’t understand why it fails. Are there some symbols that are not recognized by java? the authorization codes contain both “=” and “/” as part of them. Do i have to escape them somehow?
I also read that i might use java snippet node to make the api call but that requires me to search the web for examples.

1 Like

this looks like a application/x-www-form-urlencoded body. Did you set the Content-Type header accordingly? Additionally, the each value of the key-value pairs separated by “&” must be encoded, e.g. the forward slash becomes “%2F”. For this you can use the Column Expressions node with the encodeURIComponent function. If you want to pass in the whole body, you can use something like this:

.map(function(kv) {
    var s = kv.split("=");
    return s[0] + "=" + encodeURIComponent(s[1]);

Be aware that the key-value pairs must not contain ampersands or equal signs themselves.
Kind regards,

1 Like

Hi thanks for the advice and the new node. Sadly this does not help, i still get the 400 bad request error.
I do have the correct header - see a few images above - i posted all configuration.

maybe that is not the cause, since you say that in Python and Postman the same request works, but in this description they write that the client_id in the body should look like CLIENT_ID@TENANT_ID. In your request the tenant id is not included here. Could that be it? Can you also post the encoded body?
Kind regards,

As i said - i corrupted it so others cant use it. The format is right since it works in 2 other cases. ’
I was asking for possible bug. Maybe the internal Java code somehow can’t create a correct request.

My idea was that maybe Python and Postman automatically encode the string correctly, while in Java you have to do it manually before setting the body. Does the same problem occur with different endpoints, or just the one?
Kind regards

Hello @jcielens
I have the same issue. Did you ever resolve it?

Here’s a solution: Read Sharepoint Lists - #16 by AnotherFraudUser