Missing PATCH request for REST

I’m using KNIME in combination with MS PowerBI and trying to publish reports from KNIME using the PowerBI REST API. Unfortunately the PATCH request is not available as a node (unlike the more regular GET, POST, PUT and DELETE). In order to update e.g. a data source for the report PowerBI uses PATCH, and I did not find a way around it with other commands.

Also tried falling back to the Java node and use an HTTPConnection, but I run into the same issue: request type is not supported.

Does anyone have suggestions how to proceed?
(any change the PATCH request node will be added to the REST-set?)

Found a work-around in Java’s HTTPURLConnection… using reflection classes to change final fields at runtime :frowning:

HttpURLConnection http = (HttpURLConnection) url.openConnection();
//http.setRequestMethod(“PATCH”);

final Object target;
if (http instanceof HttpsURLConnectionImpl) {
	final Field delegate = HttpsURLConnectionImpl.class.getDeclaredField("delegate");
	delegate.setAccessible(true);
	target = delegate.get(http);
} else {
	target = http;
}
final Field f = HttpURLConnection.class.getDeclaredField("method");
f.setAccessible(true);
f.set(target, "PATCH");
1 Like

Thanks for sharing your workaround. I think a PATCH Request node would be a good extension for our REST Web Services, therefore I’ve opened a feature request for a dedicated PATCH Request node.

Yes please, we need a PATCH request with a triple store running datalog rules that does not accept any other way to delete the rules.

Do you have a timeline for creating a PATCH node?

David

we have a similar problem, would it be possible to share the workaround as a workflow? not sure how to get the java approach to work.

Best

David

I found a workaround by writing a custom REST PATCH API call using Okhttp ->
https://square.github.io/okhttp/.

JAR file download -> https://jar-download.com/artifacts/com.squareup.okhttp3/okhttp/4.2.1/source-code

The actual code from my java snippet, feel free to make changes as needed

// imports for input and output fields
import javax.json.JsonValue;

// Your custom imports:
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.MediaType;
import java.io.IOException;
// system variables
public class JSnippet extends AbstractJSnippet {
// Fields for input columns
/** Input column: “json_body” /
public JsonValue c_json_body;
/
* Input column: “patch_url” /
public String c_patch_url;
// Fields for input flow variables
/
* Input flow variable: “auth header” */
public String v_authheader;

// Fields for output columns
/** Output column: “okHeader” /
public String[] out_okHeader;
/
* Output column: “okResponse” /
public String out_okResponse;
/
* Output column: “out_okError” /
public String out_okError;
/
* Output column: “okMessage” */
public String out_okMessage;

// Your custom variables:

// expression start

// Enter your code here:
OkHttpClient httpClient = new OkHttpClient();
String json = c_json_body.toString();
MediaType JSON = MediaType.parse(“application/json; charset=utf-8”);

RequestBody body = RequestBody.create(json, JSON);

Request request = new Request.Builder()
.url(c_patch_url)
.addHeader(“Authorization”, v_authheader) // add request headers
.addHeader(“Content-Type”, “application/json”)
.patch(body)
.build();

try (Response response = httpClient.newCall(request).execute()) {

if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);




// Get response headers
Headers responseHeaders = response.headers();
out_okHeader = new String[responseHeaders.size()];
for (int i = 0; i < responseHeaders.size(); i++) {
 out_okHeader[i] = responseHeaders.name(i) + ": " + responseHeaders.value(i);
}

// Get response body

out_okResponse = response.body().string();

out_okMessage = response.message();
out_okError = "None";

} catch (IOException e) {
out_okError = e.getMessage();
}

1 Like

Hello,

Has there been any movement on the creation of an actual PATCH node? I would like to avoid creating any special logic. Thank you. @Marten_Pfannenschmidt

1 Like