API PATCH request to move message using python in Micro Focus RPA

336 views Asked by At

I need to create a PATCH request to move an email into a different folder, using Micro Focus Robotic Process Automation application. The syntax with this application is different to normal python and I'm having trouble figuring it out.

The below works if I remove the 'head' line, 'authorization' line, and the calling of 'header' and 'authorization' in the 'response' line

But obviously it returns a code of 401 as there's no authorization.

The authorization part throws this error: 'str' object is not callable
The headers part throws this error: 'str' object has no attribute 'items

CODE STARTS HERE:

import importlib
requests = importlib.import_module('requests')
json = importlib.import_module('json')
url = 'https://graph.microsoft.com/v1.0/users/{{account account}}/messages/' + messageID
body = "{'subject':" + careRecordNum + "' - Thank you for your enquiry. Ref: 1046120'}"
head = "{'Content-Type': 'application/json;charset=UTF-8'}"
authorization = "{'Authorization': 'Bearer '" + accessToken + "}"


response = requests.patch(url, data=json.dumps(body), headers=head, auth=authorization)
return {'response':response}`
1

There are 1 answers

0
JMH On

Figured it out:

def execute(messageID, accessToken): 
    import importlib
    requests = importlib.import_module('requests')

url = 'https://graph.microsoft.com/v1.0/users/{{user}}/messages/' + messageID + '/move'
body = "{\"destinationId\":\"{{folderID}}\"}"
head = {"Content-Type": "application/json;charset=UFT-8", "Authorization": "Bearer " + accessToken}

response = requests.post(url, data=body, headers=head)
return {'response':response}