web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Unanswered

D365 Commerce External integration - Create Sales

(0) ShareShare
ReportReport
Posted on by 110

Hi Everyone;

I'm trying to create retail transaction using external app integration; I achieved to query some data like sales orders, customers and create new customer, but I haven't create sales. Does anyone know what is the minimum fields that are required?

namespace MyCustom.Integracion
{


class Program
{

static void Main(string[] args)
{

GetConfiguration();

Cart newCart = new Cart()
{

//fields minimun requiered

}

var createdCart = Task.Run(async () => await CreateCart(newCart)).Result;
Console.WriteLine(string.Format("New cart created: {0}", createdCart?.Name));

}

private static void GetConfiguration()
{
clientId = ConfigurationManager.AppSettings["aadClientId"];
clientSecret = ConfigurationManager.AppSettings["aadClientSecret"];
authority = new Uri(ConfigurationManager.AppSettings["aadAuthority"]);
retailServerUrl = new Uri(ConfigurationManager.AppSettings["retailServerUrl"]);
operatingUnitNumber = ConfigurationManager.AppSettings["operatingUnitNumber"];
resource = ConfigurationManager.AppSettings["resource"];
}

private static async Task<ManagerFactory> CreateManagerFactory()
{
//System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext authenticationContext = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(authority.ToString(), false);

Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationResult authResult = null;
authResult = await authenticationContext.AcquireTokenAsync(resource, new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(clientId, clientSecret));

Microsoft.Dynamics.Commerce.RetailProxy.Authentication.ClientCredentialsToken clientCredentialsToken = new Microsoft.Dynamics.Commerce.RetailProxy.Authentication.ClientCredentialsToken(authResult.AccessToken);
RetailServerContext retailServerContext = RetailServerContext.Create(retailServerUrl, operatingUnitNumber, clientCredentialsToken);
ManagerFactory factory = ManagerFactory.Create(retailServerContext);
return factory;
}

private static async Task<Cart> CreateCart(Cart cart)
{
ManagerFactory managerFactory = await CreateManagerFactory();
ICartManager cartManage = managerFactory.GetManager<ICartManager>();
return await cartManage.Create(cart);
}

}

}

Thanks in advance.

I have the same question (0)
  • ToddB Profile Picture
    on at

    Hi Adolfo,

    Please take a look at the code for ShoppingApp (that we ship as part of sample extension) which would be calling all these APIs.:

     

    SampleExtensions

    This folder contains the sample projects and templates for extensions:

    ·         CommerceRuntime â€“ Sample extension projects for business logic extensions (Commerce runtime [CRT] triggers, handlers, and new service extension).

    ·         HardwareStation â€“ Sample Hardware station extension projects.

    ·         HybridApp â€“ Android and iOS shell apps for the POS. Extension can build these apps and deploy them to the Android and iOS platforms.

    ·         OnlineStore â€“ The sample online storefront app.

    ·         RetailProxy â€“ The sample C# proxy project for POS offline mode. As of version 10.0.11, the C# proxy is obsolete (deprecated). The Retail server extension libraries can be used directly in offline mode. You don't have to have separate proxy libraries.

    ·         RetailServer â€“ Sample Retail server extension projects.

    ·         SampleExtensionsTest â€“ The sample project for creating an extension test project.

    ·         ShoppingApp â€“ The sample mobile app (Retailer shopping app) for users in Android and iOS.

    ·         TypeScriptProxy â€“ Sample proxy projects that show how to generate TypeScript for the POS.

  • Adolfome9 Profile Picture
    110 on at

    Hi Todd;

    Thank you, I will check it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
Laurens vd Tang Profile Picture

Laurens vd Tang 303 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 122 Super User 2025 Season 2

#3
Siv Sagar Profile Picture

Siv Sagar 105 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans