Best solution for Web API authentication?

Vote:
 

Hi!

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?

#123327
Jul 01, 2015 15:17
Vote:
 

Hello Madis

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

David

#123337
Jul 01, 2015 18:19
Vote:
 

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 :)

#123342
Edited, Jul 02, 2015 7:48
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.