cancel
Showing results for 
Search instead for 
Did you mean: 

CAP: calling an action in a remote service not going through

Okassah
Explorer
0 Kudos
216

I'm consuming a remote service that has entity sets and multiple actions. I am able to query a projection on that service and get a list of entities. But once I try to use an action that creates a new entity, the backend code is never called.  I followed this tutorial to invoke the action.

await srv.send('create_entity',dataObject)

When that didn't work, I thought maybe the 'send' function wasn't properly being used, so I added the method like in this code snippet. 

bupa.send({
  method: 'POST',
  path: create_entity,
  data: dataObject
})

This time I got an error telling me that the csrf token was missing. I followed this tutorial to add csrf handling, but the error remained.   

"cds": {
    "requires": {
        "REMOTE_SERVICE": {
            "kind": "odata",
            "model": "srv/external/REMOTE_SERVICE",
            "csrf": true,
            "csrfInBatch": true
        }
    }
}

Is there a problem with the remote service that I'm consuming? Is there a sample project that consumes a remote service action?

Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Okassah
Explorer
0 Kudos
await srv.send("POST",'/Entity/SAP__self.create_entity',dataObject, {});

Answers (1)

Answers (1)

Willem_Pardaens
Product and Topic Expert
Product and Topic Expert
0 Kudos

It's difficult to assess based on the snippets you shared, but I see you are 'sending' the command to srv and to bupa. Make sure to define and connect to the remote source first (e.g. const bupa = await  cds.connect.to("REMOTE_SERVICE"); ). This tutorial should guide you through it end-to-end: https://developers.sap.com/tutorials/btp-app-ext-service-add-consumption..html 

Okassah
Explorer
0 Kudos
The connection is actually correctly established, and I can run a request like this for example:
Okassah
Explorer
0 Kudos
this.on('READ', 'entities', async req => { return srv.run(req.query); });