azureazureservicebusazure-servicebus-topicsazure-eventgrid

Failed to start logic app run for Event Grid trigger


I am following this tutorial to send a message from service bus topic to email using Event Grid.

When I run the Logic App, I get the following error:

Failed to start a run of logic app test-servicebusq. The template language expression evaluation failed: 'The execution of template trigger 'When_a_resource_event_occurs' failed: the result of the evaluation of 'splitOn' expression '@triggerBody()' is of type 'Null'. The result must be a valid array.'

When I send a message to the service bus, the logic app does not get triggered at all.

I have turned of the 'splitOn' and when I run the logic app manually, the trigger gets fired and the logic app is executed, but when I send a message to the service bus topic, the trigger does not get triggered automatically (unless I manually Run the logic app).

I want the logic app to be automatically triggered when a new message arrives in the service bus.

Is there something I am doing wrong? I followed the tutorial step by step and I am still unable to figure out what is the problem. Do I need to create an event grid resource somewhere? (it is not mentioned in the tutorial)

Edit: I am using the following code to send the message

from azure.servicebus import ServiceBusClient, ServiceBusMessage

connstr = <connection string>
topic_name = "fileincomplete"


with ServiceBusClient.from_connection_string(connstr) as client:
    with client.get_topic_sender(topic_name) as sender:
        sender.send_messages(ServiceBusMessage("Data12"))


Solution

  • After reproducing in my local environment, I could able to make this work after mentioning the Event Type Item. Below is my logic app flow.

    enter image description here

    I am using the below code to send the messages

    from azure.servicebus import ServiceBusClient, ServiceBusMessage
    
    CONNECTION_STR = "<YOUR_NAMESPACE_CONNECTION_STRING>"
    TOPIC_NAME = "<YOUR_TOPIC_NAME>" 
    
    servicebus_client = ServiceBusClient.from_connection_string(conn_str=CONNECTION_STR, logging_enable=True)
    
    with servicebus_client:
        sender = servicebus_client.get_topic_sender(topic_name=TOPIC_NAME)
        with sender:
            message = ServiceBusMessage("Data12")
            sender.send_messages(message)
            print("Sent a single message")
    

    RESULTS:

    enter image description here