cancel
Showing results for 
Search instead for 
Did you mean: 

Timesheet Entry Posting Through CAPM

raunakmatrix87
Discoverer
0 Kudos
383

Hi All,

I am trying to post the timesheet data to my public cloud system through CAPM but getting "CSRF token validation failed" error.

I am using "https://api.sap.com/api/API_MANAGE_WORKFORCE_TIMESHEET/overview" API , here we can API structure is different. Fields which are coming in Complex Type i.e. (TimeSheetDataFields) are not accessible.

below is my payload:-

{

"TimeSheetDataFields": {

"ControllingArea": "string",

"SenderCostCenter": "string",

"ReceiverCostCenter": "string",

"InternalOrder": "string",

"ActivityType": "string",

"WBSElement": "string",

"WorkItem": "string",

"BillingControlCategory": "string",

"PurchaseOrder": "string",

"PurchaseOrderItem": "string",

"TimeSheetTaskType": "string",

"TimeSheetTaskLevel": "string",

"TimeSheetTaskComponent": "string",

"TimeSheetNote": "string",

"RecordedHours": "0",

"RecordedQuantity": "0",

"HoursUnitOfMeasure": "string",

"RejectionReason": "string",

"TimeSheetWrkLocCode": "string",

"TimeSheetOvertimeCategory": "string",

"SenderPubSecFund": "string",

"SendingPubSecFunctionalArea": "string",

"SenderPubSecGrant": "string",

"SenderPubSecBudgetPeriod": "string",

"ReceiverPubSecFund": "string",

"ReceiverPubSecFuncnlArea": "string",

"ReceiverPubSecGrant": "string",

"ReceiverPubSecBudgetPeriod": "string"

},

"PersonWorkAgreementExternalID": "string",

"CompanyCode": "string",

"TimeSheetRecord": "string",

"PersonWorkAgreement": "string",

"TimeSheetDate": "/Date(1492098664000)/",

"TimeSheetIsReleasedOnSave": true,

"TimeSheetPredecessorRecord": "string",

"TimeSheetStatus": "string",

"TimeSheetIsExecutedInTestRun": true,

"TimeSheetOperation": "string"

}

Sample Payload:-

{
"TimeSheetDataFields": {
"ControllingArea": "A000",
"SenderCostCenter": "",
"ReceiverCostCenter": null,
"InternalOrder": "",
"ActivityType": "T005",
"WBSElement": "STLBSNL21042023.1.4",
"WorkItem": "P005",
"TimeSheetTaskType": "",
"TimeSheetTaskLevel": "",
"TimeSheetTaskComponent": "",
"TimeSheetNote": "",
"RecordedHours": "11",
"RecordedQuantity": "1",
"HoursUnitOfMeasure": "H",
"RejectionReason": "",
"TimeSheetWrkLocCode": "",
"TimeSheetOvertimeCategory": ""
},
"PersonWorkAgreementExternalID": "MOMPS03",
"CompanyCode": "1810",
"PersonWorkAgreement": null,
"TimeSheetDate": "2023-08-10T00:00:00",
"TimeSheetStatus": "30",
"TimeSheetIsExecutedInTestRun": false,
"TimeSheetOperation": "C"
}

It's working fine when we are posting the data in postman or API HUB.

Thanks

Accepted Solutions (0)

Answers (1)

Answers (1)

martinstenzig
Contributor
0 Kudos

Make sure you have the csrf flag set in your package.json. Below an example for a MaintenanceNotification API

"OP_API_MAINTNOTIFICATION": {
        "kind": "odata-v2",
        "csrf": true,
        "model": "srv/external/OP_API_MAINTNOTIFICATION",
        "credentials": {
                        "destination": "abcde",
                        "path":"/sap/opu/odata/sap/API_MAINTNOTIFICATION"
                    }
        }
raunakmatrix87
Discoverer
0 Kudos

Hi Martin,
Thank you for your response.

We have tried this but still getting the same error.

martinstenzig
Contributor
0 Kudos

Can you post the console output you get with `cf logs [service name]` when you execute the call?

TamasFodor
Product and Topic Expert
Product and Topic Expert
0 Kudos

Dear raunaksharma,

Could you please update the requested console output if you still receive this issue?

Maybe Martin could provide further information after that has been attached.

Kind regards,

Tamas

SAP Community Topic Expert