question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API Connection returns 400 "Bad Request" when Logic App and Connection was created in VS Code

See original GitHub issue

Dear all,

I was trying to create a Logic App (Standard) that simply sends an email via SMTP API Connection when the Logic App is called via Http webhook.

Since the scenario we are working in demands the use of Terraform IaC deployment, I created and Deployed my Logic App in a Terraform configuration. Afterwards, I created a Logic App (Standard) project in Visual Studio code and created a workflow, including the API Connection to my smtp test server. After deploying the project to my Logic App (Standard) resource via VSCode, I triggered the workflow and got a 400 “Bad request” when the SMTP Send Email action tried to call the API Connection.

{ "status": 400, "source": "https://logic-germanywestcentral-001.token.azure-apihub.net:443/tokens/logic-apis-germanywestcentral/8af2fb4fc6724ebc/smtp/a09a483c3c************************/exchange", "message": "Error from token exchange: Invalid Authorization header. Authorization header is expected in the form 'Bearer token' or 'Key token'." }

Screenshot 2021-12-15 125631

When I created the Logic App (Standard) in the Azure Portal (same subscription, same storage account, same App Service Plan), the connection works just fine.

An ARM template export shows a difference between the resource deployed by Terraform and Logic App project in VS Code (Left side of the images) and the resource I created in the Azure Portal (right side), although the portal view shows no difference.

MicrosoftTeams-image (1) MicrosoftTeams-image (2)

Is there any special way of handling the workflows/connections if they are deployed with VS Code?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12

github_iconTop GitHub Comments

2reactions
tiagoacosta17commented, Aug 26, 2022

Thanks @jjdeventer ! yesterday also had the same issue with service bus and now this helped.

2reactions
jjdeventercommented, Aug 25, 2022

Hi guys,

I had the same problem. What i did was the following:

  1. First from Visual Studio add the Action and go through the Authorization flow (in my case i am using the Outlook - Send E-mail from shared mailbox action). Result of this step is the API connection being created in the resource group you selected when adding an Azure action. Under the hood, also two files are being modified: connections.json and local.settings image Important part here is the parameter, that is pointing to @appsetting office365-connectionKey. That key is actually added to another file: the local.settings file image This is the key that is needed during runtime.

  2. When you now deploy the Logic App to your app service plan, that value is not being added to your configuration. You have to do this manually in the Configuration section of the Logic App (in this example in the Azure Portal UI). image Add a new Application Setting and name it exactly the same as the @appsetting, in my case office365-connectionKey. The value is the key from the local.settings file mentioned earlier. Don’t forget to save! This should do the trick. Now during runtime, the Logic App will fetch the key from the configuration and pass it to the API connection. Hope this helps!

Kind regards,

Jeroen

Read more comments on GitHub >

github_iconTop Results From Across the Web

Logic apps cannot handle 'Bad Request'
I'm new to Azure Dev. Trying to check statuscode after generating a request in an 'if' condition. It works fine when I get...
Read more >
Receive inbound or incoming HTTPS calls - Azure Logic ...
Receive incoming or inbound HTTPS calls or requests to workflows in Azure Logic Apps ... the trigger returns an HTTP 400 Bad Request...
Read more >
HTTP-BadRequest - Microsoft Q&A
400 Bad Request means that the request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat...
Read more >
Azure App service 400 Bad request! — A STORY | by Roopa V R
400 in particular means that the request could not be understood by the server due to malformed syntax and the client SHOULD NOT...
Read more >
Azure Logic Apps – Handling retry behavior with response ...
Azure Logic Apps – Handling retry behavior with response codes in NodeJS Function (HTTP 400, or 500) – SecureCloudBlog.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found