Skip to Content
0
Jun 11, 2020 at 02:01 PM

CPI : How to find to find the last record from a JSon or xml payload.

993 Views

Hi Experts,

I need to fetch the last record from the invoice payload when the list at the end has_more = 'true' and store that ID in a property.

Any help with the groovy script or any other solution would be a great help.

Below is the sample structure:

{
  "object": "list",
  "data": [
    {
      "id": "in_ID1",
      "object": "invoice",
      "country": "US"
      "lines": {
        "object": "list",
        "data": [
          {
            "id": "il_ID1",
            "object": "line_item",
            "amount": 50000,
 }
        "has_more": false,
        "total_count": 1,
        "url": "/v1/invoices/in_ID/lines"
transfer_data": null,
      "webhooks_delivered_at": null
    }
    {
      "id": "in_ID2",
      "object": "invoice",
      "country": "US"
      "lines": {
        "object": "list",
        "data": [
          {
            "id": "il_ID111",
            "object": "line_item",
            "amount": 50000,
 }
 {
            "id": "il_ID222",
            "object": "line_item",
            "amount": 500
}
        "has_more": false,
        "total_count": 2,
        "url": "/v1/invoices/in_ID2/lines"
transfer_data": null,
      "webhooks_delivered_at": null
    }
  ],
  "has_more": true,
  "url": "/v1/invoices"
}