Template literals

Hi all,

I’m trying to use a template literal to create a multiline string in a Realm function and getting the following error:
http request: “url” argument must be a string

The string is as follows

var url = https://accounts.yyy.com/oauth/v2/token? refresh_token=1000.nnnnnnnnnnaa& client_id=1000.X9T5WJYBKL1ZFQOEGHU3BU3X473A3H& client_secret=2bbdd11& redirect_uri=https://google.com/& grant_type=refresh_token

I am using this URL when posting to an enpoint.
I get http request: “url” argument must be a string

If I create a single line string (no back ticks), I don’t get this error.

The documentation states Realm supports template literals.

Any ideas?

Thanks,
Herb

Hi @Herb_Ramos,

Looks like this is working fine for me:

exports = function(){
  var url = `https://accounts.yyy.com/oauth/v2/token?refresh_token=1000.nnnnnnnnnnaa&
  client_id=1000.X9T5WJYBKL1ZFQOEGHU3BU3X473A3H&
  client_secret=2bbdd11&
  redirect_uri=https://google.com/&
  grant_type=refresh_token`;
  
  console.log(url);
  return true;
};

Result:

> ran on Tue Apr 13 2021 19:31:49 GMT+0200 (Central European Summer Time)
> took 362.474208ms
> logs: 
https://accounts.yyy.com/oauth/v2/token?refresh_token=1000.nnnnnnnnnnaa&
  client_id=1000.X9T5WJYBKL1ZFQOEGHU3BU3X473A3H&
  client_secret=2bbdd11&
  redirect_uri=https://google.com/&
  grant_type=refresh_token
> result: 
true
> result (JavaScript): 
EJSON.parse('true')

Else there is still the good old concatenation trick.

exports = function(){
  var url = "https://accounts.yyy.com/oauth/v2/token?refresh_token=1000.nnnnnnnnnnaa&" 
          + "client_id=1000.X9T5WJYBKL1ZFQOEGHU3BU3X473A3H&"
          + "client_secret=2bbdd11&"
          + "redirect_uri=https://google.com/&"
          + "grant_type=refresh_token";
  
  console.log(url);
  return true;
};

Not that I get a different result though…

> ran on Tue Apr 13 2021 19:34:48 GMT+0200 (Central European Summer Time)
> took 268.881812ms
> logs: 
https://accounts.yyy.com/oauth/v2/token?refresh_token=1000.nnnnnnnnnnaa&client_id=1000.X9T5WJYBKL1ZFQOEGHU3BU3X473A3H&client_secret=2bbdd11&redirect_uri=https://google.com/&grant_type=refresh_token
> result: 
true
> result (JavaScript): 
EJSON.parse('true')

Cheers,
Maxime.