cancel
Showing results for 
Search instead for 
Did you mean: 

how to call a odata with method patch

mark_fryu
Participant
0 Kudos

hi, I'm calling an odata service with patch method.

API_PRODUCTION_ORDER_2_SRV

resource path: A_ProductionOrder_2('ManufacturingOrder')

if I use the Odata adapter I get the error "Bad Request : 400 : HTTP/1.1"

while if I use the http adapter I receive the error: "Name or service not known"

can you help me to call a service with patch method?

thank you

dharamverma
Explorer

Please read my blog on this

I hope it will help you

Accepted Solutions (1)

Accepted Solutions (1)

dharamverma
Explorer

Please read my blog on this

I hope it will help you

mark_fryu
Participant
0 Kudos

hi, I read your blog, I inserted the content modifier immediately after the get call:

but if I look in the trace, I don't have an "if-match" field in the header:

also, when I call the patch method, if I set the resource path in the format you showed in the blog, so: A_ProductionOrder_2(ManufacturingOrder=’${property.ManufacturingOrder}’) I get the following error "Invalid URI syntax.":

Answers (8)

Answers (8)

dharamverma
Explorer

Following payload is working fine for me

<?xml version="1.0" encoding="UTF-8"?> <A_ProductionOrder_2><A_ProductionOrder_2Type><TotalQuantity>2.000</TotalQuantity></A_ProductionOrder_2Type></A_ProductionOrder_2>

Remember one point, dont send the same quantity again what you are getting in get call

quantity value should be diffrent from current value

mark_fryu
Participant
0 Kudos

thanks, this solved my problem, I accepted you as the correct answer 🙂 thank you very much.

I opened another question regarding a problem on oData, here is the link:

https://answers.sap.com/questions/14030205/format-field-opschedldstarttime-of-odata-api-produ.html

dharamverma
Explorer

You can not update each field, so send only field which you want to update

dharamverma
Explorer
0 Kudos

And there are some fields which can not be updated that is why you getting 400 error

mark_fryu
Participant
0 Kudos

I tried only with quantity, but I get the same error:

I didn't know what to feel anymore

mark_fryu
Participant
0 Kudos

I found the problem.

this is how it goes wrong:

A_ProductionOrder_2(ManufacturingOrder='${property.ProductionOrder}')

while this works correctly:

A_ProductionOrder_2('61333')


but I need a way to pass it as a variable

dharamverma
Explorer
0 Kudos

A_ProductionOrder_2('61333') will work fine with http adapter but not with OData adapter

With OData, A_ProductionOrder_2(ManufacturingOrder='${property.ProductionOrder}') or A_ProductionOrder_2(ManufacturingOrder='61333') will work

dharamverma
Explorer

1. Don't pass ManufacturingOrder field in payload

2. Set property ProductionOrder with the order number you want to update

and in update OData adapter

3.put A_ProductionOrder_2(ManufacturingOrder='${property.ProductionOrder}') in resource path

4. leave the Fields blank

Now it will surely work

mark_fryu
Participant
0 Kudos

I did as you said but I always get Bad Request : 400 : HTTP/1.1

in "content modifier 1" enhance the Production Order field:

I make the first read(get) call and get etag:

(I continue in the next comment, because I can insert a maximum of 2 screenshots)

mark_fryu
Participant
0 Kudos

i get the etag:

i call the odata with method patch (the payload is what I got from read(get))

dharamverma
Explorer
0 Kudos

Please give me the payload which you are setting in CM

mark_fryu
Participant
0 Kudos

this is the payload I get from the odata read(get) call (I no longer modify this payload and therefore I also use it for the patch call):

<A_ProductionOrder_2>

<A_ProductionOrder_2Type>

<MfgOrderScheduledStartDate>2020-09-09T00:00:00.000</MfgOrderScheduledStartDate>

<OrderSequenceNumber>0</OrderSequenceNumber>

<ProductConfiguration>0</ProductConfiguration>

<MfgOrderPlannedEndDate>2020-09-15T00:00:00.000</MfgOrderPlannedEndDate>

<MfgOrderCreationTime>1970-01-01T12:20:39.000</MfgOrderCreationTime>

<BasicSchedulingType>4</BasicSchedulingType>

<ManufacturingOrderCategory>10</ManufacturingOrderCategory>

<PlannedOrder></PlannedOrder>

<WBSElementExternalID></WBSElementExternalID>

<OrderIsMarkedForDeletion></OrderIsMarkedForDeletion>

<MfgOrderCreationDate>2020-09-07T00:00:00.000</MfgOrderCreationDate>

<ManufacturingOrderImportance>9</ManufacturingOrderImportance>

<OrderIsPreCosted>X</OrderIsPreCosted>

<OrderIsReleased></OrderIsReleased>

<InventoryUsabilityCode></InventoryUsabilityCode>

<SettlementRuleIsCreated>X</SettlementRuleIsCreated>

<FunctionalArea></FunctionalArea>

<GoodsRecipientName></GoodsRecipientName>

<OrderIsCreated></OrderIsCreated>

<SalesOrder></SalesOrder>

<ManufacturingObject>OR000000613333</ManufacturingObject>

<OrderLongText></OrderLongText>

<BusinessArea></BusinessArea>

<OrderIsConfirmed>X</OrderIsConfirmed>

<UnloadingPointName></UnloadingPointName>

<MfgOrderScheduledStartTime>1970-01-01T08:30:00.000</MfgOrderScheduledStartTime>

<MfgOrderPlannedEndTime>1970-01-01T00:00:00.000</MfgOrderPlannedEndTime>

<OrderIsScheduled></OrderIsScheduled>

<OrderIsDelivered>X</OrderIsDelivered>

<MaterialAvailyIsNotChecked></MaterialAvailyIsNotChecked>

<SettlementRuleIsCrtedManually></SettlementRuleIsCrtedManually>

<OrderHasGeneratedOperations></OrderHasGeneratedOperations>

<PlannedCostsCostingVariant>PPP1</PlannedCostsCostingVariant>

<SalesOrderItem>0</SalesOrderItem>

<MfgOrderScheduledEndDate>2020-09-10T00:00:00.000</MfgOrderScheduledEndDate>

<MfgOrderPlannedStartDate>2020-09-07T00:00:00.000</MfgOrderPlannedStartDate>

<ManufacturingOrderType>PP01</ManufacturingOrderType>

<MaterialGoodsReceiptDuration>0</MaterialGoodsReceiptDuration>

<OrderIsPrinted></OrderIsPrinted>

<MRPArea></MRPArea>

<ProductionUnitSAPCode>N.</ProductionUnitSAPCode>

<MfgOrderActualReleaseDate>2020-09-07T00:00:00.000</MfgOrderActualReleaseDate>

<QuantityDistributionKey></QuantityDistributionKey>

<OrderIsPartiallyReleased></OrderIsPartiallyReleased>

<Plant>BB01</Plant>

<OrderIsLocked></OrderIsLocked>

<TotalQuantity>4</TotalQuantity>

<OrderIsTechnicallyCompleted>X</OrderIsTechnicallyCompleted>

<CustomerName></CustomerName>

<StorageLocation>PR</StorageLocation>

<MfgOrderScheduledEndTime>1970-01-01T09:28:53.000</MfgOrderScheduledEndTime>

<StockSegment></StockSegment>

<ProductionUnit>N.</ProductionUnit>

<MRPController>005</MRPController>

<ProductionSupervisor>000</ProductionSupervisor>

<ProductionPlant>BB01</ProductionPlant>

<ProfitCenter></ProfitCenter>

<ActualCostsCostingVariant>PPP2</ActualCostsCostingVariant>

<OrderIsPartiallyConfirmed></OrderIsPartiallyConfirmed>

<OrderIsDeleted></OrderIsDeleted>

<Material>RATBB010</Material>

<MfgOrderPlannedScrapQty>0</MfgOrderPlannedScrapQty>

<OrderIsPartiallyDelivered></OrderIsPartiallyDelivered>

<OrderInternalBillOfOperations>214574</OrderInternalBillOfOperations>

<OrderIsClosed></OrderIsClosed>

<OrderIsToBeHandledInBatches></OrderIsToBeHandledInBatches>

<MfgOrderConfirmedYieldQty>4</MfgOrderConfirmedYieldQty>

<MfgOrderPlannedStartTime>1970-01-01T00:00:00.000</MfgOrderPlannedStartTime>

<LastChangeDateTime>20210117160101</LastChangeDateTime>

<ProductionUnitISOCode>PCE</ProductionUnitISOCode>

<CompanyCode>BB</CompanyCode>

<ManufacturingOrder>613333</ManufacturingOrder>

<ProductionVersion></ProductionVersion>

</A_ProductionOrder_2Type>

</A_ProductionOrder_2>

dharamverma
Explorer

etag value will be assigned to if-match, please use read(get) not query(get) operation in first get call, if etag header is not coming

mark_fryu
Participant
0 Kudos

thanks, now I get etag.

however the call still fails "com.sap.gateway.core.ip.component.odata.exception.OsciException: Bad Request : 400 : HTTP/1.1"

do I also need to pass the X-CSRF-Token parameter? How can I recover it?

This is the API: API_PRODUCTION_ORDER_2_SRV

resource path: A_ProductionOrder_2('ManufacturingOrder')

method: Patch

Bais
Participant
0 Kudos

403 appears because you have no access to that resource with your credentials.

When you are in Cloud Connector you must use On-Premise to reach your S4h.

the funny think is you are invoking OData with SOAP syntax? You wrote an xml soap body instead json once.

you are confusing 2 different type of format I suppose, on API you must use this body:

{
  "d": {
    "ManufacturingOrderCategory": "st",
    "ManufacturingOrderType": "stri",
    "OrderLongText": "string",
    "ManufacturingOrderImportance": "s",
    "OrderIsCreated": "s",
    "OrderIsReleased": "s",
    "OrderIsPrinted": "s",
    "OrderIsConfirmed": "s",
    "OrderIsPartiallyConfirmed": "s",
    "OrderIsDelivered": "s",
    "OrderIsDeleted": "s",
    "OrderIsPreCosted": "s",
    "SettlementRuleIsCreated": "s",
    "OrderIsPartiallyReleased": "s",
    "OrderIsLocked": "s",
    "OrderIsTechnicallyCompleted": "s",
    "OrderIsClosed": "s",
    "OrderIsPartiallyDelivered": "s",
    "OrderIsMarkedForDeletion": "s",
    "SettlementRuleIsCrtedManually": "s",
    "OrderIsScheduled": "s",
    "OrderHasGeneratedOperations": "s",
    "OrderIsToBeHandledInBatches": "s",
    "MaterialAvailyIsNotChecked": "s",
    "MfgOrderCreationDate": "/Date(1492041600000)/",
    "MfgOrderCreationTime": "PT15H51M04S",
    "LastChangeDateTime": "string",
    "Material": "string",
    "StorageLocation": "stri",
    "GoodsRecipientName": "string",
    "UnloadingPointName": "string",
    "InventoryUsabilityCode": "s",
    "MaterialGoodsReceiptDuration": "0",
    "QuantityDistributionKey": "stri",
    "StockSegment": "string",
    "OrderInternalBillOfOperations": "string",
    "ProductionPlant": "stri",
    "Plant": "stri",
    "MRPArea": "string",
    "MRPController": "str",
    "ProductionSupervisor": "str",
    "ProductionVersion": "stri",
    "PlannedOrder": "string",
    "SalesOrder": "string",
    "SalesOrderItem": "string",
    "BasicSchedulingType": "s",
    "ManufacturingObject": "string",
    "ProductConfiguration": "string",
    "OrderSequenceNumber": "string",
    "BusinessArea": "stri",
    "CompanyCode": "stri",
    "ProfitCenter": "string",
    "ActualCostsCostingVariant": "stri",
    "PlannedCostsCostingVariant": "stri",
    "FunctionalArea": "string",
    "MfgOrderPlannedStartDate": "/Date(1492041600000)/",
    "MfgOrderPlannedStartTime": "PT15H51M04S",
    "MfgOrderPlannedEndDate": "/Date(1492041600000)/",
    "MfgOrderPlannedEndTime": "PT15H51M04S",
    "MfgOrderScheduledStartDate": "/Date(1492041600000)/",
    "MfgOrderScheduledStartTime": "PT15H51M04S",
    "MfgOrderScheduledEndDate": "/Date(1492041600000)/",
    "MfgOrderScheduledEndTime": "PT15H51M04S",
    "MfgOrderActualReleaseDate": "/Date(1492041600000)/",
    "ProductionUnit": "str",
    "ProductionUnitISOCode": "str",
    "ProductionUnitSAPCode": "str",
    "TotalQuantity": "0",
    "MfgOrderPlannedScrapQty": "0",
    "MfgOrderConfirmedYieldQty": "0",
    "CustomerName": "string",
    "WBSElementExternalID": "string"
  }
}
mark_fryu
Participant
0 Kudos

I've used the soap payload for other APIs as well and it works fine.

Is it mandatory to use json for this API?

Bais
Participant
0 Kudos

if you want you can use OData adapter with xml syntax, but SOAP interface is totally another things.

https://api.sap.com/content-type/API/apis/packages

you are confusing 2 different protocol.

you are using API OData version 2, but why you are using body of a SOAP instead?

No sense.

mark_fryu
Participant
0 Kudos

this is my iflow:

in "content modifier 1" I retrieve the order number from the payload.

in the first call I do a read(get)

in "content modifier 2" I recover the etag field in the header.

in the last call, I make the patch method call.

what am I doing wrong? I get the error Bad Request : 400 : HTTP/1.1

Bais
Participant
0 Kudos

I've checked on : get_A_ProductionOrder_2

to troubleshooting your error I need example of source body and response body from error exception

mark_fryu
Participant
0 Kudos

sorry, now I managed to solve that problem, it was for the "on premise" flag.

I tried to make a call but now I get this:

I'm sure it's not the user, because I use this user for post and get calls and I have no problems

Bais
Participant
0 Kudos

put and exception handler with this groovy script so we can understand the error.

Did you tested patch with same data in Postman/Insomnia or other client before using Integration Suite?

import com.sap.gateway.ip.core.customdev.util.Message;

//reference:
//https://help.sap.com/viewer/368c481cd6954bdfa5d0435479fd4eaf/Cloud/en-US/a443efe1d5d2403fb95ee9def1a672d4.html

def Message processData(Message message) {

    def map = message.getProperties();

    def ex = map.get("CamelExceptionCaught");
    if (ex!=null) {
         message.setProperty("getCanonicalName",ex.getClass().getCanonicalName());
        // an http adapter throws an instance of org.apache.camel.component.ahc.AhcOperationFailedException
        if (ex.getClass().getCanonicalName().equals("org.apache.camel.component.ahc.AhcOperationFailedException")) {
            
            def messageLog = messageLogFactory.getMessageLog(message);
            messageLog.addAttachmentAsString("http.ResponseBody", ex.getResponseBody(), "text/plain");

            message.setProperty("http.ResponseBody",ex.getResponseBody());
            message.setBody(ex.getResponseBody());

            message.setProperty("http.StatusCode",ex.getStatusCode());
            message.setProperty("http.StatusText",ex.getStatusText());
            
        }
    }

    return message;
}

and send me the body of error, (remove confidential data if needed)

Bais
Participant
0 Kudos

could you provide full path and error?

example: https://myXXXXXX-api.s4hana.cloud.sap/sap/opu/odata/sap/API_BUSINESS_PARTNER/A_BusinessPartner

I suppose your path is:

https://myXXXXXX-api.s4hana.cloud.sap/sap/opu/odata/sap/API_PRODUCTION_ORDER_2_SRV/A_ProductionOrder_2('your value of ManufacturingOrder not the name of field')

mark_fryu
Participant
0 Kudos

here it is:

do you know what it could be?