无法在在线交换中使用ews在任务文件夹内创建任务

时间:2019-02-12 17:21:30

标签: outlook exchangewebservices office365api outlook-restapi

我正在尝试使用ews创建任务,但出现ErrorInvalidIdMalformed错误。

我已经尝试使用知名的文件夹名称和任务文件夹ID,但无法创建任务

email_id = "xyz@pqr.onmicrosoft.com"
folder_id = "tasks"
# or folder_id="id of some task folder"

RestoreTASK = b'''<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
    <t:ExchangeImpersonation>
      <t:ConnectingSID>
        %s
      </t:ConnectingSID>
    </t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<CreateItem
    xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
    MessageDisposition="SaveOnly">
    <SavedItemFolderId>
        <t:FolderId Id="%s"/>
    </SavedItemFolderId>
    <Items>
        <t:Task>
            <t:Subject>My task EWS</t:Subject>
            <t:DueDate>2006-10-26T21:32:52</t:DueDate>
            <t:Status>NotStarted</t:Status>
        </t:Task>
    </Items>
  </CreateItem>
</soap:Body>
</soap:Envelope>''' % (email_id, folder_id)

ews_api_url = 'https://outlook.office365.com/EWS/Exchange.asmx'
response = requests.post(url=ews_api_url, headers = headers, 

data = RestoreTASK)

所以我需要在soap请求中进行更改,因为我手动指定的文件夹ID是正确的。 请帮忙。

1 个答案:

答案 0 :(得分:1)

错误告诉您folderId错误,那么您如何知道其正确?您是如何首先检索FolderId的?例如,使用DistinguishedFolderId对您的XML进行简单测试就可以正常工作

<soap:Envelope 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
 </soap:Header>
<soap:Body>
<CreateItem
    xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
    MessageDisposition="SaveOnly">
    <SavedItemFolderId>
        <t:DistinguishedFolderId Id="tasks"/>
    </SavedItemFolderId>
    <Items>
        <t:Task>
            <t:Subject>My task EWS</t:Subject>
            <t:DueDate>2006-10-26T21:32:52</t:DueDate>
            <t:Status>NotStarted</t:Status>
        </t:Task>
    </Items>
  </CreateItem>
</soap:Body>
</soap:Envelope>