Skip to content

Following the API docs but its not clear ...

Solved Customisation
  • I want some widget code to be able to make a topic post in certain circumstances
    I generated an API key under userID 1
    but Im unsure where to put this key, in some APIs it would go as a BearerID in the body, and sometimes it goes as a key concatenated to the endpoint…
    but its not specified in the docs exactly how to do it
    https://docs.nodebb.org/api/write/#tag/topics
    Also usually you would expect to have to supply a Method type as POST?
    The code is currently along these lines

    const bodyData={
    "cid": 1,
    "title": "Test topic",
    "content": "This is the test topic's content",
    "timestamp": 556084800000,
    "tags": [
    "test",
    "topic"
    ]
    }
    const key='c56.. //redcated
     fetch(
       `https://aignite.nodebb.org/api/v3/topics/', bodyData
    )
    .then(response => response.json())
    .then( data=> {....
    

    I wonder if you don’t have to supply the key if its done with an Authentication cookie, but the above code doesnt work.
    Perhaps the bodyData parameter is in wrong place?

  • @Panda Here’s how I’ve done it using basic CURL commands in PHP - you should be able to gain an understanding of structure at least.

    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, 'http://localhost:5001/api/v3/topics');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "title=api test post&content=the contents of the test post&cid=1&_uid=1");
    
    $headers = array();
    $headers[] = 'Authorization: Bearer d2b8602d-01a6-86ee-bbe4-0e016144be0c';
    $headers[] = 'Content-Type: application/x-www-form-urlencoded';
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    
    $result = curl_exec($ch);
    if (curl_errno($ch)) {
        echo 'Error:' . curl_error($ch);
    }
    curl_close($ch);
        
        }
        // Item has already been processed. Continue loop until count exhausted
        else {
            echo "Checking " .
                "\nLine item already processed - \033[33m[Ignored]\n\033[0m";
        }
    }
    
  • @phenomlab
    OK. The official docs are lacking in detail (in comparison to usual API example docs)
    They omit any mention of headers and BearerID - which it seems from your example are required.
    How did you figure out that combination? Did you see more extensive documentation?

    I will try and replicate the same with a JS fetch, if not I will make a topic on NodeBB Community

  • Update, adding those fields in …

    The API code doesn’t work from a widget, but from a stand-alone hosted code it gives this error
    Error with Permissions-Policy header: Origin trial controlled feature not enabled: ‘interest-cohort’.
    Is that like a CORS issue? Is there a fix for that?

  • Update: It was a CSRF token issue.
    I hadn’t even heard of one of those 😁

  • @Panda said in Following the API docs but its not clear ...:

    How did you figure out that combination? Did you see more extensive documentation?

    There’s documentation all over the Internet in relation to curl and not really “NodeBB” specific. It’s one of the headers and required for authentication.

    A search for curl on NodeBB also shows this in detail

    https://community.nodebb.org/search?term=Curl&in=titlesposts&matchWords=all&showAs=posts

  • @phenomlab
    Yes just searched
    Found some curl things on a PhP related post on NodeBB now …
    I’m quite surprise anyone was using Curl and PhP with NodeBB !

  • @Panda you’d be surprised. If you consider that you’d need to use the API to be able to populate a WordPress widget for example (which in turn would of course be PHP), taking this route is still immensely popular.

  • phenomlabundefined phenomlab has marked this topic as solved on

Did this solution help you?
Did you find the suggested solution useful? Why not buy me a coffee? It's a nice gesture, and a great way to show your appreciation 💗

  • 2 Votes
    3 Posts
    154 Views

    Ah silly me, thanks for finding that!

  • SEO and Nodebb

    Performance
    2
    2 Votes
    2 Posts
    143 Views

    @Panda It’s the best it’s ever been to be honest. I’ve used a myriad of systems in the past - most notably, WordPress, and then Flarum (which for SEO, was absolutely dire - they never even had SEO out of the box, and relied on a third party extension to do it), and NodeBB easily fares the best - see below example

    https://www.google.com/search?q=site%3Asudonix.org&oq=site%3Asudonix.org&aqs=chrome..69i57j69i60j69i58j69i60l2.9039j0j3&sourceid=chrome&ie=UTF-8#ip=1

    However, this was not without significant effort on my part once I’d migrated from COM to ORG - see below posts

    https://community.nodebb.org/topic/17286/google-crawl-error-after-site-migration/17?_=1688461250365

    And also

    https://support.google.com/webmasters/thread/221027803?hl=en&msgid=221464164

    It was painful to say the least - as it turns out, there was an issue in NodeBB core that prevented spiders from getting to content, which as far as I understand, is now fixed. SEO in itself is a dark art - a black box that nobody really fully understands, and it’s essentially going to boil down to one thing - “content”.

    Google’s algorithm for indexing has also changed dramatically over the years. They only now crawl content that has value, so if it believes that your site has nothing to offer, it will simply skip it.

  • 2 Votes
    2 Posts
    149 Views

    @cagatay this relates to a change the css classes used for the brand header meaning it will now float to the left instead of right.

    If you’d like to retain the original behavior, you can add this css class

    [data-widget-area="brand-header"] { justify-content: end; display: flex; }

    Further information here

    https://community.nodebb.org/topic/17090/manual-build-a-custom-header-in-harmony/19?_=1684069325296

  • NodeBB: Consent page

    Solved Configure
    16
    4 Votes
    16 Posts
    559 Views

    @DownPW I still do not see any issues.

  • 13 Votes
    22 Posts
    1k Views

    Been playing with the user profile page this afternoon. Thought I’d post a video as I’m really pleased with how this came out

  • Rotating homepage icons, gifs?

    Solved Configure
    2
    3 Votes
    2 Posts
    195 Views

    @eveh It’s not a GIF, no. It’s actually a webp file so made much smaller, and uses keyframes to control the rotation on hover. You can easily make your own though 🙂

    The CSS for that is as below

    @keyframes rotate180 { from { transform: rotate(0deg); } to { transform: rotate(180deg); } } @keyframes rotate0 { from { transform: rotate(180deg); } to { transform: rotate(0deg); } }

    Your milage may vary on the CSS below, as it’s custom for Sudonix, but this is the class that is used to control the rotate

    .header .forum-logo, img.forum-logo.head { max-height: 50px; width: auto; height: 30px; margin-top: 9px; max-width: 150px; min-width: 32px; display: inline-block; animation-name: rotate180, rotate0; animation-duration: 1000ms; animation-delay: 0s, 1000ms; animation-iteration-count: 1; animation-timing-function: linear; transition: transform 1000ms ease-in-out; }
  • 0 Votes
    5 Posts
    393 Views

    @qwinter this particular site uses the code I wrote if you want to see it in action. It’s a information and intelligence gatherer I designed for collecting various information security articles from around the globe and consolidating them in one place.

    Essentially, each “post” is in fact generated by the script, and the NodeBB API.

    https://hostrisk.com/

  • 0 Votes
    3 Posts
    684 Views

    Closing this thread as a duplicate of https://sudonix.com/topic/12/nodebb-customisation