cancel
Showing results for 
Search instead for 
Did you mean: 

Issues while using PUT in Sapui5 using odata services..

ashwin_narayan
Participant
0 Kudos

Hi Experts,

I'm using Odata services, Everything is working fine Except the moment when I try updating or using "PUT" operation.

In the gateway side while using the same URL, I been able to update it but the same is not happening through SAPui5,

I'm getting a 403 forbidden error, attaching a screen shot of the error.

I try reading other blogs, but it was not helpful...I can even post the codes also if anybody want it.

Need help !

Regards,

Ashwin

Accepted Solutions (1)

Accepted Solutions (1)

AshwinDutt
Active Contributor
0 Kudos

Hello Ashwin,

Issue could be because of CSRF token as well. Check this as well.

Use the metadata URL of your Update Service or any GET service URL and First fetch the toke value by passing the header ' X-CSRF-Token ' and value as ' fetch '.

Once you get the token value in the response headers, Please pass that particular token in the header ' X-CSRF-Token ' and value as ' <xxxxxxxxxx> '.

The below would help ->

Regards,

Ashwin

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi...

Is any one help me out this error...

i am getting response as below in browser...

<?xml version="1.0" encoding="utf-8"?><error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><code>005056A509B11ED199D8826D151FC0FE</code><message xml:lang="en">The specified HTTP method is not allowed for the resource identified by the Data Service Request URI</message><innererror xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><transactionid>BEB80BE629F4F1D4BE730050569C4F03</transactionid><timestamp>20160426141119.7080000</timestamp><Error_Resolution><SAP_Transaction>Run transaction /IWFND/ERROR_LOG on SAP NW Gateway hub system and search for entries with the timestamp above for more details</SAP_Transaction><SAP_Note>See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)</SAP_Note></Error_Resolution></innererror></error>





AshwinDutt
Active Contributor
0 Kudos

Hello Umesh,

PUT work on passing Key(s). I see that your URL does not contain Entity-Set name and the Key(s) associated with that.

Check the UPDATE operation section in the below which describes the details required.

Regards,

Ashwin

Former Member
0 Kudos

Hii Ashwin

I am passing entity set in the URL ...

I am sharing my source code let me know where i m wrong..

please check the thread i have already raised...

Thanks in adv..

Former Member
0 Kudos

Try using MERGE or PATCH instead of PUT in method type. I hope this will solve your problem

0 Kudos

Hi,

Thanks for the response.. Actually I get the error when I execute from the fiori end. I'm doing oModel.create.. I corelated this operation to PUT operation.. from the gateway client the PUT operation works properly..

ashwin_narayan
Participant
0 Kudos

Hi all,

Thanks all for your valuable feedbacks and guidance.

It is now working for me...problem was with the way I was passing the values into the URL.

Thanks,

Ashwin

navn_metts
Active Participant
0 Kudos

Hello Ashwin,

I am also facing the same issue. can you please let me know how you solved this issue??

ashwin_narayan
Participant
0 Kudos

Hi Naveen,

Try posting your code, may be I can have a look.

What is the error you getting?

Regards,

Ashwin

navn_metts
Active Participant
0 Kudos

Hello Ashwin,

Thank you for your response.

I solved the issue. The issue is with the data i am passing in the request method.

Br

Navn

ashwin_narayan
Participant
0 Kudos

Perfect

0 Kudos

Hi.. I'm facing the exact same issue. I checked the pay load but I can't see anything this wrong. Can you plese help? Here is my payload.

  1. Request Payload
      1. {__metadata: {,…}, Bukrs: "0001", Ranl: "10013101", Rbo: "", SboStatus: "", Sfgkz: "",…}
        1. Bavwr: "0.00"
        2. Bbasis: "0.00"
        3. Bcredits: "0.00"
        4. Bcwhr: "100"
        5. BdefPayments: "0.00"
        6. Bhwhr: "0.00"
        7. Bkond: "0.00"
        8. Boutstanding: "0.00"
        9. BoverdueItems: "0.00"
        10. Bproppayments: "0.00"
        11. Bregpayments: "0.00"
        12. Brpwr: "0.00"
        13. Brpwr_faell: "63244.03"
        14. Bukrs: "0001"
        15. DdeferralFrom: null
        16. Ddispo: "/Date(1456684200000)/"
        17. Delfz: null
        18. Delfz_repay: null
        19. Dfaell: "/Date(1456684200000)/"
        20. Dguel_Kp: null
        21. Dkuenddg: null
        22. IoaAmount: "0.00"
        23. Jregpayments: ""
        24. Kunnr: ""
        25. NavToAddFlow: []
        26. NavToCashFlow: [{__metadata: {,…}, Bukrs: "0001", Ranl: "10013101", Sbewart: "0001", Sbewziti: "A", Scwhr: "EUR",…},…]
        27. NavToOpenItem: []
        28. Pkond: "0.0000000"
        29. R_sbo_status: "1"
        30. Ranl: "10013101"
        31. Rbo: ""
        32. Sbewart: "0138"
        33. SboStatus: ""
        34. Sboterm: ""
        35. Sbust: "00"
        36. Sfgkz: ""
        37. Sgtxt: ""
        38. Sincl: ""
        39. Sinclint: "0"
        40. Skalid: ""
        41. Skoart: "0000"
        42. Svult: ""
        43. Xtext: ""
        44. Zlsch: ""
        45. __metadata: {,…}
        46. baddflows: "0.00"
        47. bbbwhr: "0.00"
        48. bo_text: "new12"
        49. change_flag: ""
        50. partner: ""
        51. sbwhr: ""
0 Kudos

Hi.. I'm facing the exact same issue. I checked the pay load but I can't see anything this wrong. Can you plese help? Here is my payload.

  1. Request Payload
      1. {__metadata: {,…}, Bukrs: "0001", Ranl: "10013101", Rbo: "", SboStatus: "", Sfgkz: "",…}
        1. Bavwr: "0.00"
        2. Bbasis: "0.00"
        3. Bcredits: "0.00"
        4. Bcwhr: "100"
        5. BdefPayments: "0.00"
        6. Bhwhr: "0.00"
        7. Bkond: "0.00"
        8. Boutstanding: "0.00"
        9. BoverdueItems: "0.00"
        10. Bproppayments: "0.00"
        11. Bregpayments: "0.00"
        12. Brpwr: "0.00"
        13. Brpwr_faell: "63244.03"
        14. Bukrs: "0001"
        15. DdeferralFrom: null
        16. Ddispo: "/Date(1456684200000)/"
        17. Delfz: null
        18. Delfz_repay: null
        19. Dfaell: "/Date(1456684200000)/"
        20. Dguel_Kp: null
        21. Dkuenddg: null
        22. IoaAmount: "0.00"
        23. Jregpayments: ""
        24. Kunnr: ""
        25. NavToAddFlow: []
        26. NavToCashFlow: [{__metadata: {,…}, Bukrs: "0001", Ranl: "10013101", Sbewart: "0001", Sbewziti: "A", Scwhr: "EUR",…},…]
        27. NavToOpenItem: []
        28. Pkond: "0.0000000"
        29. R_sbo_status: "1"
        30. Ranl: "10013101"
        31. Rbo: ""
        32. Sbewart: "0138"
        33. SboStatus: ""
        34. Sboterm: ""
        35. Sbust: "00"
        36. Sfgkz: ""
        37. Sgtxt: ""
        38. Sincl: ""
        39. Sinclint: "0"
        40. Skalid: ""
        41. Skoart: "0000"
        42. Svult: ""
        43. Xtext: ""
        44. Zlsch: ""
        45. __metadata: {,…}
        46. baddflows: "0.00"
        47. bbbwhr: "0.00"
        48. bo_text: "new12"
        49. change_flag: ""
        50. partner: ""
        51. sbwhr: ""
AshwinDutt
Active Contributor
0 Kudos

Hello Tejas,

What is the error message which you are getting ?

Regards,

Ashwin

Ashg1402
Contributor
0 Kudos

Hi tejas,

for you, problem can be at two fields -

  1. Dfaell: "/Date(1456684200000)/"
  2. Ddispo: "/Date(1456684200000)/"

As it does the conversion into proper type for date. What is the type for these 2 fields.?

kammaje_cis
Active Contributor
0 Kudos

Problem is only with mobile?

Check here. It may not give a solution, but you might get more info.

ashwin_narayan
Participant
0 Kudos

Hi Krishna,

No idea about mobile. As of now its not working anywhere.

Thanks,

Ashwin

ashwin_narayan
Participant
0 Kudos

Hi,

Is it something to do with "x-csrf-token",

if yes then how to pass these tokens??


Thanks,

Ashwin

sreehari_vpillai
Active Contributor
0 Kudos

Hi,

I am not seeing the entitySet name in the request URL . And, please share me the UI5 code which you use to post data.

Reg  CSRF; You dont need to manually pass it if you are using oModel.create function. CSRF token handling is manually handled here. Better don't go for manual ajax calls.

ashwin_narayan
Participant
0 Kudos

Hi Sree,

Well I'm not using oModel.create as i"m directly taking values from the form and sending it to the backend. I tried working on CSRF and managed to resolve 403 forbidden error...while now it gives another error saying bad request #400.

well I will post the code for which I'musing for POST operation:

Note: changed my url for security reasons.

var mid = $("#mrid1").val();

var url = "http://"myUrl"/"my \enityset"('"+mid+"')";

  OData.request({

  requestUri : "http://"my url",

  method : "GET",

  headers : {

  "X-Requested-With" : "XMLHttpRequest",

  "Content-Type" : "application/xml ",

  "DataServiceVersion" : "2.0",

  "X-CSRF-Token" : "Fetch",

  "Accept": "application/xml",

  }

  },

  function(data, response) {

  console.log(response);

  var header_xcsrf_token = response.headers['x-csrf-token'];

  var requestObj1 = {

  requestUri: '',

  method: '',

  headers: {

  "X-Requested-With": "XMLHttpRequest",

  "Content-Type": "application/xml",

  "X-CSRF-Token": header_xcsrf_token,

  "DataServiceVersion": "2.0", 

  "MaxDataServiceVersion": "2.0",

  "Accept": "application/xml",

  },

  };

  var method = "PUT";

  requestObj1.requestUri = url;

  requestObj1.method = method;

  requestObj1.data = newData;

  

  OData.request(requestObj1, function() {

   this.resetForm();

  });

and this is th new network tab error

  1. Remote Address:192.168.3.140:8800
  2. Request URL:http://"host".com:8800/sap/opu/odata/sap/ZISU_SM_SRV_01/"Entityset"('2002')
  3. Request Method:PUT
  4. Status Code:400 Bad Request
  5. Request Headersview source
    1. Accept:application/xml
    2. Accept-Encoding:gzip, deflate, sdch
    3. Accept-Language:en-US,en;q=0.8
    4. Cache-Control:no-cache
    5. Connection:keep-alive
    6. Content-Length:72
    7. Content-Type:application/xml
    8. Cookie:sap-usercontext=sap-client=100; MYSAPSSO2=AjQxMDMBABhEAFMASQBNAE8ATgAgACAAIAAgACAAIAACAAYxADAAMAADABBVAEcAMQAgACAAIAAgACAABAAYMgAwADEANQAwADMAMAAyADAANAA1ADAABQAEAAAACAYAAlgACQACRQD%2fAPwwgfkGCSqGSIb3DQEHAqCB6zCB6AIBATELMAkGBSsOAwIaBQAwCwYJKoZIhvcNAQcBMYHIMIHFAgEBMBkwDjEMMAoGA1UEAxMDVUcxAgcgEwcFGSUgMAkGBSsOAwIaBQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0xNTAzMDIwNDUwMzVaMCMGCSqGSIb3DQEJBDEWBBQzf064s0Khp4MANpwHjNm8iNE0iDAJBgcqhkjOOAQDBDAwLgIVAJ%213WjOpC%21uvpmCtTEKTZ40P8QfZAhUApRl1VJInAEmiNXQ3HaQrNtCuKG4%3d; SAP_SESSIONID_UG1_100=UWPJizumb7GHnX1UrLZSk4XLUunAuBHktaQADCl80Rg%3d
    9. DataServiceVersion:2.0
    10. Host:"host"
    11. MaxDataServiceVersion:2.0
    12. Origin:http://"host".com:8800
    13. Pragma:no-cache
    14. Referer:http://"host":8800/sap/bc/ui5_ui5/html?sap-client=100&sap-ui-language=EN&sap-ui-appcache=false
    15. User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36
    16. X-CSRF-Token:_yQXBs3KDvKjky_0vgBQ2A==
    17. X-Requested-With:XMLHttpRequest
  6. Request Payload
    1. <d:uri xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"/>
  7. Response Headersview source
    1. content-length:744
    2. content-type:application/xml
    3. dataserviceversion:1.0
    4. server:SAP NetWeaver Application Server / ABAP 731

Thanks,

Ashwin

AshwinDutt
Active Contributor
0 Kudos

Hello Ashwin,

Try passing the Key inside the URL and check. Say UserID is the key of the GW Model, then pass

http://"host".com:8800/sap/opu/odata/sap/ZISU_SM_SRV_01/<YourEntitysetName>/(UserID='2002')


If its failing then,

Now you need to look into the format of payload which is generated from your UI is correct or not.

Check the format.

If format is also correct check Content Type Header. Try below ones.

  1. try Content-Type:application/xml and also
  2. Content-Type:application/atom+xml

  3. I would suggest to use json payload and check.
  4. passContent-Type:application/json as Header.

  5. Sample Json format -> Change accordingly for your case

{

"Carrid":"AF",

"Connid":"0820"

}


  1. Regards,
  2. Ashwin
ashwin_narayan
Participant
0 Kudos

Hi Ashwin,

Yes i Tried giving values inside the URL.

It didnt worked.

Thanks,

Ashwin

ashwin_narayan
Participant
0 Kudos
  1. Hi Sree,
  2. Appreciate Your fast Response. This is what network tab says.

  3. Remote Address:[::1]:54731
  4. Request URL:http://localhost:54731/formdata/proxy/http/abc.xyz.com:8800/sap/opu/odata/sap/)
  5. Request Method:PUT
  6. Status Code:403 Forbidden
  7. Request Headersview source
    1. Accept:application/xml
    2. Accept-Encoding:gzip, deflate, sdch
    3. Accept-Language:en-US,en;q=0.8
    4. Authorization:Basic ZHNpbW9uOlR1ZHAxMzU3
    5. Cache-Control:no-cache
    6. Connection:keep-alive
    7. Content-Length:72
    8. Content-Type:application/xml
    9. Cookie:SAP_SESSIONID_UG1_100=BHnfuhSjkcpNMrQLhRGMph3qXPLAqxHktaQADCl80Rg%3d
    10. DataServiceVersion:2.0
    11. Host:localhost:54731
    12. MaxDataServiceVersion:2.0
    13. Origin:http://localhost:54731
    14. Pragma:no-cache
    15. Referer:http://localhost:54731/formdata/index.html
    16. User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36
    17. X-Requested-With:XMLHttpRequest
  8. Request Payload
    1. <d:uri xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"/>
  9. Response Headersview source
    1. Content-Length:28
    2. content-type:text/plain; charset=utf-8
    3. server:SAP NetWeaver Application Server / ABAP 731
    4. server:Jetty(8.1.10.v20130312)
    5. x-csrf-token:Required

  10. Regards,
  11. Ashwin
sreehari_vpillai
Active Contributor
0 Kudos

Hi,

Can you get the details from the network tab in debugger ? there you will get exact error details. Code the code snippet too.

Sree