N
Novu2y ago
empe

Headless: fetchNotifications method

I want to fetch the "actor" image, the relative path will be data[0].actor, but I'm not sure how it suppose to be represented... incase the actor has an actual image - should I get the URL? Or something?
12 Replies
empe
empeOP2y ago
Right now I'm using the default image for the actor, but it's not very straightforward for me
empe
empeOP2y ago
Over the Novu GUI, the image is an SVG file
empe
empeOP2y ago
@biswaviraj?
BiswaViraj
BiswaViraj2y ago
If you're using the user avatar option, then in the data field it will return the avatar url of the subscriber whose id was sent in the actor key during trigger you can add avatar to each subscriber during the creation of subscriber
await novu.subscribers.identify(user.id, {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
phone: user.phone,
avatar: user.profile_avatar, // avatar url here
locale: user.locale,
data: { custom1: 'customval1', custom2: 'customval2' },
});
await novu.subscribers.identify(user.id, {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
phone: user.phone,
avatar: user.profile_avatar, // avatar url here
locale: user.locale,
data: { custom1: 'customval1', custom2: 'customval2' },
});
await novu.trigger('<REPLACE_WITH_EVENT_NAME_FROM_ADMIN_PANEL>', {
to: [subscriber_id],
payload: {},
actor: { subscriberId: '<SUBSCRIBER_ID_OF_ACTOR>' }, // subscriberId of the actor whose avatar to be displayed
});
await novu.trigger('<REPLACE_WITH_EVENT_NAME_FROM_ADMIN_PANEL>', {
to: [subscriber_id],
payload: {},
actor: { subscriberId: '<SUBSCRIBER_ID_OF_ACTOR>' }, // subscriberId of the actor whose avatar to be displayed
});
empe
empeOP2y ago
I think that for testing purposes, it would be great to enable the option to edit subscriber information from the GUI.. Because for my use case now, I want to test the data I could fetch, but according to your response, I will need to trigger this action which is not that straight forward ....
Gali Baum
Gali Baum2y ago
You could also do update
Gali Baum
Gali Baum2y ago
Subscribers | Novu
Novu manages your users in a specific subscribers data model, that allows the Novu API to manage different aspects of the notification flow while providing an easy interface for triggering notifications.
empe
empeOP2y ago
Thanks Gali! I saying this because I believe it could improve the experience to be able to do it from the GUI 😁 BTW, is it possible to trigger this via Curl?
import { Novu } from '@novu/node';

const novu = new Novu(process.env.NOVU_API_KEY);

await novu.subscribers.identify(user.id, {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
phone: user.phone,
avatar: user.profile_avatar,
locale: user.locale,
data: { custom1: 'customval1', custom2: 'customval2' },
});
import { Novu } from '@novu/node';

const novu = new Novu(process.env.NOVU_API_KEY);

await novu.subscribers.identify(user.id, {
email: user.email,
firstName: user.firstName,
lastName: user.lastName,
phone: user.phone,
avatar: user.profile_avatar,
locale: user.locale,
data: { custom1: 'customval1', custom2: 'customval2' },
});
Gali Baum
Gali Baum2y ago
Yes
curl -X P0ST \
-H "Authorization: ApiKey REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"subscriberId": "subscriberId",
"email": "email",
"firstName": "firstName",
"lastName": "lastName",
"phone": "phone",
"avatar": "avatar",
"locale": "locale",
"data": data
}' \
https://api.novu.co/v1/subscribers
curl -X P0ST \
-H "Authorization: ApiKey REPLACE_WITH_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"subscriberId": "subscriberId",
"email": "email",
"firstName": "firstName",
"lastName": "lastName",
"phone": "phone",
"avatar": "avatar",
"locale": "locale",
"data": data
}' \
https://api.novu.co/v1/subscribers
empe
empeOP2y ago
Thank you!!
Gali Baum
Gali Baum2y ago
oops POST I did a zero instead of 0
empe
empeOP2y ago
curl --location --request POST 'https://api.novu.co/v1/subscribers' \
--header 'Authorization: ApiKey <REPLACE_WITH_API_KEY>' \
--header 'Content-Type: application/json' \
--data-raw '{

"subscriberId": "0123456789",
"email": "[email protected]",
"firstName": "Donald",
"lastName": "Duck",
"phone": "(717) 866-1766",
"avatar": "https://en.wikipedia.org/wiki/File:Donald_Duck_angry_transparent_background.png",
"locale": "en",
"data": {}

}'
curl --location --request POST 'https://api.novu.co/v1/subscribers' \
--header 'Authorization: ApiKey <REPLACE_WITH_API_KEY>' \
--header 'Content-Type: application/json' \
--data-raw '{

"subscriberId": "0123456789",
"email": "[email protected]",
"firstName": "Donald",
"lastName": "Duck",
"phone": "(717) 866-1766",
"avatar": "https://en.wikipedia.org/wiki/File:Donald_Duck_angry_transparent_background.png",
"locale": "en",
"data": {}

}'
Worked!
Want results from more Discord servers?
Add your server