Question

ODATA - Use an OData batch GET then DELETE from the returned results

  • 20 July 2023
  • 1 reply
  • 118 views

Userlevel 4
Badge +11

I'm trying to compose an OData batch to retrieve a set of results from table PAYMENT using request_id for the retrieval. From the returned results I want to extract the payment_id and add this to the URL for the delete as payment_id is the only allowed unique key in the delete URL.

I have the below OData batch:

--batch_ABC Content-Type: multipart/mixed; boundary=changesetPQR

--changesetPQR Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 1

GET https://XXXX-dev.corporate.ifs.com/FSMDEV/odata/payment?$filter=request_id eq '991' HTTP/1.1 Content-Type: application/json

--changesetPQR Content-Type: application/http Content-Transfer-Encoding: binary Content-ID: 2

DELETE https://XXXX-dev.corporate.ifs.com/FSMDEV/odata/payment?$filter=request_id eq '991' HTTP/1.1 Content-Type: application/json

--changesetPQR-- --batch_ABC—

Below are the results:

--batchresponse_fdffc443-4f7c-4be7-bbb6-4804476baa4d Content-Type: application/http Content-Transfer-Encoding: binary

HTTP/1.1 200 OK Content-Type: application/json; odata.metadata=minimal OData-Version: 4.0

{"@odata.context":"https://XXXX-dev.corporate.ifs.com/FSMDEV/OData/$metadata#PAYMENT","value":[{"created_by":"METRIX","created_dttm":"2023-07-14T17:55:25.9100000","memo":"INTEGRATION TEST","modified_by":"METRIX","modified_dttm":"2023-07-14T17:55:25.9100000","payment_amount":"200.00","payment_card_cvv_mask":"999","payment_card_expired":"12/2024","payment_card_holder":"Joe Bloggs","payment_card_no_mask":"1234 5678 9101 1121","payment_card_type":"VISA","payment_currency":"TRY","payment_id":15,"payment_method":"CRDC","payment_ref":"INTEGRATION","payment_status":"INT","place_id":"311","request_id":"991"}]} --batchresponse_fdffc443-4f7c-4be7-bbb6-4804476baa4d Content-Type: application/http Content-Transfer-Encoding: binary

HTTP/1.1 404 Not Found Content-Type: application/json; odata.metadata=minimal OData-Version: 4.0

{"error":{"code":"","message":"No HTTP resource was found that matches the request URI 'https://XXXX-dev.corporate.ifs.com/FSMDEV/odata/payment?$filter=request_id eq '991''."}} --batchresponse_fdffc443-4f7c-4be7-bbb6-4804476baa4d--

Is the above possible?

Thank you in advance for any assistance.

I have played around a little bit with XPath as well but have been unsuccessful thus far, though it may just be my syntax that is out. I'm also looking into maybe using a different changeset, but I can't quite join everything together.


1 reply

Userlevel 6
Badge +17

as noted in our private chat, you must specify the key to delete a row using a syntax like 
DELETE https://my-fsm-server.corporate.ifs.com/FSMDEV/odata/payment('18')
you would have to extract it from the body you receive in the response from a previous query using GET

needs to be done programmatically, can’t be done in a single changeset

Reply