on ‎2020 Dec 09 10:40 AM
Dear all,
I am experimenting in the Kyma environment and I would like to access an external OData-service (in this case one that is anchored in our C4C) in a Node.js-function. I can see and use the credentials saved in the environment variables, however, I am uncertain which JavaScript-function can be used in this environment to access the external source.
So far, my function looks like this. Upon contacting the API-Endpoint directing to this function, I receive my username of the C4C (as saved in the environment variables) and the unique entity-id as served by the C4C after firing the Event Notification.
module.exports = {
main: function (event, context) {
// access to environment variables
var oCredentials = JSON.parse(process.env.CONFIGURATION);
var sUser = oCredentials.credentials.username;
// make the incoming JSON readable by Node.js and select the Unique-ID (Entity-ID)
var sEventData = event.data.replace(/-/g, '');
var oEventNotification = JSON.parse(sEventData);
var sEntityId = oEventNotification.data.entityid;
return sUser + " " + sEntityId;
}
}
If I simulate this code by sending a payload via Postman, I see, that I get the values I selected. My next step would be fetching the corresponding data with this entity-id from the OData Service. Is this possible in this manner?

Also, as you can see, my C4C is already recognized by the Kyma-environment:

All the best
Lucas Millbrodt
Request clarification before answering.
Hi Lucas,
When you are sending the post most sure you include the cookies received in the response for obtaining the x-csrf-token.
Regards,
Jamie
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try setting the headers with
headers: {
"x-csrf-token": resp.headers['x-csrf-token'],
"Cookie": resp.headers["set-cookie"].join(";")
},
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.