cancel
Showing results for 
Search instead for 
Did you mean: 

Error while doing the PUT operation

Former Member
0 Kudos

Hi all...

Here I am trying to change purchase order then i am getting error after clicking SAVE PO button ...........


I am getting Error  PUT  http://......sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET/ 405 (Method Not Allowed).

i tried to update one of the parameters in the available oData service for my work,


Kindly help me in this and guide me so that I can update the contents in the back end.

specially look the code those i have marked in bold char  PUT method...

Here is my code:

Please help me in this...........




var btnPrevPO = new sap.ui.commons.Button('btnPrevPO',{

      text : "Edit PO",

      style: sap.ui.commons.ButtonStyle.Emph,

      press : function(){PreviousPo();}

    });

    var btnSavePO = new sap.ui.commons.Button('btnSavePO',{

      text : "Save PO",

      style: sap.ui.commons.ButtonStyle.Emph,

      press : function(){PostDoc2();}

    });

    //------------------------------------------------------------------------

    function PostDoc2(){

      hdpage.setBusy(true);

      itmpage.setBusy(true);

      matnrpage.setBusy(true);

      vendpage.setBusy(true);

   

  var serviceURI = url+"/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('"+txt_PrevPO.getValue()+"')?$expand=PO_Navigation/POCOND_NAVI";

OData.request({ requestUri: serviceURI,

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

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

                                "DataServiceVersion": "2.0",

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

                   method : "GET",

                user: "**********",

                password: "************" ,

                recognizeDates: true,

                         },

                         function (data, response){

                           stat = 0;

                           check_fields ();

                           if (stat == 1) {

                    hdpage.setBusy(false);

                    itmpage.setBusy(false);

                    matnrpage.setBusy(false);

                    vendpage.setBusy(false);

              } else {

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

var PostReq = url+"/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET/";                

                  var PostData = new sap.ui.model.json.JSONModel();

                  var LineItmArr = [] , POCOND_NAVI = [], results = [];

                  var LinesLength = oModel.oData.modelData.length;

                  var PricLength = aCondData2.length;

                  for (i = 0; i < LinesLength; i++){

                    results = [];

                    for (j = 0; j < aCondData2.length; j++){

                      var innerdata = aCondData2[j];

                      for (k = 0; k < innerdata.length ; k++){

                        if (oModel.oData.modelData[i]['LineItem'] == innerdata[k]['LineItem']) {

                          if (innerdata[k]['condtype'] !== '' && innerdata[k]['condval'] !== '') {

                            results.push({

                              ChangeId : '',

                              CondPUnt : '1',

                              CondStNo : '001',

                              CondType: innerdata[k]['condtype'],

                              CondValue: innerdata[k]['condval'],

                              ConditionNo : '',

                              Currency: currency.getValue(),

                              Exppurchaseorder : '',

                              ItmNumber : innerdata[k]['LineItem'],

                              PoItem : innerdata[k]['LineItem']

                            });

                          }

                          else{

                            results.push({

                              ChangeId : '',

                              CondPUnt : "0",

                              CondStNo : '',

                              CondType: innerdata[k]['condtype'],

                              CondValue: "0.000000000",

                              ConditionNo : '',

                              Currency: currency.getValue(),

                              Exppurchaseorder : '',

                              ItmNumber : innerdata[k]['LineItem'],

                              PoItem : innerdata[k]['LineItem']

                            });

                          }

                        }

                      }

                    }

                    checkMandatory();

                    if (stat == 1) {

                        hdpage.setBusy(false);

                        itmpage.setBusy(false);

                        matnrpage.setBusy(false);

                        vendpage.setBusy(false);

                    } else {

                      var delvformat = '';

                      if (oModel.oData.modelData[i]['delvdate'] !== '') {

                        jQuery.sap.require("sap.ui.core.format.DateFormat");

                        var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern: "yyyy/MM/dd"});

                        var dateTemp = oModel.oData.modelData[i]['delvdate'];

                        delvformat = oDateFormat.format(new Date(dateTemp));

                      }

                      oModel.oData.modelData[i]['AccAss'] = oModel.oData.modelData[i]['AccAss'].replace(/\s/g,'');  // Remove spaces

                      oModel.oData.modelData[i]['matgroup'] = oModel.oData.modelData[i]['matgroup'].replace(/\s/g,'');  // Remove spaces

                      oModel.oData.modelData[i]['gl'] =

                      oModel.oData.modelData[i]['material'] = oModel.oData.modelData[i]['material'].replace(/\s/g,''); // Remove Space

                      oModel.oData.modelData[i]['netprice'] = oModel.oData.modelData[i]['netprice'].replace(/\s/g,''); // Remove Space

.

.

.

.

.

oModel.oData.modelData[i]['copaSalDoc'].replace(/\s/g,''); // Remove Space

DelDatcatExt : '',

                        DeleteInd : '',

                        DeliveryDate : delvformat,

                        Exppurchaseorder : '',

                        GlAccount : oModel.oData.modelData[i]['gl'],

                        .

                        .

           .

                        Quantity : oModel.oData.modelData[i]['POQty'],

                        SalesDoc : oModel.oData.modelData[i]['copaSalDoc'],

                        ShortText : oModel.oData.modelData[i]['shorttext'],

                      });

                      PostData = {

                          "CompCode" : ComCode.getValue(),    "CompCodeX" : "",

"CreatedBy" : createdby.getValue(),   "CreatedByX" : "",

                          "Currency" : currency.getValue() ,  "CurrencyX" : "",

                          "DeleteInd" : "",   "DeleteIndX" : "",

.

.

.

.

.

"Vendor" : txt_vendor.getValue()  ,   "VendorX" : "" ,

                          "hTextNote" : hTextNote.getValue(),

                          "CondNbtval" : CONDNBT.getValue(),

                          "PO_Navigation":

                            LineItmArr

                        };

                    }

                  }

                  if (stat == 1) {

                  } else {

                 var chk_lngth, chk_cond ;

                    chk_lngth = '';

                    chk_lngth = PostData.PO_Navigation.length;

                    for (k = 0; k < PostData.PO_Navigation.length ; k++){

                      chk_cond = '';

                      chk_cond = PostData.PO_Navigation[k].POCOND_NAVI.length;

                      if (chk_cond == 0) {

                        PostData.PO_Navigation[k].POCOND_NAVI.push({

                          ChangeId : '',

                          CondPUnt : "0",

                          CondStNo : '',

                          CondType: '',

                          CondValue: "0.000000000",

                          ConditionNo : '',

                          Currency: currency.getValue(),

                          Exppurchaseorder : '',

                          ItmNumber : '',

                          PoItem : ''

                        });

                      }

                    }

                    OData.request({

                        requestUri: PostReq,

                        method: "PUT",

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

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

                                             "DataServiceVersion": "2.0",

                                             "Accept": "application/atom+xml,application/atomsvc+xml,application/xml",

                                             "X-CSRF-Token": header_xcsrf_token

                                             },

                            user: "**********",

                          password: "***********" ,

                          data : PostData,

                         // data : temp,

                      },

                      function (data, response){

                        hdpage.setBusy(false);

                        itmpage.setBusy(false);

                        matnrpage.setBusy(false);

                        vendpage.setBusy(false);

                        if(data['Msg'] == 'E'){

                            tptext.setText(data['Return_Msg']);

                            tptext.setDesign("Bold");

                            tp1.addStyleClass("colorRedText");

                            tp1.setTitle("Error in Posting Document ");

                            tp1.open(sap.ui.core.Popup.Dock.BeginCenter, sap.ui.core.Popup.Dock.RightTop);

                        }else{

                            tptext.setText(data['Return_Msg']);

                            tptext.setDesign("Bold");

                            tp1.setTitle("PO Doc # : " + data['Exppurchaseorder']);

                            tp1.open(sap.ui.core.Popup.Dock.BeginCenter, sap.ui.core.Popup.Dock.RightTop);

                            tp1.addStyleClass(".colorRedText");

                            clearLineitm();

                            clearPricing();

                        }

                      },

                                 function (err) {

                                   hdpage.setBusy(false);

                                   itmpage.setBusy(false);

                                   matnrpage.setBusy(false);

                                   vendpage.setBusy(false);

                                    sap.ui.commons.MessageBox.alert("Error Ocurred: " + ' ' + err.message, "", "Error", "");

                                    }

                      ); 

                  }

                }

                         },

                         function (err) {

                           hdpage.setBusy(false);

                           itmpage.setBusy(false);

                           matnrpage.setBusy(false);

                           vendpage.setBusy(false);

                            sap.ui.commons.MessageBox.alert("Error Ocurred: " + ' ' + err.message, "", "Error", "");

                            });

    }


Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi ....

Is i have tried all solution still error of token is coming..

how we are go through this issue ...?

Thanks in Adv.

EkanshCapgemini
Active Contributor
0 Kudos

Hi Umesh,

Can you share the HTTP Request URI and the payload that you are using for PUT request?

Few points to consider:

  • 'Deep Update' scenario (like 'Deep Insert') is not supported in OData v2 thus in SAP Gateway as well. You have to use $batch (recommended) or go with 'Deep Insert' it self with some flag for update method (not recommended as per the standards but functionality would work ).
  • The URI should be correct as .../ZSERVICE/EntitySet('123456789')
  • The payload should contain only the properties which belong to POHeader entityset and there should not be any mention of navigation property which you might be using while Create (POST) call.

Regards,

Ekansh

Former Member
0 Kudos

Hi Ekansh


var PostReq = url+"/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('1000003042');


http://user:password@00.00.000:000/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('1000003042');


these  URI are you saying ...?



Regards,

Umesh




EkanshCapgemini
Active Contributor
0 Kudos

Yes, plz share the payload as well.

Former Member
0 Kudos



http://user:password@00.00.000:000/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('1000003042')?$expand=PO_Navigation/POCOND_NAVI


EkanshCapgemini
Active Contributor
0 Kudos

Hi Umesh,

This is not the payload. Payload is nothing but the HTTP request body.

Please share the HTTP request body content of PUT call. with screenshot.

Former Member
0 Kudos

Hi Ekansh

i am getting this output of HTTP req on PUT call..........

EkanshCapgemini
Active Contributor
0 Kudos

need HTTP Request Body .

Former Member
0 Kudos

Hi Ekansh

This my UI code  HTTP request body for PUT call

                    sap.m.MessageToast.show('header_xcsrf_token',header_xcsrf_token);

                    OData.request({

                        requestUri: PostReq,

                        method: "PUT",

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

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

                                             "DataServiceVersion": "2.0",

                                             "Accept": "application/atom+xml,application/atomsvc+xml,application/xml",

                                             "X-CSRF-Token": header_xcsrf_token

                                             },

                            user: "*****",

                          password: "******",

                          data : PostData,

                         // data : temp,

                      },

                      function (data, response){

                      console.log('Data POST Resp:l-',data, response);

                        hdpage.setBusy(false);

                        itmpage.setBusy(false);

                        matnrpage.setBusy(false);

                        vendpage.setBusy(false);

                        if(data['Msg'] == 'E'){

                            tptext.setText(data['Return_Msg']);

                            tptext.setDesign("Bold");

                            tp1.addStyleClass("colorRedText");

                            tp1.setTitle("Error in Posting Document ");

                            tp1.open(sap.ui.core.Popup.Dock.BeginCenter,sap.ui.core.Popup.Dock.RightTop);

                        }else{

                            tptext.setText(data['Return_Msg']);

                            tptext.setDesign("Bold");

                            tp1.setTitle("PO Doc # : " + data['Exppurchaseorder']);

      tp1.open(sap.ui.core.Popup.Dock.BeginCenter,  sap.ui.core.Popup.Dock.RightTop);

                            tp1.addStyleClass(".colorRedText");

                            clearLineitm();

                            clearPricing();

                        }

                      },

                                 function (err) {

                                   hdpage.setBusy(false);

                                   itmpage.setBusy(false);

                                   matnrpage.setBusy(false);

                                   vendpage.setBusy(false);

                   sap.ui.commons.MessageBox.alert("Error Ocurred: " + ' ' + err.message, "", "Error", "");

                                    }

                      );  // oData POST Request

                  }

                }

                         },

                         function (err) {

                           hdpage.setBusy(false);

                           itmpage.setBusy(false);

                           matnrpage.setBusy(false);

                           vendpage.setBusy(false);

                   sap.ui.commons.MessageBox.alert("Error Ocurred: " + ' ' + err.message, "", "Error", "");

                            });

    }

Regards

Umesh

sreehari_vpillai
Active Contributor
0 Kudos

I would suggest you to first make PUT call from gateway client, where the token issues are handled. Then , if it is a success, use the same structure of payload(http request body) to make the PUT from your UI5 / rest clients .

Sreehai

EkanshCapgemini
Active Contributor
0 Kudos

Hi Umesh,

I have already suggested you to check your payload that it should not contain Navigation Property.

  • The payload should contain only the properties which belong to POHeader entityset and there should not be any mention of navigation property which you might be using while Create (POST) call.

As per your PostData variable (details are not present in the above reply, one has to go and check the code in the question...sad), you are appending an array of LineItems Navigation Property.


PostData = {

                          "CompCode" : ComCode.getValue(),    "CompCodeX" : "",

"CreatedBy" : createdby.getValue(),   "CreatedByX" : "",

                          "Currency" : currency.getValue() ,  "CurrencyX" : "",

                          "DeleteInd" : "",   "DeleteIndX" : "",

.

.

.

.

.

"Vendor" : txt_vendor.getValue()  ,   "VendorX" : "" ,

                          "hTextNote" : hTextNote.getValue(),

                          "CondNbtval" : CONDNBT.getValue(),

                          "PO_Navigation":

                            LineItmArr

                        };

                    }

Please remove that array, then it would trigger the UPDATE_ENTITY method. I have already mentioned the reason behind this in my previous reply.

Regards,

Ekansh

Former Member
0 Kudos

Hi Ekansh,

I removed the array, now its working but x-csrf token missing i added it manually it worked i got 204 No Content in PUT. i try to put break point in update entity but its not triggering in back end.

former_member185414
Active Contributor
0 Kudos

To make a successful PUT(Update) call you need to follow below steps. We will use 'Gateway Client' for testing.

1. Implement Get_Entity and Update_Entity methods.

2. Fire the Get_Entity method and fetch the XSRF token and click on 'Use as Request' button.

3. Change the values you want to update in the request body.

4. Fire the Update_Entity method.

5. The results should be updated.

BR.

Former Member
0 Kudos

Hi Umesh,

Can you please test at Gateway client first rather than jumping directly to any of the browser based client and check with an external debugger in UPDATE_ENTITY. Also post the snapshot of what error message you will get after doing this.

Thanks

Parth

Former Member
0 Kudos

Hi Umesh,

You see 'Method Not Allowed' error when the Service method is not implemented.

For example, When implementing POST, service method 'CREATE_ENTITY' has to be implemented and for PUT, service method UPDATE_ENTITY. So try changing your method to POST rather than PUT and see if it works.


Adding to this, generally when using POST method, we implement the 'GET_ENTITY' method (and not GET_ENTITYSET method) else it will result in some 415 error. Check that if it works that way.


Here, in my service, I've implemented GET_ENTITY and POST (CREATE_ENTITY) and working fine. For the same process, if i try PUT service, getting this error. Try changing your method to POST once.


Regards,

Santosh

Former Member
0 Kudos

Hi Santosh,

It is not working like u said,

See i explain my scenario i had one service which is creating PO succesfully, the method contains GET and POST. PO created successfully.

I created similar new service with different name working fine in gateway and i am using same code in .js, now in this i am just replacing PUT in place of POST. but i am getting this all error.

jibin_joy
Contributor
0 Kudos

Hi Umesh ,

  •   Put Method : It is not working because of Wrong URL  since key is missing we have update for Particular PO 


/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('Key')

  • Patch Method : it is not working might be because of lower SP version .

Regards,

Jibin Joy

Former Member
0 Kudos

Exactly, you cannot just change POST to PUT. For Put, you have to implement UPDATE_ENTITY method and as Jibin said, the URL would have the key included as well.

See it this way, when creating a PO, use POST and when changing a PO, you specify the PO number as part of URL and update, the method implementation differs in gateway.

Former Member
0 Kudos

Santosh,

i also implemented UPDATE_ENTITY already here in new service which i said. but its not working nor triggering in update_entity when i put break point there.

jibin_joy
Contributor
0 Kudos

Hi Umesh ,

Please share URL used for PUT .

Regards,

Jibin Joy

Former Member
0 Kudos


For GET ....

var serviceURI = url+"/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('"+txt_PrevPO.getValue()+"')?$expand=PO_Navigation/POCOND_NAVI";


For PUT ...

var PostReq = url+"/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('1000003042');


1000003042 this is my PO as a 'key' as u said...


I am getting user id & password here which automatically appending before IP address in URL when i check in console i think this is not the problem?


http://user:password@00.00.000:000/sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET('1000003042');

jibin_joy
Contributor
0 Kudos

Hi Umesh ,

Looks good ... Is it Possible to test the Service from 3rd party like Chrome Rest Client or Share the Developer tool screen shot for this URL

Regards,

Jibin Joy

former_member185414
Active Contributor
0 Kudos

Hi Umesh,

Apart from the suggestions mentioned by other colleagues, please also check the UI code. As far as I understand you have copied the same JS code as was for create scenario. You need to modify the call from oModel.create to oModel.update and use method PUT as per API Doc .

BR.

Former Member
0 Kudos

Hi Jibin....

3rd party i am getting this

jibin_joy
Contributor
0 Kudos

Hi Umesh ,

This is some other Issue  ... Please Refer

How to fetch X-CSRF-Token | SCN

Former Member
0 Kudos

i get this below error when i try to update.. first GET is succesful and then PUT shows x-scrf-Token required..

I dont understand why this happening please help me to resolve my issue.

i have shared my code in this thread above.. please have look.

this same code works when i try to do POST operation instead of PUT. 

jibin_joy
Contributor
0 Kudos

Hi Umesh ,

Please continue discussion in Gateway Blog !!!

For Put Request is Token is passed in Header ?

Regards,

Jibin Joy

Former Member
0 Kudos

Yes...

Have u check the source code which i have share with the same thread above..?

Please check you will get more idea....

jibin_joy
Contributor
0 Kudos

Hi Umesh ,

  Looks everything good ....

Can u test ur Service from Chrome Rest Client where u get Token from Get Request and Pass same token in Put Request

  Please share the screen shot also !!!

Regards,

Jibin Joy

Former Member
0 Kudos

Hi Jibin ,

i am getting X-csrf-Token while PUT and Get method both

below is screen shoot  it seems csrf token is not issue.. when i put breakpoint in the UPDATE_ENTITY it is not getting trigger obivously but how can i know that where is the problem.

    

jibin_joy
Contributor
0 Kudos

Please remove $expand in Put request URL !!!

PO_HEADER_SET('34234324')

Former Member
0 Kudos

Hi Jibin

I have tried ...

It still not working

jibin_joy
Contributor
0 Kudos

Hi Umesh ,

I Recommend . Please Post regarding this Issue in Gateway Development Blog . We can Continue our Discuss there .

Regards,

Jibin Joy

agentry_src
Active Contributor
0 Kudos

Discussion successfully moved from SAPUI5 Developer Center to SAP Gateway

as suggested. 

By the way, it is better to simply Alert Moderator with Wrong Space than make the suggestion in the Discussion.  This brings it to the attention of the Moderators who can then move the entire Discussion to a more appropriate community (like I just did).  The member who started the Discussion does not have the same ability unless they start a new Discussion which then violates the Cross Posting part of the Rules of Engagement.

Cheers, Mike (Moderator)

SAP Technology RIG

Former Member
0 Kudos

Dear Jibin,

What should be the SP version minimum required please throw some light...

Former Member
0 Kudos

Dear santosh,

Did you resolve your issue.. if so please help me too.

former_member185414
Active Contributor
0 Kudos

Hi Umesh,

Seems the PO Document which you are updating does not exist? Please check that.

BR

Former Member
0 Kudos

Hi Ankit....

When i entering PO after clicking on edit button it fetching data from ECC but after editing for update we have save button when i am trying to click on SAVE PO Button then it raise an error.....

PUT http://.........../sap/opu/odata/sap/ZPO_LGWZ_CHG_SRV/PO_HEADER_SET/ 405 (Method Not Allowed)

Thanks in Adv...

pavlo_denysyuk
Participant
0 Kudos

Update an Entity

The OData services SHOULD support PATCH as the preferred means of updating an entity. But also services MAY additionally support PUT. The request below update the Emails of a person using PATCH.


PATCH serviceRoot/People('russellwhyte')
OData-Version: 4.0
Content-Type: application/json;odata.metadata=minimal
Accept: application/json

{
     "@odata.type" : "Microsoft.OData.SampleService.Models.TripPin.Person",
     "Emails" : ["Russell@example.com", "Russell@contoso.com", "newRussell@contoso.com"]
}

Maybe PATCH would help. As we clearly see 405 ( with PUT ) - Method Not Allowed.

Former Member
0 Kudos

Dear Pavlo,

I am new to this technology hence i am not getting from where i should start for getting PATCH, I had gone through some content on internet but not getting for my case, can you please guide me for the same from scratch.

Former Member
0 Kudos

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>