Hi I’m new to the Tyk world apologies if my questions are very newbie.
I have an api with a virtual endpoint plugin using inline js. What is supposed to happen on my code is to call ABC’s custom endpoint to request for a new token. Do take note that I have tested the ABCEndpoint in postman and it works totally fine. Now I wanted to call the endpoint using the api virtual endpoint of tyk.io.
First I have tested using this inlinejs to see if it really returns the “hello world” and yes it works totally fine.
function myUniqueFunctionName(request, session, config) {
var responseObject = {
Body: "Hello World",
Code: 200
}
return TykJsResponse(responseObject, session.meta_data)
}
Now here is the code that I have implemented that returns this “Error during virtual endpoint execution…”. I have omitted the urlABCEndpoint, client_id and client_secret for security purposes.
function myVirtualEndpoint(request, session, config) {
var urlABCEndpoint = "https://thedummyurl.com/v2/token";
var payload = {
grant_type: "client_credentials",
client_id: "clientidvalue",
client_secret: "clientsecretkey",
account_id: "534004151"
};
var headers = {
"Content-Type": "application/json"
};
var options = {
method: "POST",
body: JSON.stringify(payload),
headers: headers
};
var responseObject = {
Body: "success",
Code: 200
}
var responseErrorObject = {
Body: "error",
Code: 500
}
return TykMakeHttpRequest(urlABCEndpoint, options)
.then(function(response) {
//return response;
return TykJsResponse(responseObject, session.meta_data)
})
.catch(function(error) {
//return error;
return TykJsResponse(responseErrorObject, session.meta_data);
});
}
Error on the postman.
In my core settings I have only selected “Authentication Token” as the Authentication mode and that’s just it.
Hopefully anyone can advise me if there’s anything wrong in my code or any extra configuration I need to do. Thank you very much in advance!