Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ho Chia Leung 5 posts 77 karma points
    Oct 03, 2018 @ 09:00
    Ho Chia Leung
    0

    How to get Content via API, with condition, using plugin or webapi?

    Hello all,

    I am new to Umbraco, and trying hard to get API working. I just need something simple like /umbraco/api/articles?articleAuthor=john wick

    Here's what I've tried:

    1. Install Tapas plugin (https://github.com/joeriks/tapas). Works great, but no option to filter by property (eg: articleAuthor = "john wick")
    2. Try to create my own controller inheriting UmbracoApiController, following https://our.umbraco.com/documentation/reference/routing/webapi/ but can't get it working. Here's the screenshot enter image description here

    Edit: trying to call the api: enter image description here Am I doing anything wrong here?

    Thanks in advance!

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    Oct 03, 2018 @ 09:25
    Amalie Wowern
    0

    Hi How are trying to call the controller from the screenshot?

    It should be yoursite.com/umbraco/api/products/getallproducts

  • Ho Chia Leung 5 posts 77 karma points
    Oct 03, 2018 @ 09:42
    Ho Chia Leung
    0

    Hello,

    I've attached my postman get request result up there!

    Thanks!

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    Oct 03, 2018 @ 09:45
    Amalie Wowern
    0

    Can you add

    [System.Web.Http.HttpGet]
    
    public IEnumerable<string> GetAllProducts()
    

    And of course remember to build

  • Ho Chia Leung 5 posts 77 karma points
    Oct 03, 2018 @ 10:07
    Ho Chia Leung
    1

    Did this, but still the same.

    I can't find any guide to build the project in Visual Studio Code. I assume starting IIS Express will build it?

    enter image description here

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    Oct 03, 2018 @ 10:25
    Amalie Wowern
    0

    I think you need to build it.

    Do you have a normal visual studio?

    I googled build in vs code and my first result is this https://code.visualstudio.com/docs/languages/csharp

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    Oct 03, 2018 @ 10:38
  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    Oct 03, 2018 @ 09:46
    Amalie Wowern
    0

    And maybe rename the controller folder to "Controllers"

  • Ho Chia Leung 5 posts 77 karma points
    Oct 03, 2018 @ 12:05
    Ho Chia Leung
    1

    FINALLY! I found the solution!! After all the trouble while trying to move my existing website from VS Code to Visual Studio, and build them

    In order to have Visual Studio Code to "build" the website, all the .cs code must be in App_Code folder, as such: enter image description here Result: enter image description here

    Thanks for your help!!

Please Sign in or register to post replies

Write your reply to:

Draft