Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

MSGraphContact - missing in action? #37

Closed
SteveDCronin opened this issue Sep 9, 2019 · 10 comments · May be fixed by #38
Closed

MSGraphContact - missing in action? #37

SteveDCronin opened this issue Sep 9, 2019 · 10 comments · May be fixed by #38

Comments

@SteveDCronin
Copy link

I'm using CocoaPods:
...
pod 'MSGraphClientSDK'
pod 'MSGraphMSALAuthProvider'
...
running 'pod install' yields:
...
Installing MSAL (0.5.0)
Installing MSGraphClientSDK (1.0.0)
Installing MSGraphMSALAuthProvider (0.2.0)
...
There are no conflicts noted!

The online docs here:
https://docs.microsoft.com/en-us/graph/api/user-post-contacts?view=graph-rest-1.0&tabs=objc

have a code sample for ObjectiveC which includes this statement:
...
MSGraphContact *contact = [[MSGraphContact alloc] init];

My application has:
#import <MSGraphClientSDK/MSGraphClientSDK.h>
...

  • (void) createMSGraphContact; {
    MSGraphContact *contact = [[MSGraphContact alloc] init];
    ...

I get an 'undeclared identifier' compiler error for 'MSGraphContact'
I cannot find any instance of the MSGraphContact class in the Pods/MSGraphClientSDK/**

Please clarify what I am missing or what I am misunderstanding!

@ghost ghost added the ToTriage label Sep 9, 2019
@MIchaelMainer
Copy link
Contributor

I believe you need to install the MSGraphClientModels pod file. Let me know if that works.

@MIchaelMainer MIchaelMainer added question Further information is requested and removed ToTriage labels Sep 10, 2019
@SteveDCronin
Copy link
Author

SteveDCronin commented Sep 10, 2019

Michael;

Hey Thanks - that got the files.... Can you point out where I missed this in the documentation?
How did you figure this out?

When I examine the MSGraphContact class it is not clear how I would assign 'Categories' to this class. Please clarify how that is accomplished using this new class?

Steve

@MIchaelMainer
Copy link
Contributor

You didn't miss it - we missed it. I just checked, we don't have it mentioned in the readme. I'll add it to the readme.

Regarding setting Categories, it is an NSArray of strings. The setter is defined here: https://github.com/microsoftgraph/msgraph-sdk-objc-models/blob/master/GeneratedModels/MSGraphOutlookItem.h#L13 .

@MIchaelMainer
Copy link
Contributor

The repo for the models is here:
https://github.com/microsoftgraph/msgraph-sdk-objc-models

There are some great resources here to help you: https://developer.microsoft.com/en-us/graph/get-started/ios

@SteveDCronin
Copy link
Author

Michael;

Thanks for your help so far!
I am continuing to use the code snippet I referred to above.
Now that I can build an MSGraphContact I am trying to complete the task per to remainder of the snippet. I am getting an error that does not make sense to me.

It occurs here:
contact = [[MSGraphContact alloc] init];
...
NSError *error=nil;
NSData *contactData = [contact getSerializedDataWithError:&error];

There error is:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (MSGraphEmailAddress)'

The contact has a single email address constructed like this:
NSMutableArray *emailAddressesList = [[NSMutableArray alloc] init];
MSGraphEmailAddress *emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setAddress:@"tim@apple.com"];
[emailAddress setName:@"Tim Cook"];
[emailAddressesList addObject: emailAddress];
[contact setEmailAddresses:emailAddressesList];

Can you clarify 2 things:

  1. why the method terminates rather than report the error?
  2. what am I doing wrong in constructing the MSGraphEmailAddress

I am opening this same issue in 'models' GitHub you mention above just to make sure....

@MIchaelMainer
Copy link
Contributor

@SteveDCronin I see nothing wrong with how you created the contact.

Does NSJSONSerialization.isValidJSONObject(emailAddress) return true?

https://github.com/microsoftgraph/msgraph-sdk-objc-models/blob/af0518ec31da0727b739db9d1b578ffc7f7197d7/BaseModels/MSObject.m#L53

@SteveDCronin
Copy link
Author

SteveDCronin commented Sep 11, 2019

From code:
NSDictionary *emailDict;
emailAddress = [[MSGraphEmailAddress alloc] init];
[emailAddress setAddress:@"tim@apple.com"];
[emailAddress setName:@"Tim Cook"];
NSLog(@"%s emailAddress: %@",func,emailAddress.name);
NSLog(@"%s emailAddress: %@",func,emailAddress.address);
if ([NSJSONSerialization isValidJSONObject:emailAddress]) {
NSLog(@"%s isValid: %@",func,emailAddress);
} else {
NSLog(@"%s isNOTValid: %@",func,emailAddress);
}
emailDict=[emailAddress getDictionary];
if ([NSJSONSerialization isValidJSONObject:emailDict]) {
NSLog(@"%s emailDict isValid",func);
} else {
NSLog(@"%s emailDict isNOTValid",func);
}

From log:
2019-09-10 19:27:29.036826-0700 XYZ] emailAddress: Tim Cook
2019-09-10 19:27:29.892016-0700 XYZ] emailAddress: tim@apple.com
2019-09-10 19:27:44.159134-0700 XYZ] isNOTValid: <MSGraphEmailAddress: 0x2835ae940>
2019-09-10 20:00:47.931312-0700 XYZ] emailDict isValid

Huh?

@SteveDCronin
Copy link
Author

Michael;

You responded to my question about assigning Categories and the online document mentioned above delineates 'categories' as string collection. I have successfully used the HTTP post mechanism to work around the issues in using the MSGraphContact class.
In the initial testing the assignment of a category seems to be accepted but when I view the newly created contact @ 'https://outlook.live.com/people/' I don't see any category assigned (nor do I see any online means of assigning 'category'...... Is there a limitation with categories that I overlooked somewhere?

@MIchaelMainer MIchaelMainer added client bug and removed question Further information is requested labels Sep 11, 2019
@MIchaelMainer
Copy link
Contributor

@SteveDCronin I'm not familiar with the categories feature. I suggest that you first search on Stack Overflow for the [microsoft-graph] tag and categories. There is already a lot of Q&A for this subject.

Otherwise, post your question to Stack Overflow with the microsoft-graph tag.

I do not understand why the MSGraphEmailAddress is not a valid JSON object. We will need to check whether other complex types are valid JSON objects.

@SteveDCronin
Copy link
Author

I can tell you that MSGraphPhysicalAddress also fails with the same error.
For now I have given up on using the MSGraph ObjectiveC model objects....
I have succeeded in creating a contact just using JSON formatted text & HTTP Post

@ddyett ddyett closed this as completed Sep 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants