I have created an Web API endpoint in the latest version of EPiServer Commerce 8.13.4 web project for product image integration with PIM. What it does is that it takes in the URL of an image and downloads it, then adds it to some entry. Unfortunately as I call the ContentRepository Save function it gives me error:
"Procedure or function 'editPublishContentVersion' expects parameter '@UserName', which was not supplied."
As the procedure is called from an external system, there is no User associated with the request.
What would be the best solution to authenticate the external system calling the Web API endpoint?
I suggest you take a look at the ServiceAPI: http://world.episerver.com/serviceapi. This was specifically created for integration with PIM's.
Otherwise if you wish to continue with your code then you can impersonate any user you wish by adding this line of code before running your code:
PrincipalInfo.CurrentPrincipal = PrincipalInfo.CreatePrincipal("your.username");
Any code run after this line will run under the "your.username" user
Let me know how you get on
Ok, thanks! It worked!.
I know about the ServiceAPI. Unfortunately there is no option for importing new media into EPiServer other than XML bulk import, which is not very convenient for updating pictures. We need to keep track of file names (that's all that PIM knows) so that we know which ones are new and which to be deleted, since PIM gives us only the current data. The catalog item assets subsystem allows only for creating relations between assets and entries and it gives out only asset ID, not filename or even integration ID.
Everything else we have integrated using Service API :)