Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Error when creating portal customer and adding customer to a service desk in the same thread

I am using the Service Desk API https://docs.atlassian.com/jira-servicedesk/REST/3.6.2/ where I first create a customer https://docs.atlassian.com/jira-servicedesk/REST/3.6.2/#servicedeskapi/customer-createCustomer

Then I add that customer to a service desk https://docs.atlassian.com/jira-servicedesk/REST/3.6.2/#servicedeskapi/servicedesk/{serviceDeskId}/customer-addCustomers

I can see that the portal customer gets created but I get an error when i add the customer to the service desk which says that the customer cannot be found. If I close my application and just run the add customer function again everything works fine but I need to be able to do this in the same thread of I will have to build a more complex solution.

Yesterday I experimented with doing this using the same Rest Client and it worked but today it stopped working again and I have to revert to thinking about my more complex solution. 

What I am building is an Azure Function that will receive a post from a form on one of our websites and then create the customer, add the customer to a service desk and then create a customer request. Since I get an error when adding the customer to the service desk in the same call I will have to think about using Azure Durable Functions to split up this task into several Azure Functions and pass data between them based on what message the customer entered in the original form.

This seems to me as some sort of cache based bug in the Service Desk API and would be good to get some feedback on before I start building the more complex solution as a workaround.

2 answers

An update here. If I catch the exception the first time that I try to add the user to the service desk and then within that catch I try to do it again then it works. At least it is a workaround :-) 

[Test]
public async Task CreateCustomerAndAddCustomersToServiceDesk()
{
var customer = _serviceCollection.BuildServiceProvider().GetService<IJiraServiceDeskCustomerService>();

try
{
var createCustomerRequest = new CreateCustomerRequestDto()
{
FullName = "My Name",
Email = "me@test.com"
};

var t = await customer.CreateCustomerAsync(createCustomerRequest);

Assert.IsTrue(t.EmailAddress == createCustomerRequest.Email);

}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

var servicedeskService = _serviceCollection.BuildServiceProvider().GetService<IJiraServiceDeskServicedeskService>();


try
{
var t = await servicedeskService.AddCustomersToServiceDeskService(
new AddCustomersToServiceDeskRequestDto()
{
Usernames = new[] { "me@test.com" }
}, 9);
}
catch (Exception e)
{
var sd = _serviceCollection.BuildServiceProvider().GetService<IJiraServiceDeskServicedeskService>();

try
{
var q = await sd.AddCustomersToServiceDeskService(new AddCustomersToServiceDeskRequestDto()
{
Usernames = new[] { "me@test.com" }
}, 9);

}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}

Console.WriteLine(e);
throw;
}
}

This only worked the first time, now it does not work even in the second round of Exceptions.

I found another workaround that seems to work all the time now. If I in the same thread first create a customer and then call AddUsersToOrganization (which just returns null and actually does not work) and after that I call AddCustomerToServiceDesk, then it works.

Wrong again :-) :-( 

I had to create a look that tries to do this up to 50 times. It varies all the time, I have tested this a number of times now and I get from 2 tries up to 28 tries before it passes.

[Test]
public async Task CreateCustomerAndAddCustomersToServiceDesk()
{
var customer = _serviceCollection.BuildServiceProvider().GetService<IJiraServiceDeskCustomerService>();

try
{
var createCustomerRequest = new CreateCustomerRequestDto()
{
FullName = "My Name",
Email = "me@test.com"
};

var t = await customer.CreateCustomerAsync(createCustomerRequest);

Assert.IsTrue(t.EmailAddress == createCustomerRequest.Email);

}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

for (int i = 0; i < 50; i++)
{
try
{
var t = await customer.AddCustomersToServiceDesk(
new AddCustomersToServiceDeskRequestDto()
{
Usernames = new[] { "me@test.com" }
}, 9);
Console.WriteLine("User added to desk");
break;
}
catch (Exception e)
{
Console.WriteLine("User failed to add to desk");
Thread.Sleep(1000);
if (i == 49)
{
throw;
}
}
}

}

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Desk

The Complete Guide to Atlassian for ITSM

Hi Atlassian Community! This is Teresa from the Atlassian team. My colleague Paul Buffington @Buff and I are excited to share a brand new ITSM resource we’ve created – "The Complete Guide to At...

2,202 views 15 22
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you