Support Topics Documentation Slack YouTube Blog

getting URL parameters in js file


(Tal Seren) #1

Hi,

How can I get the URL parameters when calling a js file saved in web/scripts?

Thanks,
Tal


(Mark Piller) #2

Hi Tal,

Try this:

request.query.PARAMETERNAME

Where PARAMETERNAME is the actual parameter.

Mark


(Tal Seren) #3

this is not working:

var clk = request.query.clk;


var userAcquisitionRedirectsItem = new UserAcquisitionRedirectsItem( { adNetwork : 'archy', appId : 'appId', clickId : clk, country : 'IL', userAdvertisingId : '1234-afjad-test', userIp : '192.168.1.144' });

after this code I see in the table all the values, except for clickId which is empty


(Mark Piller) #4

How do you send the parameter in the URL?


(Tal Seren) #5

https://api.backendless.com/app_id/v1/files/web/scripts/UserAcquisitionRedirect/archyRedirect.js?clk=123


(Mark Piller) #6

Is it a GET or POST request?


(Tal Seren) #7

I’m pasting this url in a browser


(Mark Piller) #8

Well, I just did a simple test and it is working as expected. Here’s a URL to try:

https://api.backendless.com/91186007-E09C-8561-FF0E-ADCD410BF400/v1/files/web/scripts/hello.js?test=foo

Here’s the source code of the script:

exports.run = function ( request, response )
{
    response.send( "value of the test parameter is: " + request.query.test );
};

It seems like the problem would be somewhere in your code.

Regards,
Mark


(Tal Seren) #9

thanks mark, found my error