如何使用MindBody API python获得所有客户端

2024-10-04 11:25:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我想把所有的clients using MindBody API都弄到,我试过了

from suds.client import Client
from Helper.ClientService import ClientServiceMethods

# Making a call
calls = ClientServiceMethods()
result = calls.GetAllClients()
client_dict = Client.dict(result)
clients = client_dict['Clients']
client_list = clients.Client # transferring clients into a python list

#printing the lenght of received clients list
print len(client_list)

上面的代码可以工作,但问题是它不会拉超过27客户端,仅此而已。 从MindBody DocsGettAllClients应该可以得到1000个客户机,一个调用的限制是1000,这意味着我可以得到1000个,但问题是我注意到至少可以得到1000个客户机,我只能得到27个客户机。在

Note: I am working with Demo Data, Sandbox which can anyone look them, I used the Sample code from their MindBody Python repository

我正在通过api获取所有客户端数据,这些客户端可以查看from here

用户名:Siteowner|密码:apitest1234


Tags: thefromimportclientapi客户端客户机result
2条回答

对于任何人谁也有这个问题,这将是一个很大的帮助你。在

when we make call GetClients, mindbody will send clients but it will represent them in form of pages so that 25 client was the first page if u want to get the next 25 client you would have to call the page indexed 2 and so on and so forth.

在代码中,这是您将如何做到这一点,使用API Example codeClientService,在GetClientsByString方法中执行此操作

def GetClientsByString(self, searchStr):
        """Convenience method to find clients containing searchStr in their name or e-mail."""
        request = self.CreateBasicRequest("GetClientsRequest")

        # Since SearchText is just a string, we can assign it directly.
        request.SearchText = searchStr
        request.CurrentPageIndex = 1 # increase this number by one each time 

        return self.service.service.GetClients(request)

我就是这样处理的;非常愿意采用一种更好的方法,而不是像API那样密集:

    clientService = ClientServiceCalls()

    #get all client IDs

    clientResponse = clientService.GetClientsByString('')
    clientList = clientResponse.Clients.Client

    clientVisitsDict = []

    for c in clientList:

        #Call get ClientVisits API on each Client ID

        clientResponseVisits = clientService.GetClientVisits(str(c.ID))

        if clientResponseVisits.Visits:
            visitsList = clientResponseVisits.Visits.Visit
            for v in visitsList:

                ### your code here

相关问题 更多 >