cancel
Showing results for 
Search instead for 
Did you mean: 

$expand not working while using External API in CAP

nkaur1311
Explorer

Hello Experts,

I am working on CAP based programming model wherein I have consumed external API, API_BUSINESS_PARTNER, and fetching the data from an entity A_BusinessPartner. As below:

 @readonly
    entity BusinessPartners         as projection on external.A_BusinessPartner {
        BusinessPartner, LastName, FirstName, Customer, to_BusinessPartnerAddress
    };
    @readonly
    entity BusinessPartnerAddresses as projection on external.A_BusinessPartnerAddress {
        BusinessPartner, AddressID, Country
    }

However, When I am using $expand to get business Partner Address information, I am not getting any columns for that and the query returns as:

https://workspaces-ws-xxxxxx-app1.eu10.trial.applicationstudio.cloud.sap/address-manager/BusinessPar...

Additionally, Referring to https://github.com/sapmentors/cap-community/issues/61 , I have modified API_BUSINESS_PARTNER.csn file as

"to_BusinessPartnerAddress": {
          "type": "cds.Association",
          "target": "API_BUSINESS_PARTNER.A_BusinessPartnerAddress",
          "on": [{
              "ref": [
                "BusinessPartner"
              ]
            },
            "=",
            {
              "ref": [
                "$self"
              ]
            }
          ],
          "cardinality": {
            "max": "*"
          }
        }

Below is the custom handler for the same

this.on('READ', BusinessPartners, async (req) => {
        try {
            const tx = service.transaction();
                return await tx.send({
                    query:req.query,
                    headers: {
                    "APIKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                }                
            })      
        } catch (err) {
            req.reject(err);
        }
    });

Am I missing something? If anyone has any pointers or faced any such issue, please provide your assistance/feedback on the same.

Regards,

Navneet Kaur

francoishardy
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello,

Did someone fixed the issue ? Facing the same

Best regards,

François

Accepted Solutions (0)

Answers (0)