Getting API Key and passing it as a _proc/procname(parameter) value


#1

I need to take an api key used to submit a call via: /api/v2/_proc/procname?api_key=xx00xx00

and append it to the api call as a parameter so that the full API call would be:

/api/v2/_proc/procname(xx00xx00)?api_key=xx00xx00

I don’t want my customers to have to add the api_key value as the (parameter) value as well as the api_key value when calling this stored process.

I’m guessing it’s a pre-process script that will call platform.session.api_key somehow but I’m lost as to how to accomplish this.


#2

You’re right, you want to access the value through platform.session.api_key. You could then use a pre-process script to add this value to your procedure parameters. There are a number of different ways to provide parameters to your procedure call ( http://wiki.dreamfactory.com/DreamFactory/Features/Database/SQL/Stored_Procedures_And_Functions#Calling_a_Stored_Procedure_or_Function ) so the specifics of the script will change depending on which method you use.
For the sake of example, let’s say you’re using the second example under POST.

{
    "params": {
        "<param_name>": "<param_value>",
        "<param_name>": "<param_value>",
        "<param_name>": "<param_value>"
    }
}

And, let’s say that the name of the parameter you want to add the api key value to is my_api_key.

You could do a v8js script that looks like this:

    event.request.payload.params.my_api_key = platform.session.api_key;