Trigger a topic

Hey all! Today I updated the .NET SDK to the newest version and I try to send a notification to a topic. The novu.Event.TriggerTopicAsync method which is mentioned in https://docs.novu.co/quickstarts/.NET#sending-a-notification-to-a-topic is not available in the newest SDK version 0.3.3 When I just want to know which API I need to call, I checked out the API reference at https://docs.novu.co/api-reference but there is no API for sending a notification to a topic. Can someone tell me the API for sending a notification to a topic?
11 Replies
Gali Baum
Gali Baum14mo ago
var payloadTopic = new EventTopicTriggerDto
{
EventName = "onboarding",
Payload = onboardingMessage,
To = { Type = "Topic", TopicKey = "frontend-users" },

};

var triggerTopic = await novu.Event.Trigger(payloadTopic);
var payloadTopic = new EventTopicTriggerDto
{
EventName = "onboarding",
Payload = onboardingMessage,
To = { Type = "Topic", TopicKey = "frontend-users" },

};

var triggerTopic = await novu.Event.Trigger(payloadTopic);
@Sebastian Küsters could you please try something like this?
Sebastian Küsters
Sebastian KüstersOP14mo ago
@Gali Baum thanks for the response - via the .NET SDK I can not extend the object dynamically like in node.js For that reason I think the best is that I get information about the API, so that I can do the call without using the SDK. Can you help me there?
Novu_Bot
Novu_Bot14mo ago
@Sebastian Küsters, you just advanced to level 2!
Gali Baum
Gali Baum14mo ago
It is using same trigger endpoint https://docs.novu.co/api-reference. For a topic you ,the to attribute in the request is:
to:[{type: 'Topic', topicKey: <your-topic-key>}]
to:[{type: 'Topic', topicKey: <your-topic-key>}]
Novu
Start Point - Novu
Novu is an open-source notification infrastructure, built for engineering teams to help them build rich product notification experiences.
Gali Baum
Gali Baum14mo ago
@Sebastian Küsters let me know if it works for you 🙂
Sebastian Küsters
Sebastian KüstersOP14mo ago
Will try it out later - right now I am seeding the local setup. There I am facing some timeout issues agains Novu API when calling GET topics - need to check this first out. But I will update you as soon as I tried it. @Gali Baum today I found time to seed our new account in the EU region. I tried to trigger the topic as you descibed, but no success :/ Via .NET SDK the response is:
{"message":"workflow_not_found","error":"Unprocessable Entity","statusCode":422}
{"message":"workflow_not_found","error":"Unprocessable Entity","statusCode":422}
This is the .NET snippet:
var dto = new EventCreateData()
{
EventName = notification.WorkflowTriggerId,
Payload = notification.Payload,
Overrides = new
{
Name = notification.WorkflowTriggerId,
To = new
{
Type = "Topic",
TopicKey = topicKey
}
}
};
var novuResponse = await _novuClient.Event.Trigger(dto);
var dto = new EventCreateData()
{
EventName = notification.WorkflowTriggerId,
Payload = notification.Payload,
Overrides = new
{
Name = notification.WorkflowTriggerId,
To = new
{
Type = "Topic",
TopicKey = topicKey
}
}
};
var novuResponse = await _novuClient.Event.Trigger(dto);
Now I tried it via curl and get a successful reponse, but nothing happens and the Acitivy doesn't appear in the portal:
curl -X POST https://eu.api.novu.co/v1/events/trigger \
-H "Authorization: ApiKey XXX" \
-H "Content-Type: application/json" \
-d '{
"name": "files-uploaded",
"to": [
{
"type": "Topic",
"topicKey": "files-uploaded_8979296d-0c0c-4d83-bd0e-d58e66fc8cc2"
}
],
"payload": {
"folderName": "Hello World"
}
}'
curl -X POST https://eu.api.novu.co/v1/events/trigger \
-H "Authorization: ApiKey XXX" \
-H "Content-Type: application/json" \
-d '{
"name": "files-uploaded",
"to": [
{
"type": "Topic",
"topicKey": "files-uploaded_8979296d-0c0c-4d83-bd0e-d58e66fc8cc2"
}
],
"payload": {
"folderName": "Hello World"
}
}'
Response:
{"data":{"acknowledged":true,"status":"processed","transactionId":"0c291d7a-bbb6-4895-a869-50dca774a65e"}}
{"data":{"acknowledged":true,"status":"processed","transactionId":"0c291d7a-bbb6-4895-a869-50dca774a65e"}}
Pawan Jain
Pawan Jain14mo ago
@sebastiankuesters Did you create this topic with key files-uploaded_8979296d-0c0c-4d83-bd0e-d58e66fc8cc2 before triggering the workflow using cURL I could not find this topic files-uploaded_8979296d-0c0c-4d83-bd0e-d58e66fc8cc2 I see in logs Topic with key files-uploaded_8979296d-0c0c-4d83-bd0e-d58e66fc8cc2 not found in current environment
Sebastian Küsters
Sebastian KüstersOP14mo ago
@Pawan Jain thanks for the hint - I will double check it... @Pawan Jain thanks for sharing the information - now it works. Maybe improve the error message here - because workflow_not_found is misleading. Moreover I have to tell you that I wrote this so fast without investigation, because you describe nowhere in your docs how to actually trigger a topic. Only thanks to the hint by @Gali Baum here https://discordapp.com/channels/895029566685462578/1166659906460463165/1166673489869164564 I got a hint. It's just feedback to improve the docs - beside that thanks you both for the great support here 🙏
Pawan Jain
Pawan Jain14mo ago
Hi @Sebastian Küsters Thanks for sharing it worked. We will update the docs
empe
empe14mo ago
Do we have a ticket for that?
Want results from more Discord servers?
Add your server