Example #1
0
 def post(self, data):
     self.authenticate()
     args = {'access_token': self.token}
     data = HttpLib().post("https://" + self.host + "/rest/v1/leads.json",
                           args, data)
     if not data['success']: raise MarketoException(data['errors'][0])
     return data['result'][0]['status']
Example #2
0
def handle_va_enrollment_event(sender, student, **kwargs):
    """
    set Marketo VA Learning Path Enrolled for Lead corresponding to user
    """
    if not (get_value("course_enable_marketo_integration", None) and not \
            getattr(settings.FEATURES, "COURSE_ENABLE_MARKETO_INTEGRATION", None)
            ):
        return

    logger.info(('Setting VA Learning Path Enrolled and edX registered for Lead with email {0}.').format(student.email))
    mkto_field_id_va = get_value("marketo_va_enrollment_field_id", None)
    mkto_field_id_edx = get_value("marketo_edx_enrollment_field_id", None)
    if not mkto_field_id_va:
        logger.warn(('Can\'t set VA Learning Path Enrolled for Lead with email {0}.').format(student.email))
    if not mkto_field_id_edx:
        logger.warn(('Can\'t set edX Registered for Lead with email {0}.').format(student.email))

    try:
        mc = get_marketo_client()
        status = mc.execute(method='update_lead', lookupField='email',
                            lookupValue=student.email,
                            values={mkto_field_id_va: True,
                                    mkto_field_id_edx: True})
        if status != 'updated':
            raise MarketoException({'message': "Update failed with status {0}".format(status), 'code': None})

    except MarketoException as e:
        logger.warn(('Can\'t set VA Learning Path Enrolled or edX Registered for Lead with email {0}.').format(student.email))
Example #3
0
 def get_activity_types(self):
     self.authenticate()
     args = {'access_token': self.token}
     data = HttpLib().get(
         "https://" + self.host + "/rest/v1/activities/types.json", args)
     if data is None: raise Exception("Empty Response")
     if not data['success']: raise MarketoException(data['errors'][0])
     return data['result']
Example #4
0
 def get_paging_token(self, sinceDatetime):
     self.authenticate()
     args = {'access_token': self.token, 'sinceDatetime': sinceDatetime}
     data = HttpLib().get(
         "https://" + self.host + "/rest/v1/activities/pagingtoken.json",
         args)
     if data is None: raise Exception("Empty Response")
     if not data['success']: raise MarketoException(data['errors'][0])
     return data['nextPageToken']
Example #5
0
 def get_email_content_by_id(self, id):
     self.authenticate()
     if id is None: raise ValueError("Invalid argument: required argument id is none.")
     args = {
         'access_token' : self.token
     }
     data = HttpLib().get("https://" + self.host + "/rest/asset/v1/email/" + str(id) + "/content", args)
     if data is None: raise Exception("Empty Response")
     self.last_request_id = data['requestId']
     if not data['success'] : raise MarketoException(data['errors'][0]) 
     return data['result']
Example #6
0
 def get_leads(self, filtr, values = [], fields = []):
     self.authenticate()
     values = values.split() if type(values) is str else values
     args = {
         'access_token' : self.token,
         'filterType' : str(filtr),
         'filterValues' : (',').join(values)
     }
     if len(fields) > 0:
         args['fields'] = ",".join(fields)
     data = HttpLib().get("https://" + self.host + "/rest/v1/leads.json", args)
     if data is None: raise Exception("Empty Response")
     self.last_request_id = data['requestId']
     if not data['success'] : raise MarketoException(data['errors'][0]) 
     return data['result']
Example #7
0
 def get_email_templates(self, offset, maxreturn, status=None):
     self.authenticate()
     if id is None: raise ValueError("Invalid argument: required argument id is none.")
     args = {
         'access_token' : self.token,
         'offset' : offset,
         'maxreturn' : maxreturn
     }
     if status is not None:
         args['status'] = status
     data = HttpLib().get("https://" + self.host + "/rest/asset/v1/emailTemplates.json", args)
     if data is None: raise Exception("Empty Response")
     self.last_request_id = data['requestId']
     if not data['success'] : raise MarketoException(data['errors'][0]) 
     return data['result']
Example #8
0
 def get_lead_activity_page(self, activityTypeIds, nextPageToken, batchSize = None, listId = None):
     self.authenticate()
     activityTypeIds = activityTypeIds.split() if type(activityTypeIds) is str else activityTypeIds
     args = {
         'access_token' : self.token,
         'activityTypeIds' : ",".join(activityTypeIds),
         'nextPageToken' : nextPageToken
     }
     if listId:
         args['listId'] = listId
     if batchSize:
         args['batchSize'] = batchSize
     data = HttpLib().get("https://" + self.host + "/rest/v1/activities.json", args)
     if data is None: raise Exception("Empty Response")
     if not data['success'] : raise MarketoException(data['errors'][0])
     return data
Example #9
0
    def run_request_campaign(self, campaignID, leadsID, values):
        token_list = [{
            'name': '{{' + k + '}}',
            'value': v
        } for k, v in values.items()]
        leads_list = [{'id': items} for items in leadsID]
        data = {'input': {"leads": leads_list, "tokens": token_list}}

        self.authenticate()
        args = {'access_token': self.token}
        x = "https://" + self.host + "/rest/v1/campaigns/" + str(
            campaignID) + "/trigger.json"
        result = HttpLib().post(
            "https://" + self.host + "/rest/v1/campaigns/" + str(campaignID) +
            "/trigger.json", args, data)
        if not result['success']: raise MarketoException(result['errors'][0])
        return result['success']
Example #10
0
 def get_leads_by_listId(self, listId=None, batchSize=None, fields=[]):
     self.authenticate()
     args = {'access_token': self.token}
     if len(fields) > 0:
         args['fields'] = ",".join(fields)
     if batchSize:
         args['batchSize'] = batchSize
     result_list = []
     while True:
         data = HttpLib().get(
             "https://" + self.host + "/rest/v1/list/" + str(listId) +
             "/leads.json", args)
         if data is None: raise Exception("Empty Response")
         self.last_request_id = data['requestId']
         if not data['success']: raise MarketoException(data['errors'][0])
         result_list.extend(data['result'])
         if len(data['result']) == 0 or 'nextPageToken' not in data:
             break
         args['nextPageToken'] = data['nextPageToken']
     return result_list
Example #11
0
def update_marketo_complete(course_map, course_id, email, complete=True):
    """
    update Marketo course completeness field via REST API
    """
    logger.info(('Marking course {0} complete (70%+) in Marketo '
                 'for Lead with email {1}.').format(course_id, email))
    mkto_field_id = course_map[course_id]

    try:
        mc = get_marketo_client()
        status = mc.execute(method='update_lead', lookupField='email',
                            lookupValue=email,
                            values={mkto_field_id: complete})
        if status != 'updated':
            raise MarketoException({'message': "Update failed with status {0}".format(status), 'code': None})


    except MarketoException as e:
        logger.warn(('Failed to mark course {0} complete for Lead with '
                     'email {1}.  Error: {2}').format(course_id, email, e))
Example #12
0
    def get_multiple_leads_by_filter_type(self, filterType, filterValues,
                                          fieldslist):
        self.authenticate()
        args = {'access_token': self.token}
        fieldvalstr = ','.join(filterValues)
        fields = fieldliststr = None
        if len(fieldslist) > 0:
            fieldstr = ','.join(fieldslist)
        else:
            fieldstr = 'id,lastName,firstName,updatedAt,createdAt'

        inputp = {
            'access_token': self.token,
            'filterType': filterType,
            'filterValues': fieldvalstr,
            'fields': fieldstr
        }
        data = HttpLib().get("https://" + self.host + "/rest/v1/leads.json",
                             inputp)
        if data is None: raise Exception("Empty Response")
        if not data['success']: raise MarketoException(data['errors'][0])
        return data['result']