Recent searches


No recent searches

Creating multiple different resources in a batch



Posted Aug 02, 2023

We have a workflow where we need to create a ticket for a customer, but the customer and organization may not previously exist. So we also create the organization and customer, and add the customer to the organization. What we are currently doing is:

1. create or update organization (POST /api/v2/organizations/create_or_update)

2. create customer (POST /api/v2/users) or update customer if they exist (PUT /api/v2/users/:customer_id)

3. wait 3 minutes

4. add the customer to the organization membership (POST /api/v2/organization_memberships.json)

5. wait 3 minutes

6. create the ticket using the organization_id and customer_id (as requester_id) (POST 

/api/v2/tickets)
 
We have found that we need to wait because the resources we create are not reliably available immediately. So, if we add the customer to the organization's membership immediately after creating them, one or both of those resources may not be available and we error.
 
Waiting is causing problems and is just not generally a good pattern. Is there a way I can create these connected resources in one API request? Or a way to know that the resource is available?
 
Then, as a secondary question, is there a way to do this in bulk (many customers/orgs/tickets)?

0

3

3 comments

image avatar

Greg Katechis

Zendesk Developer Advocacy

Hi Cheryl! When creating tickets with a user and org that both do not yet exist, there isn't any way to complete all three tasks in one API call. This is because the organization must first exist before it can be added to a user's profile and there is no way to batch the calls in a quick way to ensure that the indexing of the org has occurred within our database so that it would be available to be added to the user.

That being said, you could make this a slightly easier process depending on your situation:

If you are using domain mapping with an organization

1. This would be the same as your current step one...create or update the organization, except now you will want to be sure that you're adding in the `domain_names` attribute in the body, with the domains as the value. As an example:

{
"organization":
"domain_names": ["example.org"]
}

2. Here you'll actually skip to your step 6...create the ticket, but add the requester directly to the ticket as we outline in this tip. Now if you add a requester (with a domain that belongs to an org that uses domain mapping) to the ticket on creation, the user will be added to the organization right away and the ticket will reflect that as well.

If you are NOT using domain mapping with an organization

This won't be as straightforward, but you can save a step in the process from your current workflow.

1. Create the ticket the same way as I recommended in step 2 above...create the ticket with the user attached to the ticket.

2. If the org does not yet exist, create the org.

OR

2a. If the org does exist, simply add the user to the org with the POST to org memberships and you'll be all set.

3. If the org didn't previously exist, after waiting for the database to be indexed, you can then add the user to the org the same as above.

I hope that helps a bit, but let me know if you have any questions!

0


Yes, this is helpful. I can see how I can do the process with one period of waiting rather than two, since we are not using domain mapping.

When you say "after waiting for the database to be indexed", what exactly do you mean? Is there a way to know when the database has been indexed? That is what we are doing with the 3-minute timeout, but I am hoping there is a better way. 

0


hmmm. Customers can belong to multiple orgs. If I create a membership in this organization for the customer, don't I still need to indicate which organization should be associated with the ticket? And that can't happen until the membership is done and indexed.

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post