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

Stefan Willebrand October 27, 2019

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

0 votes
Stefan Willebrand October 28, 2019

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.

Stefan Willebrand October 28, 2019

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;
}
}
}

}

0 votes
Stefan Willebrand October 27, 2019

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;
}
}

Stefan Willebrand October 27, 2019

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events