How to access Merchello services from outside of umbraco
We have a customer front end built with umbraco and merchello and that works fine, but now we are trying to build a custom CRM where sales staff can access merchello customers and orders.
I set up the project with references to Umbraco.core and Mechello.core and set up the umbraco connection string in the web.config that points to our umbraco database. Everything compiles, but when I try to access MerchelloContext I get a null reference because there is no current context.
Here is the codebit that is failing...
var customerService = MerchelloContext.Current.Services.CustomerService;
var customers = customerService.GetPage(1, 20, "LastName").Items.ToList();
From what I have read, this is occurring because the context is not being initiated in the startup of the project.
So I wondering what else I need to do other than add references for the umbraco.core and merchello.core to make this work.
Or is there a different API call that I can make to pull customer information outside or Umbraco.
Try to use "Merchello.Web.WebApi.MerchelloApiController" it's the same as UmbracoApiController but with Merchello context, read more about Umbraco API:
No Luck. I created a web api controller and inherited from MerchelloApiController, but when I try to invoke the method, I get the same error as before, except this time it occurs when it tries to create the controller. Any other thoughts?
How to access Merchello services from outside of umbraco
We have a customer front end built with umbraco and merchello and that works fine, but now we are trying to build a custom CRM where sales staff can access merchello customers and orders.
I set up the project with references to Umbraco.core and Mechello.core and set up the umbraco connection string in the web.config that points to our umbraco database. Everything compiles, but when I try to access MerchelloContext I get a null reference because there is no current context.
Here is the codebit that is failing...
From what I have read, this is occurring because the context is not being initiated in the startup of the project.
So I wondering what else I need to do other than add references for the umbraco.core and merchello.core to make this work.
Or is there a different API call that I can make to pull customer information outside or Umbraco.
Hi Chris
You can add custom api that will return all needed information. But it will take time and you will have full control over data.
Thanks,
Alex
Alex - Thanks for your reply. Do you have any details or examples about how to add a custom api?
Hi Chris,
Try to use "Merchello.Web.WebApi.MerchelloApiController" it's the same as UmbracoApiController but with Merchello context, read more about Umbraco API:
https://our.umbraco.org/documentation/implementation/Controllers/#umbraco-api-controllers
https://merchello.readme.io/docs/view-pages
Thanks,
Alex
Thanks, Again Alex! I will give the API a look.
Hi Alex -
No Luck. I created a web api controller and inherited from MerchelloApiController, but when I try to invoke the method, I get the same error as before, except this time it occurs when it tries to create the controller. Any other thoughts?
is working on a reply...