Skip to Content
0
Dec 28, 2021 at 07:11 PM

Error 400 while trying to consume data in CAP from external authorized OData service

1578 Views Last edit Dec 28, 2021 at 07:22 PM 2 rev

Hello Experts,

I am trying to consume an external SAP IBP OData service which has credentials as well. I followed this awesome blog from Jhodel Cailan But in my case my service have credentials as well.

In my OData service, there are many entities and I want only some fields from the BTPROMO entity

Here is my OData metadata

image.png

There are some associations as well but I don't need anything from there

image.png

This is how easily I am able to see data for the required fields from my OData service in JSON format

image.png

Using the blog, I started creating my CAP model to consume this external service but that ends up in giving 400 error

my catalog.cds and catalog.js looks like this

image.png

This is my package.json

image.png

And this is my .cdsrc.json

image.png


when I try to run it, I am getting this error in the console, It is saying that a field Transaction_id is undefined, but I am not even asking for this field in my catalog.cds file, Also this field doesn't exist in the entity set BTPPROMO from which I need the data, This field is only available in the association as I mentioned below in the metadata screenshot

image.png

console main error looks like this

image.png

Full error log is here

user: sap-ibp-promotions $ cds watch
 
cds serve all --with-mocks --in-memory? 
watching: cds,csn,csv,ts,mjs,cjs,js,json,properties,edmx,xml,env,css,gif,html,jpg,png,svg... 
live reload enabled for browsers 
        _______________________
 
[cds] - model loaded from 2 file(s):

  ./srv/catalog-service.cds
  ./srv/external/SapIbp.csn

[cds] - connect using bindings from: { registry: '~/.cds-services.json' }
[cds] - connect to db > sqlite { database: ':memory:' }
[cds] - connect to SapIbp > odata-v2 {
  url: 'https://<Host>:<Port>.ondemand.com/sap/opu/odata/IBP/PLANNING_DATA_API_SRV',
  authentication: '...',
  username: 'BTPUSER',
  password: '...'
}
[cds] - serving CatalogService { at: '/catalog', impl: './srv/catalog-service.js' }

[cds] - server listening on { url: 'http://localhost:4004' }
[cds] - launched at 12/28/2021, 6:57:03 PM, in: 1.666s
[cds] - [ terminate with ^C ]

[cds] - GET /catalog/BTPPROMO
[remote] - Error: Error during request to remote service: Request failed with status code 400
    at createError (/home/user/projects/sap-ibp-promotions/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/home/user/projects/sap-ibp-promotions/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/home/user/projects/sap-ibp-promotions/node_modules/axios/lib/adapters/http.js:269:11)
    at IncomingMessage.emit (events.js:412:35)
    at endReadableNT (internal/streams/readable.js:1317:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  config: {
    url: "/commit?P_TransactionID='undefined'",
    method: 'get',
    proxy: false,
    baseURL: 'https://<Host>:<Port>.ondemand.com/sap/opu/odata/IBP/PLANNING_DATA_API_SRV',
    timeout: 60000,
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    maxBodyLength: -1,
    data: undefined
  },
  request: {
    method: 'GET',
    url: "https://<Host>:<Port>.ondemand.com/sap/opu/odata/IBP/PLANNING_DATA_API_SRV/commit?P_TransactionID='undefined'",
    headers: {
      Accept: 'application/json,text/plain',
      authorization: 'Basic ...',
      'accept-language': 'en',
      'User-Agent': 'axios/0.21.4'
    }
  },
  response: {
    status: 400,
    statusText: 'Bad Request',
    headers: {
      'set-cookie': [
        'sap-usercontext=sap-client=100; path=/',
        'SAP_SESSIONID_BBT_100=lOH6w615_CBUW_uXnXY6-_jctENoDxHsqP36Fj4KKec%3d; path=/; secure; HttpOnly'
      ],
      'content-type': 'application/json;charset=utf-8',
      'content-length': '1067',
      dataserviceversion: '1.0',
      'sap-server': 'true',
      'sap-perf-fesrec': '139953.000000',
      'x-content-type-options': 'nosniff',
      'strict-transport-security': 'max-age=31536000; includeSubDomains',
      'x-xss-protection': '1; mode=block'
    },
    body: {
      error: {
        code: '/IBP/EXTRACT_MSG/064',
        message: {
          lang: 'en',
          value: 'Transaction ID undefined does not exist.'
        },
        innererror: {
          application: {
            component_id: 'SCM-IBP-INT-ODT',
            service_namespace: '/IBP/',
            service_id: 'PLANNING_DATA_API_SRV',
            service_version: '0001'
          },
          transactionid: '3372965542570250E0061CB5B83B2307',
          timestamp: '20211228185715.1964500',
          Error_Resolution: {
            SAP_Transaction: 'For backend administrators: use ADT feed reader "SAP Gateway Error Log" or run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details',
            SAP_Note: 'See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)'
          },
          errordetails: [
            {
              ContentID: '',
              code: '/IBP/CX_PLNG_DATA_DI_API',
              message: 'Transaction ID undefined does not exist.',
              propertyref: '',
              severity: 'error',
              transition: false,
              target: ''
            },
            {
              ContentID: '',
              code: '/IWBEP/CX_MGW_BUSI_EXCEPTION',
              message: 'Transaction ID BATCH_ID does not exist.',
              propertyref: '',
              severity: 'error',
              transition: false,
              target: ''
            }
          ]
        }
      }
    }
  },
  isAxiosError: true,
  correlationId: '913962db-f86f-46ba-a246-69a3139da030'
}
[cds] - Error: Error during request to remote service: Request failed with status code 400
    at run (/home/user/projects/sap-ibp-promotions/node_modules/@sap/cds/libx/_runtime/remote/utils/client.js:248:25)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async RemoteService.<anonymous> (/home/user/projects/sap-ibp-promotions/node_modules/@sap/cds/libx/_runtime/remote/Service.js:179:20)
    at async next (/home/user/projects/sap-ibp-promotions/node_modules/@sap/cds/lib/serve/Service-dispatch.js:74:17)
    at async RemoteService.handle (/home/user/projects/sap-ibp-promotions/node_modules/@sap/cds/lib/serve/Service-dispatch.js:72:10)
    at async next (/home/user/projects/sap-ibp-promotions/node_modules/@sap/cds/lib/serve/Service-dispatch.js:74:17)
    at async RemoteService.handle (/home/user/projects/sap-ibp-promotions/node_modules/@sap/cds/lib/serve/Service-dispatch.js:72:10)
    at async RemoteService.commit (/home/user/projects/sap-ibp-promotions/node_modules/@sap/cds/lib/serve/Transaction.js:66:34)
    at async ODataRequest.emit (/home/user/projects/sap-ibp-promotions/node_modules/@sap/cds/lib/req/context.js:55:9)
    at async ApplicationService.commit (/home/user/projects/sap-ibp-promotions/node_modules/@sap/cds/lib/serve/Transaction.js:113:7) {
  statusCode: 502,
  innererror: Error: Error during request to remote service: Request failed with status code 400
      at createError (/home/user/projects/sap-ibp-promotions/node_modules/axios/lib/core/createError.js:16:15)
      at settle (/home/user/projects/sap-ibp-promotions/node_modules/axios/lib/core/settle.js:17:12)
      at IncomingMessage.handleStreamEnd (/home/user/projects/sap-ibp-promotions/node_modules/axios/lib/adapters/http.js:269:11)
      at IncomingMessage.emit (events.js:412:35)
      at endReadableNT (internal/streams/readable.js:1317:12)
      at processTicksAndRejections (internal/process/task_queues.js:82:21) {
    config: {
      url: "/commit?P_TransactionID='undefined'",
      method: 'get',
      proxy: false,
      baseURL: 'https://<Host>:<Port>.ondemand.com/sap/opu/odata/IBP/PLANNING_DATA_API_SRV',
      timeout: 60000,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      data: undefined
    },
    request: {
      method: 'GET',
      url: "https://<Host>:<Port>.ondemand.com/sap/opu/odata/IBP/PLANNING_DATA_API_SRV/commit?P_TransactionID='undefined'",
      headers: {
        Accept: 'application/json,text/plain',
        authorization: 'Basic ...',
        'accept-language': 'en',
        'User-Agent': 'axios/0.21.4'
      }
    },
    response: {
      status: 400,
      statusText: 'Bad Request',
      headers: {
        'set-cookie': [
          'sap-usercontext=sap-client=100; path=/',
          'SAP_SESSIONID_BBT_100=lOH6w615_CBUW_uXnXY6-_jctENoDxHsqP36Fj4KKec%3d; path=/; secure; HttpOnly'
        ],
        'content-type': 'application/json;charset=utf-8',
        'content-length': '1067',
        dataserviceversion: '1.0',
        'sap-server': 'true',
        'sap-perf-fesrec': '139953.000000',
        'x-content-type-options': 'nosniff',
        'strict-transport-security': 'max-age=31536000; includeSubDomains',
        'x-xss-protection': '1; mode=block'
      },
      body: {
        error: {
          code: '/IBP/EXTRACT_MSG/064',
          message: {
            lang: 'en',
            value: 'Transaction ID undefined does not exist.'
          },
          innererror: {
            application: {
              component_id: 'SCM-IBP-INT-ODT',
              service_namespace: '/IBP/',
              service_id: 'PLANNING_DATA_API_SRV',
              service_version: '0001'
            },
            transactionid: '3372965542570250E0061CB5B83B2307',
            timestamp: '20211228185715.1964500',
            Error_Resolution: {
              SAP_Transaction: 'For backend administrators: use ADT feed reader "SAP Gateway Error Log" or run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details',
              SAP_Note: 'See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)'
            },
            errordetails: [
              {
                ContentID: '',
                code: '/IBP/CX_PLNG_DATA_DI_API',
                message: 'Transaction ID undefined does not exist.',
                propertyref: '',
                severity: 'error',
                transition: false,
                target: ''
              },
              {
                ContentID: '',
                code: '/IWBEP/CX_MGW_BUSI_EXCEPTION',
                message: 'Transaction ID BATCH_ID does not exist.',
                propertyref: '',
                severity: 'error',
                transition: false,
                target: ''
              }
            ]
          }
        }
      }
    },
    isAxiosError: true,
    correlationId: '913962db-f86f-46ba-a246-69a3139da030'
  },
  id: '1442039',
  level: 'ERROR',
  timestamp: 1640717835239
}
I would highly appreciate if someone can suggest what could be the possible solution or workaround for this issue, In logs I can see its trying to fetch entities an services which I even not asked for.

Attachments

image.png (489.1 kB)
image.png (110.6 kB)
image.png (183.3 kB)
image.png (87.4 kB)
image.png (62.9 kB)
image.png (20.0 kB)
image.png (66.6 kB)
image.png (34.1 kB)
image.png (39.1 kB)