def createBulkImportJob(file, partitionName=None, listId=None, format='csv', lookupField=fieldNames.id): # creates dictionary to pass with csv file to API call files = {'file': ('leads.' + format, file)} # defining a data json for the parameters to be sent to the API data = { 'access_token': identity.getAccessToken(), 'format': format, 'lookupField': lookupField } #checks to add values to request if not none type if listId is not None: data['listId'] = listId if partitionName is not None: data['partitionName'] = partitionName # sending post request. r = requests.post(url=identity.baseBulk + "/v1/leads.json", files=files, data=data).json() return r
def describe2Lead(): # defining a params dict for the parameters to be sent to the API. PARAMS = {'access_token': identity.getAccessToken()} # sending get request data = requests.get(url=identity.baseRest + "/v1/leads/describe2.json", params=PARAMS).json() return data
def getBulkExtractJobs(status=bulkStatusAll): # defining a params dict for the parameters to be sent to the API. PARAMS = {'access_token': identity.getAccessToken(), 'status': status} # sending get request data = requests.get(url=identity.baseBulk + "/v1/leads/export.json", params=PARAMS).json() return data
def listCustomObjects(): # defining a params dict for the parameters to be sent to the API. PARAMS = {'access_token': identity.getAccessToken()} # sending get request data = requests.get(url=identity.baseRest + "/v1/customobjects.json", params=PARAMS).json() return data
def getStaticList(id): # defining a params dict for the parameters to be sent to the API. PARAMS = {'access_token': identity.getAccessToken()} # sending get request data = requests.get(url=identity.baseRest + "/asset/v1/staticList/{:d}.json".format(id), params=PARAMS).json() return data
def getBulkImportWarnings(batchId): # defining a params dict for the parameters to be sent to the API. PARAMS = {'access_token': identity.getAccessToken()} # sending get request data = requests.get(url=identity.baseBulk + "/v1/leads/batch/" + batchId + "/warnings.json", params=PARAMS).json() return data
def retrieveBulkExtractData(exportId): # defining a params dict for the parameters to be sent to the API. PARAMS = {'access_token': identity.getAccessToken()} # sending get request. Doesn't return json as it returns csv which is parsed with .text data = requests.get(url=identity.baseBulk + "/v1/leads/export/" + exportId + "/file.json", params=PARAMS).text return data
def pollBulkExtractJob(exportId): # defining a params dict for the parameters to be sent to the API. PARAMS = {'access_token': identity.getAccessToken()} # sending get request data = requests.get(url=identity.baseBulk + "/v1/leads/export/" + exportId + "/status.json", params=PARAMS).json() return data
def getLeads(type, value, fields=[]): # defining a params dict for the parameters to be sent to the API. PARAMS = { 'access_token': identity.getAccessToken(), 'filterType': type, 'filterValues': value, 'fields': fields } # sending get request data = requests.get(url=identity.baseRest + "/v1/leads.json", params=PARAMS).json() return data
def deleteLead(id): # defining a data json for the parameters to be sent to the API data = json.dumps({'input': [{fieldNames.id: id}]}) # sending delete request r = requests.delete(url=identity.baseRest + "/v1/leads.json", headers={ 'Content-type': 'application/json', 'Authorization': 'Bearer ' + str(identity.getAccessToken()) }, data=data).json() return r
def createLead(type, input, action='createOrUpdate'): # defining a data json for the parameters to be sent to the API data = json.dumps({'action': action, 'lookupField': type, 'input': input}) # sending post request. r = requests.post(url=identity.baseRest + "/v1/leads.json", headers={ 'Content-type': 'application/json', 'Authorization': 'Bearer ' + str(identity.getAccessToken()) }, data=data).json() return r
def createBulkExtractJob(fields, filter, format='CSV'): # defining a data json for the parameters to be sent to the API data = json.dumps({'fields': fields, 'format': format, 'filter': filter}) # sending post request. r = requests.post(url=identity.baseBulk + "/v1/leads/export/create.json", headers={ 'Content-type': 'application/json', 'Authorization': 'Bearer ' + str(identity.getAccessToken()) }, data=data).json() return r
def getCustomObjects(apiName, value, fields=[]): # defining a params dict for the parameters to be sent to the API. PARAMS = { 'access_token': identity.getAccessToken(), 'filterType': 'dedupeFields', 'filterValues': value, 'fields': fields } # sending get request data = requests.get(url=identity.baseRest + "/v1/customobjects/" + apiName + ".json", params=PARAMS).json() return data
def cancelBulkExtractJob(exportId): # defining a data json for the parameters to be sent to the API data = json.dumps({}) # sending post request r = requests.post(url=identity.baseBulk + "/v1/leads/export/" + exportId + "/cancel.json", headers={ 'Content-type': 'application/json', 'Authorization': 'Bearer ' + str(identity.getAccessToken()) }, data=data).json() return r
def deleteCustomObjects(apiName, input): # defining a data json for the parameters to be sent to the API data = json.dumps({'deleteBy': 'dedupeFields', 'input': input}) # sending post request. r = requests.post(url=identity.baseRest + "/v1/customobjects/" + apiName + "/delete.json", headers={ 'Content-type': 'application/json', 'Authorization': 'Bearer ' + str(identity.getAccessToken()) }, data=data).json() return r