Hi,
I am writing an SAP CAP application on NodeJS that requests data from MS Graph.
I have defined a destination in SAP BTP (name: "Graph").
I have created a js service file with the following method to read a particular user's data (user id: "ABCDE"):
const readFunction = async (req) => {
let destination = 'Graph'
const url = `/users/?$search="onPremisesSamAccountName:ABCDE"`
console.log('In function readFunction..');
console.log('Trying to get to destination..');
const service = await cdsapi.connect.to(destination);
console.log('Connected to destination..');
const graphUser = await service.run({
url: url,
headers: { "ConsistencyLevel": "Eventual"}
})
console.log('Got user data..');
let users = graphUser.value.map(graph_user => {
var user = {}
user.aad_id = graph_user.id
user.username = graph_user.userPrincipalName
user.displayName = graph_user.displayName
user.givenName = graph_user.givenName
user.surname = graph_user.surname
user.isAzureActiveDirectory = true
return user
})
return users
}
module.exports = (srv) => {
srv.on('READ', 'User', readFunction)
}
But when I call this service, I get the following error in the console:
error: {
code: 'Request_UnsupportedQuery',
message: "Request with $search query parameter only works through MSGraph with a special request header: 'ConsistencyLevel: eventual'", (...)
As you can see, I have provided the ConsistencyLevel parameter on the request header, but it does not work.
I do not see it in the request header in the Chrome dev tools.
I have also added the property URL.headers.ConsistencyLevel to destination properties in SAP BTP, but it does not work either.
My questions are:
How can I correctly pass the $search parameter to the destination?
How can I set the request header values in SAP CAP on NodeJS?
When I take the $search parameter out from the path (url = `/users`),
the request works and delivers me all the users from MS Graph.