Using POST with Contacts API
I'm a bit confused about how to do a post. On this page:
http://msdn2.microsoft.com/en-us/library/bb463957.aspx
The example shows:
POST /someone@example.com/LiveContacts HTTP/1.1
On this page:
http://msdn2.microsoft.com/en-us/library/bb463980.aspx
The example shows:
POST /livecontacts/contacts/contact(ContactID)/emails HTTP/1.1
Which is correct? And is "ContactID" a placeholder for a value?
--FB
[437 byte] By [
fredb86] at [2008-2-18]
The article in the first link simply demonstrates the syntax of a POST request (i.e. it doesn't necessarily represent a working example). The example in the second article is what you can refer to directly in the code.
ContactID is a placeholder of a value that is the ID of a particular contact in your addressbook. In the example above, you are adding some new email address(es) to one of your contacts (specified by ContactID).
This page shows another slightly different version:
http://msdn2.microsoft.com/en-us/library/bb463955.aspx
I'm not actually sure what the URI should be. If I'm creating a
contact, which is what you typically use POST for, why would
I provide a ContactID? I don't know the ContactID yet
because it won't exist until your backend creates it.
FB
Further confusion....
On this page:
http://msdn2.microsoft.com/en-us/library/bb463980.aspx
It says:
"he URI specifies the exact entry to be updated. In this example, the contact that is identified by the ContactID value has the e-mail address someone@example.com set as its default e-mail address."
But the email address someone@example.com doesn't appear anywhere else on the page.
Where/how is the email address used?
J
This page may help: http://msdn2.microsoft.com/en-us/library/bb463982.aspx
Basically a POST is always an insert under the Parent specified by the URI. For example you can post a new contact under the /contacts URI. The ContactID is generated automatically by the service and you will see that if you run a GET on the same URI.
Emails and Phones are collections within a Contact, so when inserting a new Email address or Phone number, you have to specify which Contact to add the email or phone into. For example, you can post a new email like this: /contacts/contact(<contactid>)/emails. In this example, the <contactid> is the guid you received from the service beforehand, by issueing a GET to obtain the IDs of all of the contacts to determine which one to add the email to.
So, a POST is like an Insert under the URI and a PUT is an update at the URI.
I'm getting back a 403 status. Here's what I'm sending (with some changes to hide identities):
POST /myEmail@hotmail.com/LiveContacts/contacts/contact(a837234-79fc-45ab-8924-faf1112057cc) HTTP/1.1
Host: cumulus.services.live.com
Accept: */*
Authorization: DomainAuthToken at="<<DOMAIN AUTHORIZATION TOKEN GOES HERE>>"
Content-Length: 314
Content-Type: application/x-www-form-urlencoded
<Contact>
<Emails>
<Email>
<EmailType>EmailType</EmailType>
<Address>blasmo@junkjunk.com</Address>
</Email>
<Email>
<EmailType>EmailType</EmailType>
<Address>junk@blasmo.com</Address>
</Email>
</Emails>
</Contact>
There is an issue with error codes right now for security reasons apparently, which means that everything is coming back as 403 regardless of the actual error. It's not ideal, but it does mean there is a problem with your call.
You are actually trying to add Email addresses to an existing Contact, which is covered in the SDK here: http://msdn2.microsoft.com/en-us/library/bb463977.aspx
You'll see that there is a limit of one instance per POST, and you are in fact trying to add more than one email address in a single POST call.
I would (1) edit the URI to go down to the level you are inserting i.e. the Emails and (2) edit the body to one at a time e.g.
POST /myEmail@hotmail.com/LiveContacts/contacts/contact(a837234-79fc-45ab-8924-faf1112057cc)/emails HTTP/1.1 <Email>
<EmailType>EmailType</EmailType>
<Address>blasmo@junkjunk.com</Address>
</Email>
Still getting 403 back........
> POST /myEmail@hotmail.com/LiveContacts/contacts/contact(a3234034-79fc-45ab-8924-faf3d423057cc)/emails HTTP/1.1
Host: cumulus.services.live.com
Accept: */*
Authorization: DomainAuthToken at="<<DOMAINAUTHORIZATION TOKEN GOES HERE>>"
Content-Length: 85
Content-Type: application/x-www-form-urlencoded
<Email><EmailType>EmailType</EmailType><Address>blasmo@junkjunk.com</Address></Email>
This may actually be down to the Email Type you are using: "EmailType". I had assumed this was changed in your example and didn't look at it specifically, but EmailType is an enumeration and therefore fixed to certain types.
At this time, you can only use the following types (from http://msdn2.microsoft.com/en-us/library/bb447750.aspx):
WindowsLiveID
Personal
Business
Other Still getting 403...........
POST /MyID@hotmail.com/LiveContacts/contacts/contact(a39e9034-79fc-45ab-8924-faf342d057cc)/emails HTTP/1.1
Host: cumulus.services.live.com
Accept: */*
Authorization: DomainAuthToken at="<<DOMAIN AUTHORIZATION TOKEN GOES HERE>>"
Content-Length: 89
Content-Type: application/x-www-form-urlencoded
<Email><EmailType>WindowsLiveID</EmailType><Address>blasmo@junkjunk.com</Address></Email>
Well now you're getting it because you chose WindowsLiveID and the email address you are inserting isn't a Windows Live ID. In order to use that particular Email Type it has to be a registered Windows Live ID otherwise it will fail.
The other Email Types are not verified in this way though, so you could use other types.
Still getting 403..............
POST /MyID@hotmail.com/LiveContacts/contacts/contact(a39e9034-79fc-45ab-8924-faf342d057cc)/emails HTTP/1.1
Host: cumulus.services.live.com
Accept: */*
Authorization: DomainAuthToken at="<<DOMAIN AUTHORIZATION TOKEN GOES HERE>>"
Content-Length: 84
Content-Type: application/x-www-form-urlencoded
<Email><EmailType>Personal</EmailType><Address>blasmo@junkjunk.com</Address></Email>
fredb86:
Thanks for your feedback for the articles. I took note of your comments and will pass them to the writer to conrrect any error.
I edited your postings to replace the value of your real domain authentication token with a placeholder. Even if you are using test accounts, it is better not to share your credentials on a public share.
Were you able to solve the 403 issue you had?
Assuming everything else is correct, I can only guess now that the error is due to a duplication of email types. Do you have an existing email for this contact of type Personal? If so, then adding another with the same type is currently disallowed.
Still getting 403.....I changed the Content-Type to application/xml but that didn't
seem to make any difference.....
POST /MySite@hotmail.com/LiveContacts/contacts/contact(a39e9034-79fc-45ab-8924-faf342d057cc)/emails HTTP/1.1
Host: cumulus.services.live.com
Accept: */*
Content-Type: application/xml
Content-Length: 81
Authorization: DomainAuthToken at="A:20070516T163922Z:www.MySite.info:f+Ea5fb6cOefeW059Xhs33KIRdQ5kL2R6MqDizQAfJUM0QNqcjEmTOe+69KbxwD0rSCBmAfKLTh23k3dnmmvIDVT5sg5w57O9DCQCyXwfdPFlYQo7XhIgJtbdQE38o6VeZYdMt5PfDj5BVWBHk/zXIABxig92Rj2ybBzGybPeAi9orV1kAXkd75ZeBOSWx9oqXZDEO4muK6qrD21PmxrzKqQd//yKa/9Wdxui8XwkTymsnfcOyL7vD7AY3MpGRgSVO92nzliLIsJADOleHfcvLCe6gy06ahMqUSlynJrPMzp7Y+K8MnOrHSx+lVlrY4vsRp6CRdfmHnAud5J/tg=="
<Email><EmailType>Other</EmailType><Address>blasmo@junkjunk.com</Address></Email>