I have to get the details of an agent from backend server based on agent_id. We are passing few input parameters in headers. i want to get the request ID number in case of error. I have written the gateway script as below:
// Define modules
var sm = require('service-metadata.js');
var hm = require('header-metadata.js');
var apim = require('./apim.custom.js');
var LegacyAgentNumber = apim.getvariable('request.parameters.LegacyAgentNumber');
var requestId = apim.getvariable('request.parameters.requestId');
var channelId = apim.getvariable('request.parameters.channelId');
var channelName = apim.getvariable('request.parameters.channelName');
var sm_user = apim.getvariable('request.parameters.sm_user');
// To send as query parameters
var queryString = '$filter=contains(LegacyAgentNumber,%27'+legacyAgentNumber+'%27)';
apim.setvariable('queryString', queryString);
apim.setvariable('requestId', requestId);
apim.setvariable('channelId', channelId);
apim.setvariable('channelName', channelName);
apim.setvariable('sm_user', sm_user);
var contentType = apim.getvariable('request.headers.content-type');
apim.setvariable(sm_user, contentType, 'set');
if (error) {
{
//here I want to print the requestID from headers as values in errorId and refidRequest fields.
"errorId": "{requestId}Err",
"refidRequest": "{requestId}",
"httpCode": "400",
"httpMessage": "Bad Request",
"moreInformation": "Invalid Input Parameters"
}
else {
// read response data
// get the response status code
var vid = apim.getvariable ('request.parameters.id');
var vapiversion = apim.getvariable('api.version');
var vapiname = apim.getvariable('api.name');
var sresponse= {"AgentMailingAddressKeepAliveResponse": {"responseHeader": {
"id": vid +"_rs",
"refidRequest": vid,
"cmdType": "response",
"cmdStatus": "Success",
"message": "keepAlive response message "+vapiname+":"+vapiversion
}}}
apim.setvariable('message.body',response);
apim.setvariable('message.headers.content-type','application/json');
apim.setvariable('message.status.code',200);
Here is the URI : https://dev.blah.com:port/enterprise/dev/agencies/agency/books/book/agents/{agent_id}/contact-information?requestId=_123&channelId=OL&channelName=OL
How do i write the query string for this and achieve to get the details from the target.