Is that possible to alter the request resource & parameters in pre-processing script?


Hi all DF gurus,

I’m trying to alter the request resource & parameters in a PATCH request but seems out of luck. Please take a look at my code below:

if (event.request.payload.fieldb) {
var filter = “(a = '” + event.resource + “’) AND (b = " + event.request.payload.fieldb + “)”;
filter = encodeURIComponent(filter);
platform.api.get(”/url/_table/mytable?fields=id&filter=" + filter, ‘’, function(body, res) {
var json = JSON.parse(body);
var newid = json.resource[0].id;
event.resource = newid;
event.request.parameters = {};
console.log(“request altered”);
throw new Error(“dev - debug breakpoint”);

Client fire a PATCH request to “/url/_table/mytable?id_field=fieldc”. In ideal world, if fieldb exists in the request.payload, the script should fire a GET request and overwrite the event.resource, and then remove the parameters (id_field=fieldc), therefore the console.log at the bottom should show the altered resource & payload, but then, this script seems running in asynchronous mode, the 2x console.log at the bottom show first and only then console.log(“event altered”) show.

I’m wondering is there any asynchronous/sync switch that I can use in this case? or there is a more proper way to achieve this?

Thanks in advance.


were you able to figure out how to update request on pre process ?
I am also looking for same solution where I want to update request from images/20.jpg to images/unauthorized.png


Calling api from script

ok may be we could just redirect.
do you know how to redirect the request ?