[not working] 'wix-forum.v2' posts.getPost(postId, options)

I’m trying to use the ‘wix-forum.v2’ getPost, but it always returns an error.

Forum Velo Link > getPost - Velo API Reference - Wix.com
Elevate Velo Link > elevate - Velo API Reference - Wix.com

I installed the Wix Forum, created a post which has the system ID “65d1dd9381c1180010307d70”, and my code setup is below. Note:

  1. The ID is correct (tried it with WIX search and it returns).
  2. It says it needs elevated permissions to work

Page code:

import { getPostFromFile } from "backend/forumEventsGetPost.jsw";

export async function text63_click(event) {

    let postId = "65d1dd9381c1180010307d70";

    const postIs = await getPostFromFile(postId);

    console.log("post is:");
    console.log(postIs);

}

Backend File:

import { posts } from 'wix-forum.v2';
import * as wixAuth from 'wix-auth';

export async function getPostFromFile(postId) {

    let options = {
        extraFields: ["IMAGES", "VIDEOS", "URL", "REACTION_IDENTITIES"]
    };
    
    const getPostNew = wixAuth.elevate(posts.getPost);

    try {
  
        const result = await getPostNew(postId, options);

        return result;
  
    } catch (error) {

        return ("error is:", error);
  
    }

 }

It always returns this:

image

Does anyone have any idea where I’m groing wrong?

Can you try doing a queryPosts() and seeing if the post result has the same id?

Beyond that the code looks correct.

Hi @anthony

Thanks for the message.

I tried the query post function today, which worked, I then tried the same code I posted previously without changing anything and it weirdly seemed to work, not entirely sure why! Was there an update?

However, I’m having the same issues with getCategory too. Can you spot any issues here, or should I just try it again in a few days and see if it’s magically repaired itself haha

(Continued) Page code:

import { getPostFromFile } from “backend/forumEventsGetPost.jsw”;
import { getCategory } from “backend/forumEvents2.jsw”;

export async function text63_click(event) {

let postId = "65d1dd9381c1180010307d70";

const postIs = await getPostFromFile(postId);

//see result in image
console.log("category is:", postIs.categoryId);

let categoryId = postIs.categoryId;
const categoryIs = await getCategory(categoryId);

console.log("category result is:");
console.log(categoryIs);

}

image

Backend File:

import { categories } from ‘wix-forum.v2’;
import * as wixAuth from ‘wix-auth’;

export async function getCategory(categoryId) {

let options = {
    extraFields: ["URL"]
};
  
const getCategoryName = wixAuth.elevate(categories.getCategory);

try {

    const result = await getCategoryName(categoryId, options);

    return result;

} catch (error) {

    return ("error:", error);

}

}

Many thanks!

What is the full error? Does applicationError say anything else and can you share the output of it as text?

Code looks fine otherwise except return ("error:", error) should be return {"error:", error} if you want to get back an object.

As for sharing code here you can format it like:

```js
const myCode = “here”;
```

which will display as:

const myCode = “here”;