PowerAppsWebApiUtils 0.0.0.9
See the version list below for details.
dotnet add package PowerAppsWebApiUtils --version 0.0.0.9
NuGet\Install-Package PowerAppsWebApiUtils -Version 0.0.0.9
<PackageReference Include="PowerAppsWebApiUtils" Version="0.0.0.9" />
paket add PowerAppsWebApiUtils --version 0.0.0.9
#r "nuget: PowerAppsWebApiUtils, 0.0.0.9"
// Install PowerAppsWebApiUtils as a Cake Addin #addin nuget:?package=PowerAppsWebApiUtils&version=0.0.0.9 // Install PowerAppsWebApiUtils as a Cake Tool #tool nuget:?package=PowerAppsWebApiUtils&version=0.0.0.9
This is an API to work with PowerApps and Dynamics 365 Web API
Design goals include
Early bound classes for web api Simple Linq provider for web api.
Targets .netcore 2.0 and .net framework 4.7 Integrate well with Azure Active Directory
Feedback and contributions welcome...
How tos:
Setup an application user for PowerAppsWebApiUtils: https://www.linkedin.com/pulse/how-setup-application-user-powerappswebapiutils-philippe-dufag Generate early bound classes and setup a project to use PowerAppsWebApiUtils: https://www.linkedin.com/pulse/powerappswebapiutils-howto-philippe-dufag
Examples of supported Linq queries:
To get the service context:
var config =
new PowerAppsAuthenticationSettings
{
ClientId = configuration["clientId"],
ClientSecret = configuration["secret"],
DirectoryId = configuration["directory"],
ApiUrl = configuration["powerappsApiUrl"],
ResourceUrl = configuration["powerappsUrl"],
};
serviceProvider = new ServiceCollection() .AddPowerAppsWebApiConfiguration(config) .BuildServiceProvider();
//To impersonate, create, query, diassociate and delete
using (var context = serviceProvider.GetService<WebApiContext>())
{
context.CallerObjectId = Guid.Parse("cabfad08-d910-4c38-9873-ee9bec791238");
var account =
new Account {
Name = "JB Petroleum Inc.",
NumberOfEmployees = 6,
IndustryCode = account_industrycode.PetrochemicalExtractionandDistribution,
Revenue = 100000m,
CreditLimit = 250000m,
CustomerTypeCode = account_customertypecode.Reseller
};
account.Id = await context.Create(account);
var contact =
new Contact {
FirstName = "J",
LastName = "B",
ParentCustomerId = account.ToNavigationProperty(),
AccountRoleCode = contact_accountrolecode.DecisionMaker,
Address1_Line1 = "1450 JB Street",
Address1_Country = "Canada",
};
contact.Id = await context.Create(contact);
var parentcustomerid = context.CreateQuery<Contact>().Where(p => p.Id == contact.Id).Select(p => p.ParentCustomerId).FirstOrDefault();
Assert.NotNull(parentcustomerid);
Assert.Equal(account.Id, parentcustomerid.Id);
await context.Diassociate<Contact>(contact, p => p.ParentCustomerId);
parentcustomerid = context.CreateQuery<Contact>().Where(p => p.Id == contact.Id).Select(p => p.ParentCustomerId).FirstOrDefault();
Assert.Null(parentcustomerid);
//To delete an entity:
await context.Delete(contact);
}
//Sample queries: { context.CreateQuery<Account>().Where(p ⇒ p.Address1_Country == "Canada").Select(p ⇒ new Account(p.Id) { Name = p.Name}).OrderBy(p ⇒ p.Name).ToList(); context.CreateQuery<Account>().ToList(); context.CreateQuery<Account>().FirstOrDefault(); context.CreateQuery<Account>().Where(p ⇒ p.Name == "Test").ToList(); context.CreateQuery<Account>().Where(p ⇒ p.Name == "Test").FirstOrDefault(); context.CreateQuery<Account>().Where(p ⇒ p.StateCode == account_statecode.Active).ToList(); context.CreateQuery<Account>().Where(p ⇒ p.StateCode == account_statecode.Active).FirstOrDefault(); context.CreateQuery<Account>().Where(p ⇒ p.Name == "Test").Where(p ⇒ p.StateCode == account_statecode.Active); context.CreateQuery<Account>().Where(p ⇒ p.Name == "Toto" || p.Name == "Tata").Where(p ⇒ p.StateCode == account_statecode.Active).ToList(); context.CreateQuery<Account>().Where(p ⇒ p.Name == "Toto" || p.Name == "Tata").Where(p ⇒ p.StateCode == account_statecode.Active).FirstOrDefault();
context.CreateQuery<CustomerAddress>().Where(p => p.ParentId == new Account(Guid.NewGuid()).ToNavigationProperty()).Where(p => p.ShippingMethodCode == customeraddress_shippingmethodcode.Airborne && p.Country == "Canada").ToList();
context.CreateQuery<CustomerAddress>().Where(p => p.ParentId == new Account(Guid.NewGuid()).ToNavigationProperty()).Where(p => p.ShippingMethodCode == customeraddress_shippingmethodcode.Airborne && p.Country == "Canada").FirstOrDefault();
context.CreateQuery<CustomerAddress>().Where(p => p.ParentId == new Account(Guid.NewGuid()).ToNavigationProperty()).Select(p => new { Id = p.Id, OwnerId = p.OwnerId }).FirstOrDefault();
context.CreateQuery<Account>().OrderByDescending(p => p.Name).ToList();
context.CreateQuery<Account>().OrderByDescending(p => new {p.Address1_City, p.Name} ).ToList();
context.CreateQuery<Account>().Where(p => p.StateCode == account_statecode.Active).OrderBy(p => p.Name).ToList();
context.CreateQuery<Account>().Where(p => p.StateCode == account_statecode.Active).OrderByDescending(p => p.Name).ToList();
context.CreateQuery<Account>().Where(p => p.StateCode == account_statecode.Active).OrderBy(p => new {p.Address1_City, p.Name}).ToList();
context.CreateQuery<Account>().Where(p => p.StateCode == account_statecode.Active).OrderByDescending(p => new {p.Address1_City, p.Name}).ToList();
context.CreateQuery<Account>().Where(p => p.StateCode == account_statecode.Active).Select(p => new { Name = p.Name, Id = p.Id, CreatedBy = p.CreatedBy }).OrderBy(p => p.Name).ToList();
context.CreateQuery<Account>().Where(p => p.StateCode == account_statecode.Active).Select(p => new { Name = p.Name, Id = p.Id, CreatedBy = p.CreatedBy }).OrderByDescending(p => p.Name).ToList();
context.CreateQuery<Account>().Where(p => p.StateCode == account_statecode.Active).OrderByDescending(p => p.Name).Select(p => new { Name = p.Name, Id = p.Id, CreatedBy = p.CreatedBy }).ToList();
context.CreateQuery<Account>().Where(p => p.StateCode == account_statecode.Active).Select(p => new Account{ Id = p.Id, CustomerTypeCode = p.CustomerTypeCode }).OrderByDescending(p => p.Name).ToList();
context.CreateQuery<Account>().Where(p => p.Name == "John").Where(p => p.StateCode == account_statecode.Active).OrderByDescending(p => p.Name).Select(p => new Account{ Id = p.Id, CustomerTypeCode = p.CustomerTypeCode }).ToList();
context.CreateQuery<Account>().Where(p => p.Name == "John" || p.Name == "Doe").Where(p => p.StateCode == account_statecode.Active).OrderByDescending(p => p.Name).Select(p => new { Id = p.Id, CustomerTypeCode = p.CustomerTypeCode, ExchangeRate = p.ExchangeRate }).ToList();
context.CreateQuery<Account>().Where(p => p.StateCode == account_statecode.Active).Select(p => new { Id = p.Id, CreatedBy = p.CreatedBy }).ToList();
}
================================================================= You can still override the webapi request using the following method for operation not supported by webapi or use the async/await pattern:
var repository = serviceProvider.GetRequiredService<GenericRepository<Contact>>(); var querystring = $"{config.ApiUrl}{Contact.CollectionName}?$select=firstname,lastname,_parentcustomerid_value,address1_city&$filter=address1_city eq 'Redmond'&$orderby=lastname"; var contacts = await repository.RetrieveMultiple(querystring);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
- Microsoft.Extensions.Http (>= 2.2.0)
- Microsoft.IdentityModel.Clients.ActiveDirectory (>= 5.0.5)
- Newtonsoft.Json (>= 11.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
0.0.0.9 Diassociate function now available
Code Generation [Early bound classes need to be regenerated]:
Refactor attribute NavigationPropertyAttributeTargets into NavigationPropertyAttributeTarget (used with Diassociate)
Fix issue with PrimaryId generation in some situation
0.0.0.8 Fix issue with CallerObjectId.
Code Generation [Early bound classes need to be regenerated]:
Fix issue in codegen with picklist. EntityMetadata DefaultFormValue is optional.
Fix issue with lookup. Lookups are now using SchemaName for json serialization for 'Create' and 'Update' operations when attribute isCustomType and attributeType is 'Lookup', otherwise it uses LogicalName
0.0.0.7 Impersonation (new properties CallerObjectId and MSCRMCallerID on WebApiContext and GenericRepository. see Microsoft docs https://docs.microsoft.com/en-us/powerapps/developer/common-data-service/webapi/impersonate-another-user-web-api).
0.0.0.6 Modification to service registration (Scoped -> Transient) to ease integration with Azure Functions.
0.0.0.5 Add missing nuget assemblies in "earlybound" folder.
Change PowerAppsWebApiUtils.Console to tools folder.
From docs.microsoft.com, "The tools folder is added to the PATH environment variable for the Package Manager Console only"
0.0.0.4 Standard OData string query functions support (BeginsWith, EndsWith, Contains)
Azure Functions have changed their dependency on Newtonsoft [Newtonsoft.Json (>= 11.0.2)], so integration with Azure Functions will be simplier now Microsoft.NET.Sdk.Functions/1.0.30-beta1
0.0.0.3 OrderBy / OrderByDescending support - Readme.md having few examples
0.0.0.2 Include missing file PowerAppsWebApiUtils.Console.runtimeconfig.json
0.0.0.1 Initial release. .net core app to generate early bound classes. Api exposes in .netstandard 2.0 supportin all CRUD operations and limited Linq support (ToList and FirstOrDefault)