4

I was able to connect to Mind Body api and run a simple command to get all clients data

from Helper.ClientService import ClientServiceCalls

calls = ClientServiceCalls()
clients = calls.GetAllClients()
print(clients)

the server will respond with these information:

(GetClientsResult){
   Status = "Success"
   ErrorCode = 200
   XMLDetail = "Full"
   ResultCount = 4503
   CurrentPageIndex = 0
   TotalPageCount = 181
   Clients = 
      (ArrayOfClient){
         Client[] = 
            (Client){
               MobileProvider = None
               AppointmentGenderPreference = "None"
               Gender = "Female"
               IsCompany = False
               LiabilityRelease = False
               PromotionalEmailOptIn = True
               CreationDate = 2017-02-23 00:00:00
               Liability = 
                  (Liability){
                     IsReleased = False
                     AgreementDate = None
                     ReleasedBy = None
                  }
               UniqueID = 100015484
               ID = "100015484"
               FirstName = "Sdfoij"
               LastName = "[asodfj"
               EmailOptIn = True
               State = "CA"
               Country = "US"
               BirthDate = None
               FirstAppointmentDate = 2017-03-03 00:00:00
               HomeLocation = 
                  (Location){
                     SiteID = -99
                     BusinessDescription = ""The MINDBODY Health Club Demo is awesome." - Anonymous (but probably someone cool and smart)"
                     AdditionalImageURLs = ""
                     FacilitySquareFeet = None
                     TreatmentRooms = None
                     HasClasses = True
                     PhoneExtension = None
                     ID = 1
                     Name = "Clubville"
                  }
               PhotoURL = "https://clients.mindbodyonline.com/studios/DemoAPISandboxRestore/clients/100015484_large.jpg?v=98"
               IsProspect = False
               Status = "Active"
               ContactMethod = 1
            }.... **and continue printing other client informations**

     }
 }

now The issue is i want to extract these info from it,

Client Email, Client Name, Client Phone Number, Client Status (active or inactive), Client Birthday, Client Address, Most Recent Visit Date, Most Recent Visit Description, Start Date, Custom Field(s)

But i don't know what Library I can use to parse through this output, I am thinking about Beautiful Soup but I am not really sure,

I am really newbie to working with apis, so if anyone could give me an idea about how to do this it would be really great.

Ayyoub
  • 4,581
  • 2
  • 19
  • 32
  • Same here Josh, I am really confused on how to deal with this api, anyway if you have any info that could put me on the right track please don't hesitate on mentioning it. thanks – Ayyoub Mar 29 '17 at 19:16
  • My guess is that they are using [SOAP](https://en.wikipedia.org/wiki/SOAP) since one of the ClientService uses the package suds. So you may want to look at an XML parser for the response. – aquil.abdullah Mar 29 '17 at 19:17
  • Checkout this link [her](https://developers.mindbodyonline.com/Documentation/WorkingWithSOAP#xmldetail) It has a bit of a description of their XML response. – aquil.abdullah Mar 29 '17 at 19:22
  • please help me, the answer you provided was throwing error, can you give another solution ? – Ayyoub Mar 31 '17 at 16:22

1 Answers1

3

OK, I did a search on mindbody WSDL in the googs and got back the following link: https://api.mindbodyonline.com/0_5/SiteService.asmx?wsdl. From looking at the code in the API examples it looks like they are definitely using SOAP. My recommendation is that you try the following:

from suds.client import Client
from Helper.ClientService import ClientServiceMethods
calls = ClientServiceMethods()
clients = calls.GetAllClients()
client_dict = Client.dict(clients)

Or take a look at this link for taking a response and turning it into a dict.

Community
  • 1
  • 1
aquil.abdullah
  • 3,059
  • 3
  • 21
  • 40
  • from running your sample code i got TypeError: 'NoneType' object is not iterable – Ayyoub Mar 29 '17 at 19:58
  • any thoughts ?? – Ayyoub Mar 29 '17 at 20:13
  • Hmm. OK, I don't have this API. So I can't run the code directly. Here is what I would suggest. Run `type(clients)` and `dir(clients)` and let me know what results you get. It may be possible to access the fields you want directly. – aquil.abdullah Mar 31 '17 at 18:59
  • i found , when running print(type(clients)) |||| and from runing print(type(calls)) i got – Ayyoub Mar 31 '17 at 19:03
  • It looks like you are using the wrong API call. `ClientServiceCalls` only displays the results to stdout. I'll update my answer. – aquil.abdullah Mar 31 '17 at 19:14
  • You're right running this type of client_dict did return but i am little bit confused on how i can access the info i want in this dic because from looking at it i think its not a regular python dic ?? – Ayyoub Mar 31 '17 at 19:21
  • Once again, I do not have the API so I cannot help you directly, but I believe that it is a nested dict. which means that you can access it via `client_dict["field"]["field"]` Can you tell me the results of `type(clients)` and `dir(clients)`? – aquil.abdullah Mar 31 '17 at 19:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/139624/discussion-between-ayoub-and-aquil-abdullah). – Ayyoub Mar 31 '17 at 19:29
  • running type clients returned and running dir clients ['Clients', 'CurrentPageIndex', 'ErrorCode', 'ResultCount', 'Status', 'TotalPageCount', 'XMLDetail', '__contains__', '__delattr__', '__doc__', '__getitem__', '__init__', '__iter__', '__keylist__', '__len__', '__metadata__', '__module__', '__printer__', '__repr__', '__setattr__', '__setitem__', '__str__', '__unicode__'] returned – Ayyoub Mar 31 '17 at 19:31
  • any luck Abdullah ? – Ayyoub Mar 31 '17 at 19:45