Search code examples
node.jsgetstream-io

InputException Occuring in GetStream.io when tring to Add Reactions for an activity form NodeJS


When I try to add reaction to an activity, it shows an error message that user_id cannot be empty. As per the doc, there where no field to pass the user id in JS/NODE sample code. please help.

Language: Node JS

Code Used :

await client.reactions.add("like", activity.id );

also tried

await client.reactions.add("like", activity.id, "jack" );

Response: Error

Details : '{"detail":"Errors for fields \'user_id\'","status_code":400,"code":4,"exception":"InputException","exception_fields":{"user_id":["user_id is a required field"]},"duration":"0.16ms"} with HTTP status code 400' }


Solution

  • If your client is a serverside client(initialized with api key and api secret), you need to specify the user_id in the call to reactions.add. If you use a clientside integration(initialized with api key, user token and app_id), the user_id doesn't need to be specified.

    For serverisde your code will be:

    const userId = 'bob';
    await client.reactions.add('like', activity.id, null, { userId });
    

    For clientside you will have:

    const token = srvClient.createUserToken('bob'); //srvClient is initialized with apiKey and apiSecret
    const client = stream.connect(
        apiKey,
        token,
        appId,
    );
    await client.reactions.add('like', activity.id);