How to delete a personal address book contact using ews-javascript-api

151 Views Asked by At

I'm using the ews-javascript-api to delete a contact from my exchange personal address book. I'm following the microsoft c# example (but obviously writing my code in javascript. Here's the example I'm following:

EWS Delete contact

And here is my code to delete a contact.

    const itemId = new ews.ItemId(id);

    const contact = ews.Contact.Bind(window.exchangeService, itemId).then((response) => {
        if (response) {
            response.Delete(ews.DeleteMode.MoveToDeletedItems).then(response => {
                dispatch( addressBookAction.deleteContactSuccess(response));

                // Refresh our PAB
                dispatch( addressBookAction.fetchAddressbook());
            }).catch((error) => {
                dispatch( addressBookAction.deleteContactFailure(error));
            });;
        }
    });

Where id is a real id of a contact. I'm getting it by calling contact.Id.UniqueId

I'm getting an error when I try the ews.Contact.Bind and passing it the ItemId object created from my contact id. It says the id is not formed correctly.

Ideas?

2

There are 2 best solutions below

0
Gautam Singh On BEST ANSWER

instead of creating new ItemId(), use contact.Id when using bind.

0
brockoli On

Gautam was correct. I was taking the Id.UniqueId and using that to create a new ItemId object to use for the delete. If I just pass contact.Id it works. ty