Reactions using REST

Hey Team,

We need to get a list of people reacting to a post.

We found that the SDK does not yet support this. However, we do need to get this feature running and we found that we might be able to get the data from REST instead of relying on SDK websockets.

We want to be able to use this endpoint Swagger UI

Could you please help clarify on what are the parameters that is required to be passed.

  "referenceId": "string",
  "referenceType": "message",

We can generate the token using this which is understandable

  -H 'authority: api.ekomedia.technology' \
  -H 'user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1' \
  -H 'x-api-key: XXX' \
  -H 'content-type: application/json' \
  -H 'accept: */*' \
  -H 'origin: http://localhost:3000/' \
  -H 'sec-fetch-site: cross-site' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-dest: empty' \
  -H 'referer: http://localhost:3000/' \
  -H 'accept-language: en-US,en;q=0.9' \
  --data-raw '{"userId":"21990011","displayName":"test@7peakssofwtwaresoftware.com","deviceId":"ekowebsdkx0a52a10b4-4926-4032-88d5-0eef4acd3b501621927209082","deviceInfo":{"version":"4.4.3","kind":"web","model":"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"}}' \
  --compressed

We tried using this to get the data

  'https://api.staging.ekomedia.technology/api/v2/reactions' \
  -H 'authorization: Bearer x.x' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "referenceId": "b424727f94d2c6412c8582f02f08ef5d",
  "referenceType": "birthday.post",
  "reactionName": "like"
}' | python -m json.tool

Response >>>
{
    "code": 500000,
    "message": "Not found",
    "status": "error"
}

Can anyone help on suggesting on how to get this done please as the error is vague and not descriptive.

Hello !

Let me help answering your questions.

On the problem that you have concerning the rest request, I believe this is because the token bearer value is not matching any known network ; I do understand you redacted it for security reasons, but it seems you are targeting our staging instance which is reserved from Amity’s quality control and internal testing usage ; therefore your network might not be there.

Please do know that the APi functions are in fact available in the web sdk for your usecase. The functions you’re looking for are located in:

import {
  ReactionRepository,
  ReactionReferenceType,
} from '@amityco/js-sdk'

ReactionRepository.reactionsForReference({
  referenceId: postId,
  referenceType: ReactionReferenceType.Post,
}) 

That said, while building a quick example to help you get through this I found a tiny bug in that function so I’ll add to publish a patch along with the next release and let you know.

About why you may have not known about this feature in our SDK, I will raise the feedback to the our documentation team.

If you have any more questions please do let me know.
Julien

@Julien, thanks for the response.

We are actually using eko-sdk , however, we did try with the @amityco/js-sdk but it still does not give us the correct response for existing data.

Could you help clarify what is the referenceId has to be passed?

We are receving dataStatus as “not-exist” for a referenceId that exists (please see the image attached)
image

However when i try with the REST API, i am able to recieve the response as below
image

Please help look into this issue and help us the correct way to get the data from the SDK, any suggestion is much appreciated.

Also which SDK should we be using, do you recommend @amityco/js-sdk as this is not documented on the documentation?

Hello @sijanhs !

The referenceId should normally be either a postId, a commentId or a messageId.

According to your screenshot about the LiveCollection, you may be experiencing a false positive (or not). Live Collections are stateful objects created synchronously, but they do query data a bit later on, and populates themselves back asynchronously as well ; therefore you should listen to the “dataUpdated” event and look for the models passed in the event listener rather than looking at values in the object directly as those may change over time.

Concerning the REST APi, please know that it’s currently not recommended nor advertised to use it on your end. We’re constantly working on improving it and signatures may change quite often. It is recommended to use SDKs instead.

About the choice of eko-sdk vs @amityco/js-sdk, it is actually the same package with few differences in naming. We will keep patching the eko-sdk for backward compatibility reasons for customers who already use it and depends on it, but the newly published @amityco/js-sdk is the one on which we will continue to deploy new features moving forward.

As a confirmation of my saying in my earlier post, the web team is actively working on the issue you spotted and will come back to you shortly with a patch in the coming days/weeks.

Please stay tuned :slight_smile:

Thanks for the quick feedback.

We did try listening to “dataUpdated” section however we got the same response as not-exist that we previously encountered.

I would request your help suggest on how to resolve this.

Please find our implementation and response below for our react application. Just FYI, the dataUpdated never got triggered

And also we encountered that we cannot use ReactionRepository without instantiating it.

  const reactionCollection = useRef();
  const reactionRepo = new ReactionRepository();

  useEffect(() => {
    reactionCollection.current = reactionRepo.reactionsForReference({
      referenceId,
      referenceType: ReactionReferenceType.Post,
    });
   console.log({ reactionCollection.current });

    reactionCollection.current.on('dataUpdated', (data) => {
      console.log({ data });
    });

    reactionCollection.current.on('dataError', (error) => {
      // eslint-disable-next-line no-console
      console.log({ error });
    });

    return () => reactionCollection.current.dispose();
  }, [referenceId]);

1 Like