简体   繁体   中英

Microsoft Graph API move junk email into Inbox not working (giving 400 response)

For ref I am sharing code here. For the documentaiton I am following this link https://learn.microsoft.com/en-us/graph/api/message-move?view=graph-rest-1.0&tabs=http

but it is giving 400 error response在此处输入图像描述

 def move_junk_to_inbox(message_id: str): status, access_token = get_token() headers = { "Content-Type": "application/json", "Authorization": access_token # "Prefer": 'outlook.body-content-type="text"', } folder_name = "Inbox" base_url = "https://graph.microsoft.com/v1.0/" end_point = f"users/{email_id}/messages/{message_id}/move" move_url = base_url + end_point body = {"destinationId": folder_name} response = requests.post(move_url, headers=headers, data=body, timeout=TIMEOUT) return response

I was able to solve it by using move event using this doc https://learn.microsoft.com/en-us/graph/api/message-move?view=graph-rest-1.0&tabs=http

 def move_email(self, email_id: str, message_id: str, target_folder: str): try: access_token, status = self.get_token() if not status: raise "Failed to generate auth token" headers = { "Content-Type": "application/json", "Authorization": access_token, "Prefer": 'outlook.body-content-type="text"', } body = {"destinationId": target_folder} end_point = f"{self.base_url}/users/{email_id}/messages/{message_id}/move" res = requests.post(end_point, headers=headers, json=body) return res.json() except Exception as e: err = f"Error move mail: {str(e)}" return None

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM