Using sending bulk events API , how can you identify which event has successfully passed and which one has any issue?

Hello,
I’m pushing events into DHIS2 via the “/api/events” API. But, I have included multiple events in the request body in the events array, as seen below:

events =[{'program': 'WDxDNw07AX1', 'orgUnit': 'JZ7b9o5QLlr', 'eventDate': '2023-03-02', 'dataValues': [...]}, 
{'program': 'WDxDNw07AX1', 'orgUnit': 'JZ7b9o5QLlr', 'eventDate': '2023-03-01', 'dataValues': [...]}, 
{'program': 'WDxDNw07AX1', 'orgUnit': 'JZ7b9o5QLlr', 'eventDate': '2023-03-06', 'dataValues': [...]]

In the response, I receive an array that looks like this:

[{'responseType': 'ImportSummary', 'status': 'ERROR', 'importCount': {...}, 'conflicts': [...], 'reference': 'yZovJ1WJPJ5'}, {'responseType': 'ImportSummary', 'status': 'ERROR', 'importCount': {...}, 'conflicts': [...], 'reference': 'OVoPrRRYULs'}, {'responseType': 'ImportSummary', 'status': 'SUCCESS', 'importCount': {...}, 'conflicts': [...], 'reference': 'GBEP5FU3EOG', 'href': 'https://hisptz.com/southsudan/api/events/GBEP5FU3EOG'}]

Now I’m having trouble determining which events were successfully pushed from my request body and which events had errors because the return answer was not in the sequence that I had specified in the request body. So, how do I map the event from the request body to the returned response? Is there an ID or index in the API answer that I can use to map the event?

Hi @Yash_Bhindi

Welcome to the community! :tada:

Thank you for your question. Could you post the full response? The {…} is the part that might contain the details needed to find the answer.

Might also give a clue…

Here is the complete request body and the received response:
Request body:

[
  {
    'program': 'WDxDNw07AX1',
    'orgUnit': 'JZ7b9o5QLlr',
    'eventDate': '2023-03-09',
    'dataValues': [
      {
        'dataElement': 'KvMbmH5EVVx',
        'value': None
      },
      {
        'dataElement': 'gcAw7Om28x8',
        'value': 'TBD'
      }
    ],
    'indexOrder': 0
  },
  {
    'program': 'WDxDNw07AX1',
    'orgUnit': 'JZ7b9o5QLlr',
    'eventDate': '2023-03-16',
    'dataValues': [
      {
        'dataElement': 'KvMbmH5EVVx',
        'value': 12
      },
      {
        'dataElement': 'gcAw7Om28x8',
        'value': 'ABC'
      }
    ],
    'indexOrder': 1
  },
  {
    'program': 'WDxDNw07AX1',
    'orgUnit': 'JZ7b9o5QLlr',
    'eventDate': '2023-03-17',
    'dataValues': [
      {
        'dataElement': 'KvMbmH5EVVx',
        'value': 44
      },
      {
        'dataElement': 'gcAw7Om28x8',
        'value': 'INF'
      }
    ],
    'indexOrder': 2
  },
  {
    'program': 'WDxDNw07AX1',
    'orgUnit': 'JZ7b9o5QLlr',
    'eventDate': '2023-03-07',
    'dataValues': [
      {
        'dataElement': 'KvMbmH5EVVx',
        'value': 3
      },
      {
        'dataElement': 'gcAw7Om28x8',
        'value': 'FOO'
      }
    ],
    'indexOrder': 3
  }
]

Response:

[
  {
    'responseType': 'ImportSummary',
    'status': 'ERROR',
    'importCount': {
      'imported': 0,
      'updated': 0,
      'ignored': 1,
      'deleted': 0
    },
    'conflicts': [
      {
        'object': 'gcAw7Om28x8',
        'value': "Value 'TBD' is not a valid option code of option set: t0XDlbbg241"
      }
    ],
    'reference': 'JCDnEAvxVWs'
  },
  {
    'responseType': 'ImportSummary',
    'status': 'ERROR',
    'importCount': {
      'imported': 0,
      'updated': 0,
      'ignored': 1,
      'deleted': 0
    },
    'conflicts': [
      {
        'object': 'gcAw7Om28x8',
        'value': "Value 'ABC' is not a valid option code of option set: t0XDlbbg241"
      }
    ],
    'reference': 'lVelIduPlv1'
  },
  {
    'responseType': 'ImportSummary',
    'status': 'SUCCESS',
    'importCount': {
      'imported': 1,
      'updated': 0,
      'ignored': 0,
      'deleted': 0
    },
    'conflicts': [ ],
    'reference': 'snPYZxgm1Ki',
    'href': 'https://hisptz.com/southsudan/api/events/snPYZxgm1Ki'
  },
  {
    'responseType': 'ImportSummary',
    'status': 'SUCCESS',
    'importCount': {
      'imported': 1,
      'updated': 0,
      'ignored': 0,
      'deleted': 0
    },
    'conflicts': [],
    'reference': 'x8Smu5tCGLf',
    'href': 'https://hisptz.com/southsudan/api/events/x8Smu5tCGLf'
  }
]

As you can see, the response lacks an index, so how can I tell which array member in the response corresponds to which event in the request body?

The issue here is that the data element ‘gcAw7Om28x8’ has an option set but ‘TBD’ and ‘ABC’ are not the correct options or not entered properly.

When you look up instance/api/dataElements/gcAw7Om28x8.json?fields=id,name,optionSet[name,options[name,code]], what do you find? Are you able to see TBD and ABC as code or name?

Thanks!

Yes, that’s correct; I purposefully passed the invalid option. However, let’s say I passed four event programs in the request body array, and the response array contains four elements describing the status of each event (SUCCESS or ERROR), but this response array is not in the same order as the events I passed in the request body. It does not have an index, such as which event is ERROR or which is SUCCESS; it just has two properties, ‘object’ and ‘value’ (in case of error). Using this, how would I know which of the four events programs I’ve passed has the error?
Did you get my point?

Thanks

In that case, I think you need to use the object’s ID

1 Like