0

So I am currently working with the ZenDesk API. I am creating many users using the batch CreateUser method that takes an array of up to 100 user objects. Now, for some reason, some users fail to generate. Therefore, I wanted to obtain the result of the JobStatus after creating the users so that I can identify the problem easily. The issue is that the result variable is null after performing the CreateUsers() method.

Some sample code:

public static void createEndUsers(Zendesk zd){      
    for(Organization org : zd.getOrganizations()){
        List<User> usersList = getUsersPerOrg(org, 0)
        JobStatus js = zd.createUsers(usersList);

        List<T> resultElements = js.getResults(); 
    }
}

Why is getResults() returning null in this instance? Is it because the operation has not yet been performed when it reaches that part of the code? How can I make sure that I "wait" until the result is ready before I try to access it?

Kristianasp
  • 61
  • 11

1 Answers1

0

If you have a look at the posssible values from org.zendesk.client.v2.model.JobStatus.JobStatusEnum you will notice that the job may be queued for execution or it could still be running at the time that the job status was returned by the operation org.zendesk.client.v2.Zendesk#createUsers(org.zendesk.client.v2.model.User...).

As can be seen from the Zendesk Documentation for createUsers Operation

This endpoint returns a job_status JSON object and queues a background job to do the work. Use the Show Job Status endpoint to check for the job's completion.

only when the job is completed, there will be a corresponding result delivered for the operation.

A possible solution in your case would be to check (possibly in a separate thread) every 500ms whether the job status is not queued or not running (otherwise said whether it completed) and if it successfully completed to retrieve the results.

marius_neo
  • 1,535
  • 1
  • 13
  • 28