0

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.

1 Answer 1

0

As I see you have already saved the necessary data in the variables. So did you try a query like below in invoke policy?

https://dev.blah.com:port/enterprise/dev/agencies/agency/books/book/agents/$(agentId)/contact-information?requestId=$(requestId)&channelId=$(channelId)&channelName=$(channelName)

Also you don't need to use this files:

var sm   = require('service-metadata.js');
var hm   = require('header-metadata.js');
var apim = require('./apim.custom.js'); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.