How to access 2sxc API from external non DNN website

160 views Asked by At

I am trying to access a 2sxc api using postman but is not working for some reason.

$2sxc(moduleContext)
      .webApi.get('app/auto/api/List/persons')

I am using [Domain]/DesktopModules/api/2sxc/counterApp/List/persons

But I get a 404 error.

Using $2sxc does work. But I want to make a call from a non DNN-website. The code: Foto: 2sxc api controller

2

There are 2 answers

1
Jeremy Farrance On BEST ANSWER

Are you inside the Content App or your own custom app?

If you are in the Content App, there automagic path is

https://example.com/DesktopModules/2sxc/api/app/content/content/Person
|------------------ root -------------------|- app/id --|-part--|--type

The above should just work without writing code (a controller).

If you're in your own custom app, then you will have written your own custom controller. Which you can read about here, ASP.net WebAPI in 2sxc. In the fake example, below that would be in Portals/0/2sxc/myapp/api/PublicController.cs

https://example.com/api/2sxc/app/myapp/api/public/persons
|------------------ root ----|-app/id--|-controller|-function
1
iJungleBoy On

There are 3 pieces of magic you must understand.

  1. Do you just want any content with REST (get all, 1, update, delete), custom queries or custom processing code
  2. The correct path
  3. Permissions

In general, all the examples that use $2sxc will also work from external, but you must modify the URL (because auto-detection doesn't work) and you must set permissions.

For the URL-path you can use the same one as $2sxc calls (check your F12 JS Console) but substitute auto with the app name, as auto won't work outside of DNN.

For permissions you must add them at the content-type level (the person-icon on the side of the content-types)

Good news BTW: 2sxc 11.08 or 11.09 will have a lot of guidance built into the admin-UI just for this use case :)