Page 1 of 2

Using dynamic request parameters for server code requests

Posted: Wed Jul 10, 2013 11:48 pm
by samwiltshire

Hi there,

I am trying to use the new server code function and have found the help quite useful, however, I notice that in order to to pass on parameters to the server side code it is done via query strings, which is fine, except for when you need to send something which is dynamic.

For example, I have the following POST url working if I hard code the parameters in:

https://api.appery.io/rest/1/code/XXX...

However, I cant seem to see any syntax for making the 'id' (or any parameter for that matter) dynamic, i.e. https://api.appery.io/rest/1/code/XXX... etc?

Further, how would I do the above but sourcing the parameter from localStorage?

FYI, I am only beginning at JS & databases etc so please include basics if you feel necessary.

Thanks!


Using dynamic request parameters for server code requests

Posted: Wed Jul 10, 2013 11:50 pm
by maxkatz

Using dynamic request parameters for server code requests

Posted: Thu Jul 11, 2013 9:56 am
by samwiltshire

Thanks for that - it helped! However, I think I still stuck albeit a bit further along. At present I have set up the request as per the instructions, and when I go to test it doesnt seem to accept the parameters.

Here is a screenshot from the test tab:

Image

FYI, I have the following settings:
method - post
data type - json
settings - none
security context - none
content type - json
appery io proxy - false

What am I doing wrong?


Using dynamic request parameters for server code requests

Posted: Thu Jul 11, 2013 1:16 pm
by Kateryna Grynko

Hi,

You run custom code on server and pass there parameters. Do you process them in your server code?


Using dynamic request parameters for server code requests

Posted: Thu Jul 11, 2013 3:30 pm
by samwiltshire

Hi

I will be running some custom code on the server, however, at this point I am just trying to get the server code working. Once I can get it working then yes, I will be using the parameters for processing.


Using dynamic request parameters for server code requests

Posted: Thu Jul 11, 2013 5:22 pm
by Maryna Brodina

Hello! There are two ways to pass parameters in script - in address line (URL) and request body. To pass parameters through URL you need to change URL. For example codehttps://api.appery.io/rest/1/code/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/exec?DB_id={dbid}&collection={c}&id={id}/code
where dbid, c, id - parameter names on Request tab.

If you won't add anything in URL codehttps://api.appery.io/rest/1/code/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/exec/code and set parameters on request tab then they pass in request body. Try to experiment with standard server code, don't change it:
codevar responseBody = {},
requestParams = {},
paramKeys = request.keys();
for (var key = 0; key < paramKeys&#46;length; key++) {
requestParams[paramKeys[key]] = request&#46;get(paramKeys[key]);
}
responseBody&#46;requestBody = request&#46;body();
responseBody&#46;requestParams = requestParams;
console&#46;log(responseBody);
response&#46;success(responseBody, "application&#47;json");/code
try to change URL address, set a few parameters on request tab to see what parameters and how are being passed.


Using dynamic request parameters for server code requests

Posted: Sun Jul 14, 2013 11:13 am
by samwiltshire

Hey there

Thanks for your help with this - I have the service working in the test environment, however, I cant seem to invoke the service at all.

Is there a chance that you could take a look at it? I think I already have it shared with a href="mailto:support@tiggzi.com" rel="nofollow"support@tiggzi.com/a. The service is called filterService.

Thanks in advance!

Sam


Using dynamic request parameters for server code requests

Posted: Sun Jul 14, 2013 11:19 am
by Igor

Hello,

How do you invoke the service? Do you have any errors on browser console?


Using dynamic request parameters for server code requests

Posted: Sun Jul 14, 2013 11:21 am
by samwiltshire

Hi Igor

There are no console errors - I have been looking for them but nothing. I am invoking the service on load of the liveDashboard page.


Using dynamic request parameters for server code requests

Posted: Sun Jul 14, 2013 11:27 am
by Igor

Please share app with a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a and tell us the app name.