How to call Microsoft Graph API from Java application - sharepoint

I am trying to build a Java application which will use Microsoft Graph API in order to view files on SharePoint. Can anyone suggest any github urls or demo projects or a third party libraries available on maven
.

You can start building your java application by following the doc - https://github.com/microsoftgraph/msgraph-sdk-java
You can write below code to get files on SharePoint
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
LinkedList<Option> requestOptions = new LinkedList<Option>();
requestOptions.add(new QueryOption("expand", "fields"));
ListItem listItem = graphClient.sites("{site-id}").lists("{list-id}").items("{item-id}")
.buildRequest( requestOptions )
.get();

Related

Latest Nugets for Outlook REST API?

I want to send emails from my .NET 4.6.1 application using one of our organisation's O365 email accounts. I'm wondering if there's a Nuget package which can help me.
Microsoft.Office365.OutlookServices looks a bit out-of-date, and the comments on the project page don't inspire confidence.
Microsoft.Graph seems more recent, but its code samples use the pre-release Microsoft Authentication Library (MSAL), which it says isn't suitable for production. Maybe I can use Active Directory Authentication Library .NET (ADAL) instead in conjunction with Graph?
The graph library is the official SDK. It is linked from the official Samles and SDKs page.
Even though the MSAL is described as pre-release on the NuGet page, the Github project page describes the Nuget as being from the stable branch.
Your mileage with it may vary, however in my projects I haven't had any issues with the 1.0.304142221-alpha NuGet.
Someone from Microsoft could probably shed some light on it, perhaps come with an indication of a release date of a non-preview NuGet?
For just sending mails, you can use System.Net.Mail like this:
var mailMessage = new MailMessage();
mailMessage.To.Add(new MailAddress(RECEIVER_MAIL_ADDRESS));
mailMessage.From = new MailAddress(SENDER_MAIL_ADDRESS, SENDER_NAME);
mailMessage.Subject = SUBJECT;
mailMessage.Body = BODY;
mailMessage.IsBodyHtml = true;
using (var smtp = new SmtpClient("smtp.office365.com", 587))
{
var credential = new NetworkCredential
{
UserName = USERNAME,
Password = PASSWORD,
Domain = DOMAIN_OPTIONAL
};
smtp.Credentials = credential;
smtp.EnableSsl = true;
smtp.TargetName = "";
await smtp.SendMailAsync(mailMessage);
}

Alternate URI with Azure Mobile Client SDK

When using Azure Mobile Client SDK, apart from the web URL, there seems to be no control over the URL of the REST end point that will be hit. By default, the request will go to (GET) www.myurl.com/tables/entity to return all entities. What can I do to inject a version number between tables and entity, such as /tables/v1/entity? I know that I could do www.myurl.com/v1/tables/entity but that's not the solution I am looking for. Thanks.
From my test, we could use attribute to achieve this scenario. Here are the steps:
1) Add config.MapHttpAttributeRoutes in startup file
HttpConfiguration config = new HttpConfiguration();
//For more information on Web API tracing, see http://go.microsoft.com/fwlink/?LinkId=620686
config.EnableSystemDiagnosticsTracing();
config.MapHttpAttributeRoutes();
new MobileAppConfiguration()
.UseDefaultConfiguration()
.ApplyTo(config);
2) Add attribute Route in the method that you want to custom the domain.
[Route("tables/v1/todoitem")]
// GET tables/TodoItem
public IQueryable<TodoItem> GetAllTodoItems()
{
return Query();
}
The following is the result on my local:
Hope this could give you some tips.

Unable to add a service reference to Dynamics 365 crm in visual studio 2012

I am trying to add service reference to Dynamics 365 CRM using the following API https://[Organization].api.crm8.dynamics.com/api/data/v8.2/ but each time I am getting this window that asks me for credentials....
I tried using the credentials that I use to login to the crm...but they donot work...can someone tell me which credential I should use?..
Why exactly are you trying to add a reference to the CRM web services? Assuming you want to access CRM from server side code, what you need to do is:
Add references to the core CRM SDK assemblies (Microsoft.Crm.Sdk.Proxy.dll and Microsoft.Xrm.Sdk.dll). You get can them from the downloadable SDK or just add the "Microsoft.CrmSdk.CoreAssemblies" NuGet package.
After doing this you'll be able to write code "talking" with CRM. But what you are missing is the actual "connection". There are several ways of obtaining it, but the easiest one is to use the Xrm Tooling helper class, described here - https://msdn.microsoft.com/en-us/library/mt608573.aspx. You'll need to reference the required assemblies or use the "Microsoft.CrmSdk.XrmTooling.CoreAssembly" NuGet package.
After doing all this, you'll be able to successfully code against Dynamics CRM.
CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["MyCRMServer"].ConnectionString);
IOrganizationService orgService = crmSvc.OrganizationServiceProxy;
// Who am I?
WhoAmIResponse whoAmIResp = orgService.Execute(new WhoAmIRequest()) as WhoAmIResponse;
Guid myUserId = whoAmIResp.UserId;
// Get all accounts starting with 'A'
QueryExpression query = new QueryExpression("account");
query.ColumnSet = new ColumnSet("accountid", "name");
query.Criteria.AddCondition("name", ConditionOperator.BeginsWith, "a");
EntityCollection ecoll = orgService.RetrieveMultiple(query);
foreach(Entity account in ecoll.Entities)
{
if(account.Attributes.Contains("name"))
{
Console.WriteLine((string)account["name"]);
}
}
// Update some account
Entity accountToUpdate = new Entity("account");
accountToUpdate["accountid"] = new Guid("_some_guid_here");
accountToUpdate["name"] = "new name";
orgService.Update(accountToUpdate);
If you want to use the type safe approach, you'll need to generate a proxy class - like described here: https://msdn.microsoft.com/en-us/library/gg327844.aspx
Afterwards you'll be able to write code like this:
DataContext data = new DataContext(orgService);
// DataContext is the name of the service context, as defined in the CrmScv tool
var myAccountData = (from a in data.AccountSet
where a.Address1_Telephone1 == "12312313"
select new
{
a.AccountId,
a.Name,
a.EMailAddress1,
a.PrimaryContactId
}).First();
Contact contactToUpdate = new Contact()
{
ContactId = myAccountData.PrimaryContactId.Id,
EMailAddress1 = myAccountData.EMailAddress1
};
orgService.Update(contactToUpdate);
... which is much nicer and less error prone.
From the looks of it you are trying to authenticate through an App outside of the context of Dynamics 365. If you want to authenticate with the Web API this way you will have to connect to Microsoft Dynamics 365 web services using OAuth and authenticate using ADAL
https://msdn.microsoft.com/en-us/library/gg327838.aspx
Here is a walkthrough on how to do it
https://msdn.microsoft.com/en-us/library/mt622431.aspx
Additional note:
If you are using CRM 2013 SDK you may need to update to 6.1.2 for Dynamics 365 Support
https://blogs.msdn.microsoft.com/crm/2017/02/01/dynamics-365-sdk-backwards-compatibility/

Netsuite SuiteTalk - Login

I am trying to use SuiteTalk to retrieve customer records.
I downloaded the v2016.1 WSDL from here: http://www.netsuite.com/portal/developers/resources/suitetalk-documentation.shtml
I used mv package to build the WSDL and generated the jar file.
I create a project in Eclipse and added the jar file. I am using Java.
Here's a snippet of my code. I am stuck here and don't know how to proceed. It looks like I am missing another jar file? like the NetSuiteService?
RecordRef role = new RecordRef();
role.setInternalId("3");
role.setType(RecordType.contact);
Passport passport = new Passport();
passport.setEmail("me#test.com");
passport.setPassword("mypassword");
passport.setRole(role);
passport.setAccount("123456");
Please help me. What do I need to do?
I'm not familiar with the Java bindings, but it looks like you are missing the data center URL configuration.
I'd recommend using the ruby bindings. They are community supported and there's some decent example code demonstrating various common functions.
I work with .net, I think you need to initialize the service to indicate the datacenter that corresponds to you, it is more or less like this:
// Instantiate the NetSuite web services
Service = new Aggregates.DataCenterAwareNetSuiteService(_account);
Service.Timeout = 1000 * 60 * 60;
var appInfo = new ApplicationInfo();
//App info from application netsuite
appInfo.applicationId = cuenta.ApplicationInfo;
// Prepare login credentials for request level login
Service.passport = new Passport()
{
email = _email,
password = _password,
account = _account
};
Service.applicationInfo = appInfo;

Sharepoint 2010 Client Object Module getting a site url list

I’m trying to learn SharePoint Client Object Model, specifically how to get a list of all SharePoint site URLs using a remote connection. This is possible using webservices…but I want to do it using the client object model.
I’ve figured how to get the title lists of a specific sharepoint site using the following code:
client object module):
ClientContext ctx = new ClientContext( server );
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = WindowsAuthenticationCredentials(username, password);
Web w = ctx.Web;
var lists = ctx.LoadQuery(w.Lists);
ctx.ExecuteQuery();
//Enumerate the results.
foreach (List theList in lists)
{
}
Output:
Announcements, Master Collection Pages… etc…
How can I do the same to get a site url list?
In web services you can call the following to achieve that, but as I said just trying to figure out how to do the same using client object module. If you can provide c# code that would greatly be appreciated.
WSPSitedata.SiteData sitedata = new SiteData();
sitedata.Url = #SharePointBaseURL + #"_vti_bin/sitedata.asmx";
sitedata.Credentials = our_credentials
_sSiteMetadata metaData = new _sSiteMetadata();
_sWebWithTime[] webWithTime
sitedata.GetSite(out metaData, out webWithTime, out users, out groups, out vgroups);
The SharePoint Client Object Model CSOM is designed to remotly interact with your SiteCollection. Sure, it is possible to connect to various SiteCollections, but it's not possible to look over all SiteCollections sitting within a SPWebApplications.
In 2010 you could still use the ASMX WebServices which are available in earlier versions of SharePoint.
To get a better understanding of the CSOM you should have a look at the MSDN site http://msdn.microsoft.com/en-us/library/ee537247.aspx
Did you really mean a list containing all SiteCollection URLs or was that a misunderstanding?
Thorsten

Resources