How to Create and Associate a Category to a Contact using EWS Managed API 2.2 - categories

Is it possible to create a Category Item Object and Associate it with a Contact using the EWS Managed API?

You can assign a Category to any Object in a Mailbox using the Categories property https://msdn.microsoft.com/en-us/library/microsoft.exchange.webservices.data.item.categories(v=exchg.80).aspx .
For a particular color/description to be show in Outlook or OWA the category you pass in must match an Item in the Master category list. You can read/modify the Master category list in a Mailbox using EWS eg https://social.msdn.microsoft.com/Forums/en-US/e5c5f072-0b5c-49ce-9db7-57f76f5e011e/edit-master-category-list-in-exchange-2010-via-ews?forum=exchangesvrdevelopment and https://social.msdn.microsoft.com/Forums/en-US/a3917500-2bbc-4def-98b4-696e49efed6f/adding-categories-to-a-users-master-category-list-in-exchange-2010-using-ews?forum=exchangesvrdevelopment

I came across this post while looking to update the master category list using EWS, but not the Managed API. In case anyone else is looking to do the same thing, here's the solution I came up with, which uses Python and requests:
import base64
import requests
from requests_ntlm import HttpNtlmAuth
# Create the XML request template for EWS
payload = r"""<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013" />
</soap:Header>
<soap:Body>
<m:UpdateUserConfiguration>
<t:UserConfigurationName Name="CategoryList">
<t:DistinguishedFolderId Id="calendar">
<t:Mailbox>
<t:EmailAddress>your_email#your_domain.com</t:EmailAddress>
<t:RoutingType>SMTP</t:RoutingType>
<t:MailboxType>Mailbox</t:MailboxType>
</t:Mailbox>
</t:DistinguishedFolderId>
</t:UserConfigurationName>
<t:XmlData>{}</t:XmlData>
</m:UpdateUserConfiguration>
</soap:Body>
</soap:Envelope>"""
# Create the categories XML
# Colors: https://learn.microsoft.com/en-us/openspecs/exchange_server_protocols/ms-oxocfg/eb7cac90-6200-4ac3-8f3c-6c808c681c8b
xml_data = r"""<?xml version="1.0"?>
<categories default="First category" xmlns="CategoryList.xsd">
<category name="First category" color="1" />
<category name="Second category" color="2" />
</categories>"""
# Encode the payload and insert it into the XML request
xml = base64.b64encode(xml_data.encode())
payload = payload.replace('{}', str(xml).strip('b\''))
# Use requests with the NTLM authentication libary to submit the request
headers = {'content-type': 'text/xml'}
ews_url = 'https://mail.your-organizations-exchange-server.com/EWS/Exchange.asmx'
session = requests.Session()
session.auth = HttpNtlmAuth(exhange_username, exchange_password)
response = session.post(ews_url, data=payload, headers=headers)
print(response.text)

Related

MarkAsJunk operation Error Code 9020. Getting "An internal server error occurred. The operation failed."

I am trying to use the MarkAsJunk operation using only SOAP requests with Office.context.mailbox.makeEwsRequestAsync. For this purpose I also use the easyEWS module which is a wrapper over OfficeJS. The code I'm using to send the SOAP looks like this:
this.markAsJunk = function (itemId) {
var soap = '<m:MarkAsJunk IsJunk="true" MoveItem="true"' +
'
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <ItemIds>' +
' <t:ItemId Id="' + itemId + '"/>' +
' </ItemIds>' +
'</m:MarkAsJunk>';
soap = getSoapHeader(soap);
asyncEws(soap, function (data) { });
};
The SOAP which I'm sending looks like this:
<?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:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />
</soap:Header>
<soap:Body>
<m:MarkAsJunk IsJunk="true" MoveItem="true"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<ItemIds>
<t:ItemId Id="AAMkADg2OGZmNDkzLWVjNDYtNGI2MC1iMGI3LWE3YmEzMDk5MThiNABGAAAAAAC3FQIsRYg6SZwlyqfCFdA0BwBTNDtA08+GRo/QPlH0XaGpAAAAAAEMAABTNDtA08+GRo/QPlH0XaGpAADEMDCVAAA="/>
</ItemIds>
</m:MarkAsJunk>
</soap:Body>
</soap:Envelope>
ItemIds is present in namespace xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages", so you need to use "m:ItemIds".
Please refer the tutorial here for the SOAP request format.

Server was unable to process request.,Object reference not set to an instance of an object. SOAP API

want to push data through soap API, code provided in API documentation is given below. i am getting error. error i am getting. let me know where i am wrong, thanks in advance.
url
<?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/">
<soap:Body>
<PushData xmlns="RBSS">
<RBSS>
<Lead_Response_DateTime>20-05-2016 10:25:16</Lead_Response_DateTime>
<Lead_Push_DateTime>20-05-2016 10:25:16</Lead_Push_DateTime>
<Lead_Recd_DataTime>20-05-2016 10:25:16</Lead_Recd_DataTime>
<FirstName>test</FirstName>
<Phone1>9876543215</Phone1>
<Phone2>9876543215</Phone2>
<Email>amrit#gmail.com</Email>
<DOB>20-05-2016</DOB>
<Age>26</Age>
<Child_DOB>20-05-2002</Child_DOB>
<Child_Age>4</Child_Age>
<Pincode>400052</Pincode>
<City_Name>Mumbai</City_Name>
<Address>2, Akshardham…..</Address>
<Annual_Income>1000000</Annual_Income>
<Annual_Income_Slab>10</Annual_Income_Slab>
<SMS_Keyword>0</SMS_Keyword>
<Short_Code></Short_Code>
<Circle_Operator></Circle_Operator>
<Sum_Assured></Sum_Assured>
<Premium_Pitched></Premium_Pitched>
<Company_Name>WRS</Company_Name>
<Website_Name>Bima Deals.com</Website_Name>
<UTN_Source>FaceBook</UTN_Source>
<Lead_Source></Lead_Source>
<Type_Of_Lead></Type_Of_Lead>
<Verification_Type></Verification_Type>
<Product_Name></Product_Name>
<Product_Category></Product_Category>
<No_of_Companies></No_of_Companies>
<Names_of_Companied></Names_of_Companied>
<SMS_Message_Sent></SMS_Message_Sent>
<Customer__Remarks></Customer__Remarks>
<FLAG></FLAG>
<Lead_Type>INCOMING_WEB</Lead_Type>
<Channel_Type>INTERNET</Channel_Type>
<Mode_Type>PREFIXED_APPOINTMENT</Mode_Type>
<Source_Type>BIMADEALS</Source_Type>
<Campaign_Type>APR_16</Campaign_Type>
<Opportunity_Id>123456</Opportunity_Id>
<PROSPECT_ID></PROSPECT_ID>
<Title>MR</Title>
<UID></UID>
<LastName>Lastname</LastName>
<Gender>Male</Gender>
<MaritalStatus></MaritalStatus>
<MobileNo>9865856325</MobileNo>
<AgeAtRetirement></AgeAtRetirement>
<VendorCSE_Name></VendorCSE_Name>
<TermOfPlan></TermOfPlan>
<Smoker_NonSmoker></Smoker_NonSmoker>
<VendorCode></VendorCode>
<MeetingDate></MeetingDate>
<MeetingTime></MeetingTime>
<City_ID>67</City_ID>
<ID>123</ID>
<CallcenterID></CallcenterID>
<ADDLInfo1></ADDLInfo1>
<ADDLInfo2></ADDLInfo2>
</RBSS>
</PushData>
</soap:Body>
</soap:Envelope>

Invalid Soap Call

Why doesn't this soap call work for this URL ?
http://services.aonaware.com/DictService/DictService.asmx?op=Define
<v:Envelope xmlns:i="http://www.w3.org/1999/XMLSchema-instance" xmlns:d="http://www.w3.org/1999/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<Define xmlns="http://tempuri.org/" id="o0" c:root="1">
<word i:type="d:string">Name</word>
</Define>
</v:Body>
</v:Envelope>
But this one does
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://services.aonaware.com/webservices/">
<soapenv:Header/>
<soapenv:Body>
<web:Define>
<!--Optional:-->
<web:word>Test</web:word>
</web:Define>
</soapenv:Body>
</soapenv:Envelope>
Because they are different: not only in content but also in namespace definition, to correct the first one you've to atleast use the correct namespace so use http://services.aonaware.com/webservices/ for your <Define> element as you do in the second one:
<v:Envelope xmlns:i="http://www.w3.org/1999/XMLSchema-instance" xmlns:d="http://www.w3.org/1999/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<Define xmlns="http://services.aonaware.com/webservices/" id="o0" c:root="1">
<word i:type="d:string">Name</word>
</Define>
</v:Body>
</v:Envelope>
Then make sure also that id an c:root are valid attributes in your xsd for <Definition> and i:type it's a correct one for <word>.
EDIT
I invoke http://services.aonaware.com/DictService/DictService.asmx with SOAPUI using my corrected request and it response correctly:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<DefineResponse xmlns="http://services.aonaware.com/webservices/">
<DefineResult>
<Word>Name</Word>
<Definitions>
<Definition>
<Word>Name</Word>
<Dictionary>
<Id>gcide</Id>
<Name>The Collaborative International Dictionary of English v.0.44</Name>
</Dictionary>
<WordDefinition>Name \Name\ (n[=a]m), n. [AS. nama; akin to D. naam, OS. & OHG.
...
[1913 Webster]</WordDefinition>
</Definition>
<Definition>
<Word>Name</Word>
<Dictionary>
<Id>gcide</Id>
<Name>The Collaborative International Dictionary of English v.0.44</Name>
</Dictionary>
<WordDefinition>Name \Name\ (n[=a]m), v. t. [imp. & p. p. {Named} (n[=a]md); p.
...
</WordDefinition>
</Definition>
</Definitions>
</DefineResult>
</DefineResponse>
</soap:Body>
</soap:Envelope>
Hope this helps,

How to 'set' read-only calendar appointment properties (related to meetings)?

I'm recreating calendar meeting events in a sychronization tool (using CreateItem), basically preserving some properties for meetings and writing them back.
However, there are some properties that are read-only, and I see no way to preserve their state:
IsMeeting
IsCancelled
MeetingRequestWasSent
IsOnlineMeeting
Some of these boolean values are stored in property AppointmentState, but that is read-only too:
Name Bit Description
None 0x0000 No flags have been set. This is only used for an appointment that does not include attendees.
Meeting 0x0001 This appointment is a meeting.
Received 0x0002 This appointment has been received.
Canceled 0x0004 This appointment has been canceled.
Is IsMeeting maybe automatically set if I set other meeting-properties, like e.g. OptionalAttendees or RequiredAttendees? That would help with one of the four, if I knew which properties trigger the setting of IsMeeting.
(Yes, this is a follow-up to Meeting request properties not settable in EWS SOAP calls?).
You should be able to use MAPI Extended Properties:
Appointment state is
Named Prop Name: id: 0x8217=33303 = PidLidAppointmentStateFlags, dispidApptStateFlags
Named Prop Guid: {00062002-0000-0000-C000-000000000046} = PSETID_Appointment
So SOAP that should be something like
<t:ExtendedProperty>
<t:ExtendedFieldURI DistinguishedPropertySetId="Appointment" PropertyId="33303" PropertyType="Integer" />
<t:Value>1</t:Value>
</t:ExtendedProperty>
(I use the managed API for that, and got that XML from the trace-log, hope that is something you can use)
[Edited by the OP] This is the complete call that does the job:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:typ="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:mes="http://schemas.microsoft.com/exchange/services/2006/messages">
<soapenv:Header>
<typ:RequestServerVersion Version="Exchange2007_SP1"/>
<typ:MailboxCulture>en-US</typ:MailboxCulture>
<typ:TimeZoneContext>
<typ:TimeZoneDefinition Id="W. Europe Standard Time"/>
</typ:TimeZoneContext>
</soapenv:Header>
<soapenv:Body>
<mes:UpdateItem ConflictResolution="AutoResolve" SendMeetingInvitationsOrCancellations="SendOnlyToChanged">
<mes:ItemChanges>
<typ:ItemChange>
<typ:ItemId <t:ItemId Id="AAMkA[snip]xAAA=" ChangeKey="Dw[snip]Mar"/>
<typ:Updates>
<typ:SetItemField>
<typ:ExtendedFieldURI DistinguishedPropertySetId="Appointment" PropertyId="33303" PropertyType="Integer"/>
<typ:CalendarItem>
<typ:ExtendedProperty>
<typ:ExtendedFieldURI DistinguishedPropertySetId="Appointment" PropertyId="33303" PropertyType="Integer"/>
<typ:Value>5</typ:Value>
</typ:ExtendedProperty>
</typ:CalendarItem>
</typ:SetItemField>
</typ:Updates>
</typ:ItemChange>
</mes:ItemChanges>
</mes:UpdateItem>
</soapenv:Body>
</soapenv:Envelope>
Strangely, the result says "Success", but reports a (one) conflict. I have no idea which one:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="1" MajorBuildNumber="225" MinorBuildNumber="19" Version="V2_48" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
<m:UpdateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:UpdateItemResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:Items>
<t:CalendarItem>
<t:ItemId Id="AAMk[snip]xAAA=" ChangeKey="DwA[snip]aMat"/>
</t:CalendarItem>
</m:Items>
<m:ConflictResults>
<t:Count>1</t:Count>
</m:ConflictResults>
</m:UpdateItemResponseMessage>
</m:ResponseMessages>
</m:UpdateItemResponse>
</s:Body>
</s:Envelope>

Customer attributes not saving on Add

So I've been experimenting with adding customers to QuickBooks Online from a local database instance at our business. I want to keep track of our internal customer reference numbers in QBO, so have tried to save those to several different attributes like AcctNum, ExternalKey, ExternalId, AlternateId, or even directly to the Id attribute. After attempting to save to these fields, the return result looks good.
var qbCustomer = new Customer
{
AcctNum = customer.CustRef.ToString(CultureInfo.InvariantCulture),
ExternalKey = new IdType {idDomain = idDomainEnum.NG, Value = customer.CustRef.ToString(CultureInfo.InvariantCulture)},
Id = new IdType {idDomain = idDomainEnum.NG, Value = customer.CustRef.ToString(CultureInfo.InvariantCulture)},
Name = customer.CustName1,
FamilyName = customer.CustRef.ToString(CultureInfo.InvariantCulture),
};
Customer resultCustomer = dataServices.Add(qbCustomer);
But the next time I retrieve those customers, all of those fields are just null. Why are these fields not saving? Is there another more appropriate field to use to store an external ID besides just using one of the plain text fields (Name, Address, etc.)?
UPDATE:
Here's the raw XML exchange.
What I sent when adding a new customer:
<?xml version="1.0" encoding="utf-8"?>
<q1:Customer xmlns="http://www.intuit.com/sb/cdm/qbo" xmlns:q1="http://www.intuit.com/sb/cdm/v2">
<q1:Id>7</q1:Id>
<q1:ExternalKey>7</q1:ExternalKey>
<q1:TypeOf>Person</q1:TypeOf>
<q1:Name>Customer Name</q1:Name>
<q1:FamilyName>7</q1:FamilyName>
<q1:AcctNum>7</q1:AcctNum>
</q1:Customer>
Intuit's response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Customer xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:qbp="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:qbo="http://www.intuit.com/sb/cdm/qbo">
<Id idDomain="QBO">12</Id>
<SyncToken>0</SyncToken>
<MetaData><CreateTime>2013-07-25T13:51:43-07:00</CreateTime><LastUpdatedTime>2013-07-25T13:51:43-07:00</LastUpdatedTime></MetaData>
<Name>Customer Name</Name>
<WebSite/>
<Email/>
<FamilyName>7</FamilyName>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="StringTypeCustomField"><DefinitionId>Preferred Delivery Method</DefinitionId><Value>DONT</Value></CustomField>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="StringTypeCustomField"><DefinitionId>Resale Number</DefinitionId></CustomField>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="BooleanTypeCustomField"><DefinitionId>Bill With Parent</DefinitionId><Value>false</Value></CustomField>
<ShowAs>Erik Kunze/Magdalena Guarda Munoz</ShowAs>
<OpenBalance><Amount>0</Amount></OpenBalance>
</Customer>
My retrieval later:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<qbo:SearchResults xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:qbp="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:qbo="http://www.intuit.com/sb/cdm/qbo">
<qbo:CdmCollections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Customers">
<Customer>
<Id idDomain="QBO">12</Id>
<SyncToken>0</SyncToken>
<MetaData><CreateTime>2013-07-25T13:51:43-07:00</CreateTime><LastUpdatedTime>2013-07-25T13:51:43-07:00</LastUpdatedTime></MetaData>
<Name>Customer Name</Name>
<WebSite/>
<Email/>
<FamilyName>7</FamilyName>
<CustomField xsi:type="BooleanTypeCustomField"><DefinitionId>Bill With Parent</DefinitionId><Value>false</Value></CustomField>
<CustomField xsi:type="StringTypeCustomField"><DefinitionId>Preferred Delivery Method</DefinitionId><Value>DONT</Value></CustomField>
<ShowAs>Erik Kunze/Magdalena Guarda Munoz</ShowAs>
<OpenBalance><Amount>0</Amount></OpenBalance>
</Customer>
</qbo:CdmCollections>
<qbo:Count>1</qbo:Count>
<qbo:CurrentPage>1</qbo:CurrentPage>
</qbo:SearchResults>
There's no AcctNum in the raw XML anywhere.
You are referring QBD's customer endpoint in apiexplorer.
Correct QBO link - https://developer.intuit.com/apiexplorer?apiname=V2QBO#Customer
Api Docs & Sample Create request - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0400_quickbooks_online/customer#Sample_Create_Request_XML
Simplest request body to create QBO customer -
<Customer xmlns:ns2="http://www.intuit.com/sb/cdm/qbo" xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:ns3="http://www.intuit.com/sb/cdm/baseexceptionmodel/xsd">
<TypeOf>Person</TypeOf>
<Name>TestQBCustomer12345</Name>
</Customer>
Simplest Response
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Customer xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:qbp="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:qbo="http://www.intuit.com/sb/cdm/qbo">
<Id idDomain="QBO">14</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2013-07-25T14:08:49-07:00</CreateTime>
<LastUpdatedTime>2013-07-25T14:08:49-07:00</LastUpdatedTime>
</MetaData>
<Name>TestQBCustomer12345</Name>
<WebSite/>
<Email/>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="StringTypeCustomField">
<DefinitionId>Preferred Delivery Method</DefinitionId>
<Value>DONT</Value>
</CustomField>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="StringTypeCustomField">
<DefinitionId>Resale Number</DefinitionId>
</CustomField>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="BooleanTypeCustomField">
<DefinitionId>Bill With Parent</DefinitionId>
<Value>false</Value>
</CustomField>
<ShowAs>TestQBCustomer12345</ShowAs>
<OpenBalance>
<Amount>0</Amount>
</OpenBalance>
</Customer>
You can test it first using apiexplorer then use the proper setters to do the same in your code.
Please let me know how it goes.
Thanks
Refer to the documentation:
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0500_quickbooks_windows/0600_object_reference/customer
You'll note that:
Id is an internal key generated by IPP/IDS - it's NOT something you can set yourself.
ExternalKey is the same situation - it's generated by IPP/IDS, not set-able by you.
ExternalId is marked "UNSUPPORTED FIELD."
AlternateId is marked "NOT SUPPORTED."
The only one of these fields that should work is:
AcctNum
If you're still having problems with that field, the way to troubleshoot is to get the raw XML outgoing request from Intuit, the raw XML that you get back (showing success) and then the raw response that you get back when you query it, showing that it's NULL.