Thursday, July 21, 2022

How to make Batch/Bulk requests using Oracle Fusion Rest APIs

 Oracle Fusion provides a lot of rest APIs that we can use in our integrations.

In this post we will see how we can create AP invoices in Bulk using Invoice rest API to avoid multiple calls to Oracle Fusion.

For example if we have 10 invoices, we will need to call this API 10 times  if we create one by one approach. By using bulk/batch approach we can create all 10 invoices in one call only.

We can get the Invoice rest APIs from below link for 22b Release:

https://docs.oracle.com/en/cloud/saas/financials/22b/farfa/api-invoices.html 

The complete URL for invoice resource endpoint will be like below:

https://xxxx-dev1.fa.us6.oraclecloud.com/fscmRestApi/resources/11.13.18.05/invoices

In the above link if we go to Create an invoice, we will find that the method supported is POST and content types supported are:

a). application/vnd.oracle.adf.resourceitem+json

b). application/json

Using these content types we can create only one invoice at a time.

But our requirement is to create multiple invoices in batch/bulk using this rest endpoint, So we need to use different content type which is:

 application/vnd.oracle.adf.batch+json

We can get more details about creating batch requests from below links:

https://docs.oracle.com/en/cloud/saas/financials/22b/farfa/Batch_Actions.html

https://docs.oracle.com/en/cloud/paas/app-builder-cloud/consume-rest/advanced-tasks.html#GUID-3F3F2D10-CF68-46D1-AF83-A52988CF817B

Note:- 

REST APIs support executing multiple operations in a single roundtrip using a batch request. The data is committed at the end of the request. However, if one request part in a batch request fails, then all changes are rolled back and an error response is returned. 

A batch request can consist of a combination of create, update, get, delete, invoke custom methods and describe requests. The path parameter and the payload needs to be the same as what you use to invoke the request directly. The get method supports the same URL parameters in the batch request as a separate HTTP request.

We can combine multiple operations into a single HTTP request (batch actions) to improve performance. The request body is a JSON object with a field named parts, which is an array of objects. Each object in the array contains:


a). A unique ID
b). A relative path to the resource
c). An operation
d). (Optional) A payload

Now let us see how we can test this using POSTMAN.

The request will look like below :

Endpoint URL: https://xxxx-dev1.fa.us6.oraclecloud.com/fscmRestApi/resources/11.13.18.05

Method: POST

Content-Type :   application/vnd.oracle.adf.batch+json

Sample request payload:  This will be based on parts, as many invoices we have to create.Here we have 2  so we have 2 parts.

 

{
    "parts": [
    {
        "id": "part1",
        "path": "/invoices",
        "operation": "create",
        "payload": {
        "InvoiceNumber": "TEST_BULK_INV_CREATE_1",
        "InvoiceCurrency": "USD",
        "InvoiceAmount": 200,
        "InvoiceDate": "2022-07-07",
        "BusinessUnit": "USA BU",
        "Supplier": "TestSupplier02",
        "SupplierSite": "US Office01",
        "Description": "Test Invoice",
        "invoiceLines": [{
            "LineNumber": 1,
            "LineAmount": 200
            }]  
    }

    },
  {
    "id": "part2",
    "path": "/invoices",
    "operation": "create",
    "payload": {
        "InvoiceNumber": "TEST_BULK_INV_CREATE_2",
        "InvoiceCurrency": "USD",
        "InvoiceAmount": 200,
        "InvoiceDate": "2022-07-07",
        "BusinessUnit": "USA BU",
        "Supplier": "TestSupplier02",
        "SupplierSite": "US Office01",
        "Description": "Test Invoice",
        "invoiceLines": [{
            "LineNumber": 1,
            "LineAmount": 200
            }]  
    }

  }
    ]
}

 Note:-  The path should be relative

              In the endpoint url we have used before " /invoices" and Inside the payload we have provided path as "/invoices" in each part.

 

We can see in the below screenshot , how the request would look like in POSTMAN



 

We get a successful response as below:


 We can  verify this from Oracle Fusion application as well:

Login to Fusion application -> navigator->Payables-> Invoices

Search for the invoices which we passed in the payload:

We can see that the invoices got created successfully using bulk/batch approach with the AP invoice rest API.

In the similar way we can use this approach for other resources as well.


No comments:

Post a Comment