Is there a way of getting a list of customers in a project through API?

Harry Bob
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 24, 2020

Hello,

 

Is there a way of getting a list of customers in a project through API? I can get a list of users in an organization but the users who are not part of any organization I am unable to see how I can get a list of these users.

 

Thanks!

3 answers

1 vote
Angélica Luz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 28, 2020

Hello Harry,

Thanks for reaching out to Community!

It's possible to get all customers of a service desk project using API. For that, please use the endpoint below:

GET /rest/servicedeskapi/servicedesk/{serviceDeskId}/customer

This method returns a list of the customers on a service desk.

Please, give it a try and let us know how it goes.

Regards,
Angélica

Charles Johnson July 20, 2020

This call will only retrieve 50 results at a time. :-\ (regardless of the limit parameter chosen)

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 21, 2020
Charles Johnson July 21, 2020

Yes, I've tried that.  it always defaults to '50', regardless of the value provided in the limit parameter.  (using Cloud)

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 21, 2020

Hi @Charles Johnson , 

The page I am referring to says that in some cases only a limited subset of results is returned and, in those cases, you can use pagination to get all the results.

In short: 

You get the first 50 results by calling:  

Then to get the next 50 results you call:

 

 

And so on. Please refer to the documentation (pagination section) for more details: 

Charles Johnson July 21, 2020

My experience thus far when using the 'limit' parameter:

https://XXX.atlassian.net/rest/servicedeskapi/servicedesk/{serviceDeskId}/customer?limit=100

it will always revert back to '50' .. and the response's "isLastPage" value is always "true"
{ "size": 50, "start": 0, "limit": 50, "isLastPage": true,....

(i know i have more than 50 customers :-) )

I've tried adding "&size=100" as a parameter (as the pagination page suggests) but it only ever & always reverts to '50' as the maximum number of record returns.
Even if i had to loop through pages (using & incrementing the 'start' parameter as in your example...which would be very inconvenient) the response always shows "isLastPage: true" .. so i have no programable way to determine if i've received ALL the pages or not.  

If you know of the exact incantation to pull back all the records (no pagination required) that would solve my needs for using this API.  Otherwise, i keep bumping into "50" with no clear stopping point ¯\_(ツ)_/¯

Harry Bob
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 21, 2020

@Charles Johnson

 

The maximum results it will return at one time is 50 and I don't believe there is a way around it. You'll just have to manually adjust the 'start' query and go through the list until you get to the end. 

So you'd have to start at:

0-49

https://XXXXXX.atlassian.net/rest/servicedeskapi/servicedesk/1/customer

50-99

https://XXXXXX.atlassian.net/rest/servicedeskapi/servicedesk/1/customer?start=50

100-49

https://XXXXXX.atlassian.net/rest/servicedeskapi/servicedesk/1/customer?start=100

 

Hope that helps

Like Dario B likes this
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 22, 2020

Thanks for explaining this in more details @Harry Bob .

Also, I can confirm there is no way around the hard limit of 50 for this endpoint and therefore the only way to get all the results is to use pagination (the 'start' parameter to cycle through all the results).

Cheers,
Dario

Like Harry Bob likes this
Charles Johnson July 22, 2020

Rats.  The pagination requirement complicates my process.
What about the "isLastPage" value always being "true"? 
Is that by design, or should it say "false" if start at '0' and have 400 customers that I have to page through incrementally?  (secret question: how do i know how many times i have to page through another set of '50' before i can stop the process loop?)

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 24, 2020

Hi @Charles Johnson ,

 

After a bit of research I have found the below bug ticket opened some time ago in order to address the pagination issues with this endpoint:

 

Since the description was incomplete, I have added below details to it:

Other issues with this endpoint:

  • Even if not specified on the documentation, this is an experimental endpoint. Therefore, you must add the X-ExperimentalApi: opt-in header in your requests or it won't work.
  • The isLastPage attribute is returning as true on each request.
  • The start and limit  attributes do not reflect the values passed as url parameters.
    For example, callling: https://XXXX.atlassian.net/rest/servicedeskapi/servicedesk/12/customer?start=10&limit=10 returns:
    {
        "size": 10,
        "start": 0,
        "limit": 50,
        "isLastPage": true,
    ...
    

 

 

I have also forwarded this information to the developer assigned to this ticket.

 

Please vote for the above bug ticket and set yourself as a watcher so that you will be notified in case of any update/progress. The bug will be addressed according to the Atlassian Cloud bug fixing policy.

 

 

Cheers,
Dario

Like Angélica Luz likes this
0 votes
Robert Condon February 6, 2024

Has anyone looked in to the fact that, even with Pagination, this will only return a maximum of between 9950-10000 results.

rest/servicedeskapi/servicedesk/1/customer?start=9950 and above always returns 

"isLastPage": true,

 

0 votes
Tim Washum March 27, 2023

Here is a python script to query for a customer

import requests
import json

url = "https://xxxx.atlassian.net/rest/servicedeskapi/servicedesk/1/customer"
email_to_find = "johndoe@gmail.com"

payload = ""
headers = {
        'X-ExperimentalApi': 'opt-in',
        'Authorization': 'Basic INSERTKEY',
        'Cookie': ''
}

response = requests.request("GET", url, headers=headers, data=payload)

while True:
    response_data = response.json()

    # Loop through each customer in the response and check if the email matches
    for customer in response_data['values']:
        if customer.get('emailAddress') == email_to_find:
            print("Found the email address!")
            print(json.dumps(customer, indent=4))
            break
   
    # Check if there are more pages of results to retrieve
    if response_data['isLastPage']:
        break
    else:
        # Get the next page of results using the "next" link in the API response
        next_link = response_data['_links'].get('next')
        if next_link:
            response = requests.get(next_link, headers=headers)
        else:
            break

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events