Trying to call a workflow from a visual studio webform using vb.net code

My problem is that I am trying to call a workflow from a visual studio webform using vb.net code. I tried using both process.start(workflowurl) and a hyperlink using the workflow url. Both of those approches are a “Get” call, while my workflow is to allow downloading a file using an ftp node and a response node, which needs to be a “Post” request. Does not work. I also tried the following code using httpclient and it does not work. Do you have a way to call an ftp workflow from a webform using vb. net code? Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
Page.RegisterAsyncTask(New PageAsyncTask(AddressOf MyAsyncMethod))
End Sub

Private Async Function MyAsyncMethod() As Task

'Dim webhookUrl As String = "http://localhost:5678/webhook-test/823f20b4-f8fd-4736-b257-d9418dccffd8" ' Replace with your actual webhook URL
Dim webhookUrl As String = "https://silly-eel-99.hooks.n8n.cloud/webhook/fbcd3019-1603-4a1c-8f41-941bfb55387e"

'Dim jsonPayload As String = "{""name"": ""John Doe"", ""email"": ""[email protected]""}" ' Example JSON data to send

Using httpClient As New HttpClient()
    Try
        'Dim content As New StringContent(jsonPayload, Encoding.UTF8, "application/json") ' Set content type to JSON

        'Dim response As HttpResponseMessage = Await httpClient.PostAsync(webhookUrl, Content) ' Make the POST request
        Dim response As HttpResponseMessage = Await httpClient.GetAsync(webhookUrl) ' Make the POST request

        If response.IsSuccessStatusCode Then
            ' Workflow triggered successfully
            Console.WriteLine("n8n workflow triggered successfully!")
        Else
            ' Handle potential errors (e.g., incorrect URL, network issues)
            Console.WriteLine($"Error triggering n8n workflow: {response.StatusCode} - {Await response.Content.ReadAsStringAsync()}")
        End If

    Catch ex As Exception
        ' Handle any exceptions during the HTTP request
        Console.WriteLine($"An error occurred: {ex.Message}")
    End Try
End Using
Await Task.Delay(10000) ' Example delay

End Function

If the n8n webhook is protected with authentication, you’ll need to add the appropriate headers. It’s important to check if the n8n server is accessible from where the VB.NET application is running. If you’re working in a local environment (localhost), you may need to expose n8n with tools like ngrok for external testing.

A webhook in n8n is an HTTP entry point that allows you to start a workflow when it receives an HTTP request (GET, POST, etc.).

  • Create a workflow in n8n that starts with a Webhook node.

  • Copy the URL generated by the webhook (it can be something like: https://your-n8n-server/webhook/test).

  • From your VB.NET code, make an HTTP POST or GET call to that URL, sending data if necessary.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.