Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch API for Business Partner #5433

Open
hoandreas opened this issue Feb 3, 2025 · 3 comments
Open

Patch API for Business Partner #5433

hoandreas opened this issue Feb 3, 2025 · 3 comments
Labels
question Further information is requested

Comments

@hoandreas
Copy link

hoandreas commented Feb 3, 2025

Describe the Question

Hello,

So I followed the installation and generation steps in this documentation:
https://api.sap.com/api/API_BUSINESS_PARTNER/cloud-sdk/JavaScript

And I have imported the client to consume the service via the generated typed client library.
The get request was successful, but when I try to use the update function, I always get the .getCustomFields is not a function error message. And if I also include the date fields, it will throw momentInstance.unix is not a function error.

I followed this documentation for the update implementation.
My code looks like this:

const {
  opApiBusinessPartnerSrv,
} = require("./generated/business-partner/OP_API_BUSINESS_PARTNER_SRV/service");
const { businessPartnerApi } = opApiBusinessPartnerSrv();

// and this is how the update function being called
      const updateResult = await businessPartnerApi
          .requestBuilder()
          .update(payload);

I tried building the entity first before sending the payload like this:

      const payload = await businessPartnerApi
          .entityBuilder()
          .fromJson(sanitizedPayload);

But the generated payload is an empty object.
The original payload before being built is obtained from the fiori app via req.data.
Am I missing some steps or how do I use this update function?

Thanks guys.

@hoandreas hoandreas added the question Further information is requested label Feb 3, 2025
@tomfrenken
Copy link
Member

Conceptually you make the right calls, but it is hard to determine the core of your issue with the information you provided.

Can you share:

  • Your node version
  • SAP Cloud SDK version
  • Any of the actual payload's contents

@tomfrenken
Copy link
Member

tomfrenken commented Feb 3, 2025

Alternatively, you can try creating the entity on your own instead of passing a payload and see if you still receive errors, this would point at an erroneous payload.

import { apiBusinessPartner } from "./generated/API_BUSINESS_PARTNER/service"
const { businessPartnerApi } = apiBusinessPartner()
const payload = businessPartnerApi.entityBuilder().build();
const updateResult = await businessPartnerApi
    .requestBuilder()
    .update(payload)
    .execute({ destinationName: "MyDestination" });

@hoandreas
Copy link
Author

hoandreas commented Feb 4, 2025

hello @tomfrenken, thank you for your reply.
My Node version is v20.18.0
and these are the SAP cloud SDK that I use

dependencies:
    "@cap-js-community/odata-v2-adapter": "^1.13.7",
    "@sap-cloud-sdk/core": "^1.54.2",
    "@sap-cloud-sdk/http-client": "^3.22.2",
    "@sap-cloud-sdk/odata-v2": "^3.24.0",
    "@sap-cloud-sdk/odata-v4": "^3.22.2",
    "@sap-cloud-sdk/openapi": "^3.25.0",
    "@sap-cloud-sdk/openapi-generator": "^3.25.0",
    "@sap-cloud-sdk/resilience": "^3.22.2",

devDependencies:
    "@sap-cloud-sdk/generator": "^3.24.0",

And here's the example payload that I send:

{
  __metadata: {
    id: "http://baseUrl.local:4004/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('28')",
    uri: "http://baseUrl.local:4004/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('28')",
    type: 'API_BUSINESS_PARTNER.A_BusinessPartnerType'
  },
  BusinessPartner: '28',
  Customer: '123123qwe',
  Supplier: '28',
  AcademicTitle: '123123qwe',
  AuthorizationGroup: '',
  BusinessPartnerCategory: '1',
  BusinessPartnerFullName: ' T Test pzo Kred.1 Kreditor 1',
  BusinessPartnerGrouping: '0001',
  BusinessPartnerName: ' T Test pzo Kred.1 Kreditor 1',
  BusinessPartnerUUID: 'a3f8e2c1-4b76-4e5d-9c2d-1f8e4a5b6c7d',
  CorrespondenceLanguage: 'DE',
  CreatedByUser: 'SAMPLE_USR',
  CreationDate: '2023-05-09T00:00:00.000Z',
  CreationTime: null,
  FirstName: '',
  FormOfAddress: '0001',
  Industry: '',
  InternationalLocationNumber1: '0',
  InternationalLocationNumber2: '0',
  IsFemale: true,
  IsMale: false,
  IsNaturalPerson: '',
  IsSexUnknown: false,
  Language: '',
  LastChangeDate: '2023-05-10T00:00:00.000Z',
  LastChangeTime: null,
  LastChangedByUser: 'SAMPLE_USR',
  LastName: 'T Test pzo Kred.1 Kreditor 1',
  LegalForm: '',
  OrganizationBPName1: '',
  OrganizationBPName2: '',
  OrganizationBPName3: '',
  OrganizationBPName4: '',
  OrganizationFoundationDate: null,
  OrganizationLiquidationDate: null,
  SearchTerm1: 'PZO',
  AdditionalLastName: '',
  BirthDate: null,
  BusinessPartnerIsBlocked: false,
  BusinessPartnerType: '',
  ETag: 'SAMPLE_USR20250111111111',
  GroupBusinessPartnerName1: '',
  GroupBusinessPartnerName2: '',
  IndependentAddressID: '',
  InternationalLocationNumber3: '0',
  MiddleName: '',
  NameCountry: '',
  NameFormat: '',
  PersonFullName: '',
  PersonNumber: '23710',
  IsMarkedForArchiving: false,
  BusinessPartnerIDByExtSystem: '',
  TradingPartner: '',
  to_BuPaIdentification: {
    __deferred: {
      uri: "http://baseUrl.local:4004/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('28')/to_BuPaIdentification"
    }
  },
  to_BuPaIndustry: {
    __deferred: {
      uri: "http://baseUrl.local:4004/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('28')/to_BuPaIndustry"
    }
  },
  to_BusinessPartnerAddress: {
    __deferred: {
      uri: "http://baseUrl.local:4004/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('28')/to_BusinessPartnerAddress"
    }
  },
  to_BusinessPartnerBank: {
    __deferred: {
      uri: "http://baseUrl.local:4004/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('28')/to_BusinessPartnerBank"
    }
  },
  to_BusinessPartnerContact: {
    __deferred: {
      uri: "http://baseUrl.local:4004/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('28')/to_BusinessPartnerContact"
    }
  },
  to_BusinessPartnerRole: {
    __deferred: {
      uri: "http://baseUrl.local:4004/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('28')/to_BusinessPartnerRole"
    }
  },
  to_BusinessPartnerTax: {
    __deferred: {
      uri: "http://baseUrl.local:4004/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('28')/to_BusinessPartnerTax"
    }
  },
  to_Customer: {
    __deferred: {
      uri: "http://baseUrl.local:4004/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('28')/to_Customer"
    }
  },
  to_Supplier: {
    __deferred: {
      uri: "http://baseUrl.local:4004/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner('28')/to_Supplier"
    }
  }
}

Alternatively, you can try creating the entity on your own instead of passing a payload and see if you still receive errors, this would point at an erroneous payload.

But if I create the entity that way, how do I pass the payload that contains the updated data to hit the patch API?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants