How to get the access token

Hello Amity team,

Our React Web app uses this UIKit open source for the social feed.
I’d like to customize this UIKit web open-source and specifically, integrate the content-search API.

Here, I will share the code I created.

const data = {
  "apiKey": "",
  "userId": "0e57c7a3f404ff343",
  "query": {
      "targetId": [
          "4f0153714fdb10e0d2"
      ],
      "targetType": "community",
      "postedUserId": "b20e57c7a340ff4783"
  },
}

const response = await fetch("https://beta.amity.services/search/posts", {
  method: "POST",
  body: JSON.stringify(data),
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bear xxxxxxxx"
  },
});
const result = await response.json();

console.log(result);

I want to know how I can get a “Bear” token for “Authorization” of the request headers.
In amityco/js-sdk, there is a function to get the access token created?
As you can see in the following screenshot, a token exists already.

Please help me to resolve this issue.
Thank you,
Chentao

Hello, we will look into this and get back to you. Thank you :pray:

Hello, please follow steps below:

  1. Obtain an access token using the JS SDK by referring to the documentation here: https://docs.amity.co/amity-sdk/core-concepts/user/user-token-management
  2. It is recommended to use the endpoint https://beta.amity.services/search/v2/posts (v2) rather than v1 for better functionality.
  3. Please pass the auth token in the body, please note an access token is not required for this step.
    {
    “apiKey”: “”,
    “userId”: “0e57c7a3f404ff343”,
    “authToken”: “auth”,
    “query”: {
    “targetId”: [
    “4f0153714fdb10e0d2”
    ],
    “targetType”: “community”,
    “postedUserId”: “b20e57c7a340ff4783”
    },
    }

Thank you for your reply. I will try without the access token.

The content-search API works without the access token. Thank you for your help.

Another question.
Is there a way to get the total post number of the user? (The content-search API can return this total number?)
I need this number for the pagination.
Please let me know.
Thank you,
Chentao

Hello, for the best practice in obtaining the total number of posts, we recommend using our webhook. This approach will provide you with comprehensive user-related information, including posts.

Hi Amity support, Thank you for your reply.
What is the webhook name?
As I said already, I am getting the posts using the content-search API.
I want to get the count of all posts that the content-search API can return.
The existing webhook can return the same result as the content-search API?
If you don’t make sense my question, please let me know.
Thank you,
Chentao

Hello, you can utilize this webhook event: Amity API

The number should be the same as content search because webhook event is generated immediately after a post is successfully created.

Alternatively, if you prefer to use content search, you can accumulate the number(count) of post IDs returned in the response. Please keep in mind that content search returns a maximum of 100 items per call, so you will need to use pagination to retrieve the next values.

Pagination: Using from and size

Screenshot 2566-12-06 at 13.13.31