mardi 21 avril 2020

Python function with if statements for python requests query

I'm trying to add if/else statement into my function to prevent updating email (for corresponding emailId in the emailId list) with priority and notes IF notes already exist.

my code:

emailId = [732853380, 7331635674]
customerId = ['cust-12345-mer', 'cust-6789-mer']

def update_email(emailId, token, user, priority=4, notes="my note goes here"):
    headers = {     'accept': 'application/json',
                    'Content-Type': 'application/json',
                    'token': token,
                    'user': user}
    endpoint = 'request/'
    if notes != "":
        body = {'emailId': emailId, 'unassignEmail': True}
    else:
        body = {'emailId': emailId, 'unassignEmail': True, 'priority': priority,'notes': notes}
    requests.put(url = host + endpoint, headers = headers, json=body)
    return True

    for x, y in zip(emailId, customerId):
        update_email(x, token, user, priority=4, notes="my note goes here" + y )

When I run the above I receive response 'True' for each item on the list. However, the email for emailId which has no notes is not being updated with notes and priority. Could someone please help me get this right? not sure what I'm doing wrong. thanks!

Aucun commentaire:

Enregistrer un commentaire