Calling another endpoint from a custom script


#1

Hi,

I’ve been trying to call another endpoint in DF 2.6 through a custom V8js script and I just can’t!

I’ve followed @drewpearce article on https://dzone.com/articles/database-table-endpoint-obfuscation-through-custom but it just doesn’t work. The roles are all set up with proper script access. Also the call is being made with an authenticated and authorized user.

the code that I currently have is :

var id = platform.session.user.id;

var api_path = ‘/padb/_proc/list_user_messages’;
var options = {};
options.parameters = event.request.parameters;
options.parameters.in_id = id;
options.headers = event.request.headers;
var result;
result = platform.api.get(api_path, null, options);

var_dump(result);

also I tried with

result = platform.api.get(api_path, options);

but still doesn’t work.

the logs don’t show anything apart from “NULL” for the result dump.

If I call the list_user_messages directly it works but not through the proxy endpoint.

Any ideas or suggestions?

Thanks,
George


#2

Hi, to call a proc with parameters, you need a POST request, and you need use options.parms instead options.parameters

{
  "params": [
    {
      "name": "string",
      "value": "string"
    },
    {
      "name": "string",
      "value": "string"
    }
  ],
  "schema": {
    "_field_name_": "string"
  },
  "wrapper": "string",
  "returns": "string"
}

http://wiki.dreamfactory.com/DreamFactory/Features/Database/SQL/Stored_Procedures_And_Functions#Calling_a_Stored_Procedure_or_Function (see Using POST section)