Add costumer to service desk with api powershell gives a timeout after 2 time

Hi,

I’ve created a powershell script that extracts our azure AD and import all the users as costumers in our service desk.
In this script I use 2 api’s. One api adds the costumer to our Jira. And the other adds that costumer to a specific service desk.
For the first I use this api:

Invoke-RestMethod -Uri "https://***.atlassian.net/rest/api/2/user?username=$($s.UserPrincipalName)" -ContentType "application/json;charset=UTF-8" -WebSession $mysession

This api works fine.
And for the second I use this api:
Invoke-RestMethod -Method Post -Uri https://***.atlassian.net/rest/servicedeskapi/servicedesk/6/customer -Body $body -ContentType "application/json;charset=UTF-8" -WebSession $mysession

This api works fine once or twice. But after I loop more then 2 time through this api. I get a time-out error. I’ve sent this to support and after a few tries we saw that if my request goes through, it succeeds. But after 2 times my request doesn’t go through anymore.
When support tries my script in bash it works fine. So is there any known problem with powershell and those api’s? Because I need to do this in powershell.

Thanks!
Regards,
Nick

Hello Nick,

I don’t know anything specific about powershell that should be causing this, so it may have to do with different defaults than what the support engineer was using in bash.

Can you please send me a message with the support ticket (or if its still open, mention my name on it) and I’ll read in more detail what they tried.

In the mean time, it may be worth trying some options like -DisableKeepAlive and -PreserveAuthorizationOnRedirect.

Cheers
Matt

1 Like

Hi Matt,

Thanks for your response but I’ve finally found the problem!
I was running this script on a windows server and that’s where I got the problem.
But now I’ve tried running it on my local machine and everything works fine…

So sorry to bother you and maybe this can help someone else.

Cheers,
Nick

I don’t suppose you’d be willing to upload your full script (minus api keys, url, etc.)?