How to delete recently created Google Contact? - c#

I am temporary creating one contact and immediatly after that i want to delete that contact.
I am creating contact as follows:
ContactEntry[] ContactEntry = new ContactEntry[2];
ContactEntry[0] = new ContactEntry();
ContactEntry[0].Title.Text = "Temp";
Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
ContactEntry createdEntry = (ContactEntry)obj_ContactService.Insert(feedUri, ContactEntry[0]);
In order to delete above contact if i use:
ContactEntry[0].Delete();
It is throwing Exception : "No Service object set".
Note: I am using Google Apps API Ver 2 for .NET

Rather than deleting the original data holder object you should delete the instance you got from the google server. Like this:
createdEntry.Delete();

This could help you out...
http://code.google.com/apis/contacts/docs/2.0/developers_guide_dotnet.html#Deleting
Edit: As the API says, you need a ContactRequest instance to call the Delete method. I dont see that in the snippet you posted

Related

Using Google Admin API (C# / .Net)-- how can I add a first relationship to a user?

I have working code that updates users names and supervisors with data from an HR SQL database. Everything works fine until I try to update the supervisor of a user who doesn't have a manager in Google. The object comes back with the UserToUpdate.Relations equal to null. It seems like I should be able to create a relation, but when I attempt to add the UserRelation item to the User, it errors with a "System.NullReferenceException: 'Object reference not set to an instance of an object.'" error. Any advice? Is there a way to add a relation to a user if they don't already have one?
code I'm running:
User UpdateUser = service.Users.Get(sUserEmail).Execute();
//code here to look up data in sql
UserRelation UR = new UserRelation();
UR.Type = "manager";
UR.Value = sManagersEmail;
UpdateUser.Relations.Add(UR); //this is where it fails
service.Users.Update(UpdateUser, sUserEmail).Execute();
I've also tried using the .Insert method instead of .Add:
UpdateUser.Relations.Insert(0,UR); //this also fails
to no avail -- same result.
For users that already have a manager, this works:
UpdateUser.Relations[0].value = sManagersEmail;
I can't find any further reference to do anything with .Net; I see how to do it with a JSON post outside .net's API, but it sure seems like I shouldn't have to do that...
Thank you!
you should check if the relations property on the user object is not null, otherwise instantiate an empty list, to which you will add the new relationship object.
try to use this in place of the line of code that fails:
if(UpdateUser.Relations == null){
UpdateUser.Relations = new List<UserRelation>();
}
UpdateUser.Relations.Add(UR);

The requested web method is unavailable to this caller or application thrown when using `GetConversationItems`

In my outlook web add-in I use Office.js's getCallbackTokenAsync
to get the token before connecting to EWS in my asp.net back end.
ExchangeService service = new ExchangeService();
service.Url = new Uri(mailItem.ewsUrl);
service.Credentials = new OAuthCredentials(mailItem.ewsToken);
PropertySet ps = new PropertySet(
ItemSchema.Subject,
);
_email = EmailMessage.Bind(service, new ItemId(mailItem.itemID),ps);
//the following throws error
ConversationResponse response = service.GetConversationItems(convId,
properties,
null,
foldersToIgnore,
ConversationSortOrder.TreeOrderDescending);
Seems like this GetConversationItems method is not allowed when I used the token retrieved by Office.js to initialize the EWS service. I tried to updated the manifest permission to the highest level to ReadWriteMailBox but still not working. Seems like I can only use Office.js to call EWS?
The token you get from getCallbackTokenAsync is only used to retrieve attachments on the current item or on the current item.
For more information, please see the following link:
getCallbackTokenAsync
Best Regards,
Evan

Survey Monkey API V3 - Survey title when creating from an existing survey

I'm upgrading a C# application used at work to gather client satisfaction stats using Survey Monkey. The upgrade is to make it use the Survey Monkey API V3 instead of V2 (since V2 gets turned off soon). Both versions of our code make use of Ben Emmett's excellent .NET wrapper(https://github.com/bcemmett/SurveyMonkeyApi) extended with appropriate methods to support creating new surveys and sending invitations.
In version 2 we used the Create_Flow API method to generate new surveys based on an existing one (we have a couple of existing base surveys and choose the appropriate one based on the type of project we're surveying about). It's important that the title of the new survey reflect the name of the relevant project. The relevant part of our V2 code looks like this:
var data = new CreateFlowSettings();
data.survey.survey_title = legislationTitle;
data.survey.from_survey_id = fromSurveyId;
data.collector.recipients = recipients;
data.email_message.subject = subject;
data.email_message.body_text = bodyText;
data.email_message.reply_email = replyEmail;
var serializedData = JsonConvert.SerializeObject(data);
const string endPoint = "/batch/create_flow";
var response = MakeApiRequest(endPoint, serializedData);
var createFlowResponse =
JsonConvert.DeserializeObject<CreateFlowResponseObjects.CreateFlowResponse>(response.ToString());
return createFlowResponse;
In V3 we create our surveys using the /surveys endpoint like so (the term 'template' used in the code below is not a reference to the Survey Monkey concept of template surveys):
public Survey CreateSurvey(string templateSurveyid, string newSurveyTitle)
{
const string endpoint = "/surveys";
var requestData = new RequestData {{"from_survey_id", templateSurveyid}, {"title", newSurveyTitle}};
var result = MakeApiRequest(endpoint, Verb.POST, requestData);
return result.ToObject<Survey>();
}
In V2 the title of the survey displayed at the top of each page in our new surveys would reflect the 'survey_title' data we sent with the API request. In V3 however the 'title' value is NOT replacing the text appearing at the top of each page. It IS correctly determining the name of the survey on the site but at the top of each page we see the title of the survey on which the new one was based (the survey with the id passed to the API as 'from_survey_id').
I think I've googled this pretty extensively and can't find anybody else describing this problem. Any ideas what I am doing wrong? Do I need to code modifying the survey after creation to achieve this in V3?
So it turns out this is a bug in API v3. Only part of the survey title is being updated on copy survey.
This has been resolved - expect a fix out (likely sometime this week) and it will start working without any changes on your side.
Note: PATCH on the survey should be working properly (but I wouldn't recommend coding around the issue unless necessary)

Exchange Web Service (EWS) FindItems does not work if contact is in GAL

I created a small application that gets Contact objects from an external source. Then, depending on some configurations, I have to create/upadate these contacts in a user's contact folder on our exchange server, so that the next time this user opens its MS Outlook, he sees the new contacts (on the exchange server, I have a user with impersonation capabilities, so security is not a concern).
For that, I use the FindItems(folderId, filter, view) method of the EWS library that works good. For the filter, I'm using the user's email address which is quite a good key... If I get a result back, this simply means that the Contact already exist, and that I need to do an update instead of a create. Everything works as expected until here...
BUT, I encounter a problem when the Contact (email address in fact) is already existing in the GAL (Global Address List). In this case, the FindItems method returns no result even if the Contact exists in the folder! It seems (this is a supposition) that the exchange server creates a link for contacts which have an email address that already exist in the GAL and not a new contact. And this could explain why the FindItems method does not return anything in this case. The strange thing is that if I'm filtering on another property (for example on the combination of first and lastname), it works!
Currently, what happens is that for each Contact that already exist in the GAL, a creation instead of an update is done (because the FindItems method returns nothing), and as a result, the same Contact is created X time (instead of beeing created once, and then updated X-1 time).
The question is of course, how can I know if a Contact exists in an exchange folder when it already exists in the GAL?
Current code:
ItemView view = new ItemView(5)
{
PropertySet = new PropertySet(BasePropertySet.FirstClassProperties)
};
SearchFilter f = new SearchFilter.IsEqualTo(ContactSchema.EmailAddress1, email);
FindItemsResults<Item> contactItems = _service.FindItems(folderId, f, view);
int resultCount = contactItems.Count(); // Always 0 if GAL, otherwise it works
Finally, I solved my problem with an extended property by using the SetExtendedProperty method. In this extended field, I just put an Id and that solved the problem.
But that does not explain why the search is not working with an email address... If someone knows the answer, I'm still interested :)
The new search looks like this:
ItemView view = new ItemView(nb);
view.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties, _extendedPropDef);
SearchFilter f = new SearchFilter.IsEqualTo(_extendedPropDef, contact.Id);
FindItemsResults<Item> contactItems = _service.FindItems(folderId, f, view);
With this code, everything works as expected...

Access custom view column from exchange public folder

I'm using Exchange Web Services to access contact records in a public folder. I need to pull a custom column, "Client Contact Management", created for a view in that folder. The custom column was created in the user interface.
I've already used the ExtendedPropertyDefinition class before on properties that I have created on my own through code. Is that what I'm supposed to use in this case and if so then how do I get the guid for the custom column?
I finally found the answer on this thread from David Sterling on the microsoft exchange server forums. His example (copied below) shows how to do things using EWS directly and using the managed api.
// via autogenerated proxy classes
PathToExtendedFieldType hairColorPath = new PathToExtendedFieldType();
hairColorPath.DistinguishedPropertySetId = DistinguishedPropertySetType.PublicStrings;
hairColorPath.DistinguishedPropertySetIdSpecified = true;
hairColorPath.PropertyName = "HairColor";
hairColorPath.PropertyType = MapiPropertyTypeType.String;
// via the Client API
ExtendedPropertyDefinition hairColor = new ExtendedPropertyDefinition(
DefaultExtendedPropertySet.PublicStrings,
"HairColor",
MapiPropertyType.String);
Here is what I did using the managed api for my own problem. The key is using the DefaultExtendedPropertySet.PublicStrings which is where outlook stores the custom view column.
ExtendedPropertyDefinition _clientContactManagementPropertyDefinition =
new ExtendedPropertyDefinition(
DefaultExtendedPropertySet.PublicStrings,
"Client Contact Management",
MapiPropertyType.Boolean
);

Categories

Resources