How to construct single string from Multiple Comma Separated header to create updates URL in UpdateURL Javascript

Not applicable

Apologies if this is very basic question/doubt - i just started with Apigee and faced below issue.

I am trying to create LinkedIn profile search proxy and passed fields separated by comma in header "profileparams".

Take an example as

profileparams=id,first-name,last-name,num-connections,picture-url

I need to create the url in below format using javascript:

	https://api.linkedin.com/v1/people/~:(id,first-name,last-name,num-connections,picture-url)?format=js...

For this i coded below in proxy:

if (context.getVariable("proxy.pathsuffix") == "/people/extended/search") {
       var dataFields = context.getVariable("request.header.profileparams"); 
	context.setVariable("serviceURL", "/people/~:(" + dataFields.toString() + ")?" + queryParam);
}

When i am sending request it is only picking up first field of header i.e. "id" and ignoring rest all.

I tried splitting based on comma and recreate new string but it is always ignoring any operation after first field of the header.

Any snippet or hint will be helpful. Thanks in advance.

1 1 595
1 REPLY 1

Hi, please see this article for more information.

I think you probably want something like this:

if (context.getVariable("proxy.pathsuffix") == "/people/extended/search") {
  var hdr = context.getVariable("request.header.profileparams.values") + '';
  var dataFields = hdr.substring(1, hdr.length-1).split(',');
  context.setVariable("serviceURL", "/people/~:(" + dataFields.toString() + ")?" + queryParam);
  // OR...
  // context.setVariable("serviceURL", "/people/~:(" + hdr.substring(1, hdr.length-1) + ")?" + queryParam);
}