If you are using Python as a programming language and interested in integrating MindBody Online then you are for a treat. As today we are going to share a tutorial on Mindbody API Integration using python with example and code. This complete tutorial is guided step by step so you can understand the process easily.
MindBody is a software for class- and appointment-based businesses which is used by 50000+ business worldwide. This cloud-based business management software is mainly used by Yoga, Spa, dance school etc.
Mindbody API Integration Using Python With Example: Steps By Step Guide
Step 1: API Credentials Required
Before integration of API, API Credentials and Site Credentials are required. To get this you should have developer account at https://developers.mindbodyonline.com/ or login to developer account. After login you can find easily API Credentials at right side and Site Credentials at left side as shown in the image below.
Step 2: Create A Folder
To start integration first make a folder and name it Mindbody or whatever in your mind. In Mindbody folder create a file and name it as BasicRequestHelper.py. Copy the codes given below and paste it in BasicRequestHelper.py
SOURCE_NAME = "XXXXXXXXXX" SOURCE_PASSWORD = "XXXXXXXXXXX" USER_NAME = "Siteowner" USER_PASSWORD = "apitest1234" SITE_IDS = [-99] def FillArrayType(service, elems, arrayType, elemName=None): if elemName == None: elemName = arrayType.lower() if elems != None: ArrayObject = service.factory.create("ArrayOf" + arrayType) setattr(ArrayObject, elemName, elems) return ArrayObject else: return None def FillDefaultCredentials(service, request, siteIDs): sourceCreds = service.factory.create('SourceCredentials') sourceCreds.SourceName = SOURCE_NAME sourceCreds.Password = SOURCE_PASSWORD sourceCreds.SiteIDs.int = siteIDs userCreds = service.factory.create('UserCredentials') userCreds.Username = USER_NAME userCreds.Password = USER_PASSWORD userCreds.SiteIDs.int = siteIDs request.SourceCredentials = sourceCreds request.UserCredentials = userCreds request.XMLDetail = "Full" request.PageSize = 25 request.CurrentPageIndex = 0 return request def CreateBasicRequest(service, requestName, siteIDs=SITE_IDS): request = service.factory.create(requestName) if hasattr(request, 'Request'): request = request.Request return FillDefaultCredentials(service, request, siteIDs)
Step 3: Enter/Replace Your Credential Details
In the above code enter your own credential as explained in step 1
SOURCE_NAME = "XXXXXXXXXX" //Replace xxxxxx with your own credential s SOURCE_PASSWORD = "XXXXXXXXXXX" USER_NAME = "Siteowner" //These are default Sandbox login details use it for testing or replace it by your own credential s USER_PASSWORD = "apitest1234" SITE_IDS = [-99]
Step 4: Create New File In Folder
Create GetAppointment.py file in Mindbody folder and copy the code given below in GetAppointment.py file
from datetime import datetime from suds.client import Client import BasicRequestHelper from SiteService import SiteService class AppointmentService(): serviceName = "Appointment" urlService ="https://api.mindbodyonline.com/0_5/" + serviceName + "Service.asmx?wsdl" service = Client(urlService) def CreateBasicRequest(self, requestName): return BasicRequestHelper.CreateBasicRequest(self.service, requestName) def GetBookableItems(self): request = self.CreateBasicRequest("GetBookableItems") sessionType = SiteService().GetSessionTypes() sessionTypeIds = self.parseSessionTypesId(sessionType) request.SessionTypeIDs = BasicRequestHelper.FillArrayType(self.service, sessionTypeIds, "Int") request.StartDate = raw_input("Please Enter startDate in the format of YYYY-MM-DD :") request.EndDate = raw_input("Please Enter startDate in the format of YYYY-MM-DD :") print self.service.service.GetBookableItems(request) def parseSessionTypesId(self,data): sessionType_array =  for x in data.SessionTypes.SessionType: sessionType_array.append(x.ID) return sessionType_array AppointmentService().GetBookableItems()
Step 5: Create Another New File
Create a new file named SiteService.py and copy the codes given below in it.
import BasicRequestHelper from suds.client import Client from datetime import datetime class SiteService(): serviceName = "Site" urlService = "https://api.mindbodyonline.com/0_5/" + serviceName + "Service.asmx?wsdl" service = Client(urlService) def CreateBasicRequest(self, requestName): return BasicRequestHelper.CreateBasicRequest(self.service, requestName) def GetSessionTypes(self, programIds=None, onlineOnly=False): request = self.CreateBasicRequest("GetSessionTypes") request.ProgramIDs = BasicRequestHelper.FillArrayType(self.service, programIds, "Int") request.OnlineOnly = onlineOnly return self.service.service.GetSessionTypes(request)
Step 6: Execution of programs
Open the terminal and go to the directory(Mindbody) which contained all the above files. Then hit “python GetAppointment.py”
You will get error regarding to suds dependency. To overcome this problem run this command in the terminal “pip install suds”
Or you can download it from https://pypi.python.org/pypi/suds and unzip the file in project directory(Mindbody ). Then run it again you will asked to enter startDate and endDate as displayed in the below image. Please provide dates in right format else you will prompt to error.
After providing dates you will get result as show below.