How to change http header on server side platform.api.get method

I am writing a post process event script using the Dreamfactory ‘Scripts’ interface and would like to get additional data using the platform.api object.

Due to the potentially long number of IDs in my filter, I am attempting to get the data by POST. The only part I can’t figure out is how to set the X-HTTP-METHOD header to GET. I’ve come up with the following code based on the wiki: https://github.com/dreamfactorysoftware/dsp-core/wiki/API-Access-via-Scripts

if (event.response.record) {
   var options = {
      "CURLOPT_HTTPHEADER": ["Content-type: application/json", "X-HTTP-Method: GET"]
   };

   result = platform.api.post(
      "db/example_table", 
      {"filter": "id IN (321,322,323)"},
      options
   );

   var_dump(result); // No valid fields were found in record.
}

But I get “No valid fields were found in record.” Everything works if I use platform.api.get instead of POST.

Any help or guidance is appreciated, thanks!

I’m not sure anyone here has accomplished this yet. But here’s a free bump to see what other folks in the community might come up with! :+1:

@steven: Where you able to find a solution to this? I am having the same issue.

I didn’t have any luck getting this to work.

I originally thought I needed this approach because I ran into an error with the URL being too long when I was passing a really long string of IDs as a URL parameter to the API from my app. Because this is server-side it might not have the same length limitation. I’m not sure how the arguments are passed through, but things have been working fine just using GET.

I figured out. You need to use the full URL like platform.api.post(
http://URL/api/v2/db/example_table”,

Also you need to set the headers (session and app key) again as it is a new api call.

var options = {
“CURLOPT_HTTPHEADER”: [“Content-type: application/json”, “X-HTTP-Method: GET”,"X-Dreamfactory-Api-Key:event.request.headers[“x-dreamfactory-api-key”],“X-DreamFactory-Session-Token:”+event.request.headers[“x-dreamfactory-session-token”]]
};

1 Like

Awesome! Thanks for posting the solution!