Power Platform error:502 message: ad Gateway - power-automate

I am trying to run my app which is posting data through a flow which connects to an API. When I test my flow in Power Automate it runs successfully but when I Run() it in Power Apps it gives me a 502 error , Bad Gateway message. In my flow I provide a POST body in JSON since I used the "Ask in Power Apps" option and it appends the body value with a HTTP_Body variable. My flow body looks like this:
{
"username":"example.com",
"password":"mypassword"
}
I also have basic authentication which I use the same values and pass as plain text in flow and is requested as a parameters in my flow.Run(). I need to know how I can pass my HTTP_Body in Power Apps from two textboxes(username.Text and password.Text) avaialable from my Login page since i suspect that is where my error is coming from?
Any quick help would greatly appreciated!
I have tried :
.Run({username: txtusername.Text,password: txtPwd.Text},txtusername.Text,txtPwd.Text)) and tried UpdateContext to create a record but the error persists.

Related

API Gateway error "Unsupported Media Type" when trying to accept application/x-www-form-urlencoded data

I am using the following tutorial:
https://www.twilio.com/docs/sms/tutorials/how-to-receive-and-reply-python-amazon-lambda
When I test the api in aws I receive a 415 error, Unsupported Media Type.
I assume this is related to the fact that Twilio sends its data in the form of application/x-www-form-urlencoded and AWS wants json.
The tutorial takes this into account. However, its code does not work for me.
I have searched the web, and tried numerous fixes to no avail.
The raw data from Twilio is (with sensitive information changed)
ToCountry=US&ToState=AK&SmsMessageSid=SM7777777777777777777777&NumMedia=0&ToCity=AAA&FromZip=99999&SmsSid=SM9999999999999999999&FromState=AK&SmsStatus=received&FromCity=BBB&Body=Is+this+json+&FromCountry=US&To=%2B15555555555&ToZip=88888&NumSegments=1&ReferralNumMedia=0&MessageSid=SM888888888888888888&AccountSid=AC6666666666666666&From=%2B14444444444&ApiVersion=2010-04-01
I enter this information in the body section of the test, run the test and the error is thrown.
There is also the same error when I try the actual webhook through Twilio.
I have also entered with surrounded in {}
I have also tried a jsonified version with the ampersands changed to commas, and the equal signs changed to colons with the items in quotes.
I also have tried:
{
"to_number": "+14444444444",
"from_number": "+15555555555",
"message": "hello does this API work"
}
I have also tried to add the following to the header of the test
"Content-Type": ["application/x-www-form-urlencoded"]
Many of the fixes I have tried involve changing the Integration Request mapping.
None have worked.
The one from the tutorial is:
#set($httpPost = $input.path('$').split("&"))
{
#foreach( $kvPair in $httpPost )
#set($kvTokenised = $kvPair.split("="))
#if( $kvTokenised.size() > 1 )
"$kvTokenised[0]" : "$kvTokenised[1]"#if( $foreach.hasNext ),#end
#else
"$kvTokenised[0]" : ""#if( $foreach.hasNext ),#end
#end
#end
}
And is of content type application/x-www-form-urlencoded
There is a stack on this topic:
Amazon Api gateway integration with Twilio
None of its solutions worked for me.
I thought the following was very promising, but it also failed for me.
https://gist.github.com/199911/68a43f83fd933b1e3ac6
I have also tried to change the lambda function. However I do not think it is the source. Its tests work.
Any help would be much appreciated.
Quote from AWS console:
You can configure binary support for your API by specifying which media types should be treated as binary types. API Gateway will look at the Content-Type and Accept HTTP headers to decide how to handle the body.
It sounds like you should configure your specific media type "application/x-www-form-urlencoded" under API gateway settings (Binary Media Types), which will tell the API gateway to accept that body type.
Navigate to Api Gateway Console:
Click on your API
On the left select settings (under API menu)
Scroll down and click Add Binary Media Type
Type application/x-www-form-urlencoded Click save
Hoping this will help.

Azure Logic App - Get Response Body with 500 Internal Server Error

Is there any way to get the response body in Azure Logic App even when we get 500 Internal Server Error?
I have made the Logic App in a way that I'm setting the response code to 500 on an issue, and I'm adding some error related information in the response body. I tried returning 504 Gateway timeout as well, in case of a timeout issue I could face, but I'm always receiving a null response body in case of non-200 response codes.
If we are not able to see the response body in case of an error by design, is there a better way to set and fetch error related information from the response object?
Yes you can get the response body in Azure Logic App by adding the response action. According to this Add a Response action section of the Microsoft document.
When you use the Request trigger to handle inbound requests, you can model the response and send the payload results back to the caller by using the built-in Response action.
Following steps would help you to get the response body.
In the Logic App Designer, under the step where you want to add a Response action, select New step.
The under Choose an action, in the search box, enter response as your filter, and select the Response action.
Now add any values that are required for the response message. For the Body, you can select the trigger body output from the dynamic content list.
I would suggest to read the Receive and respond to inbound HTTPS requests in Azure Logic Apps document for more information.
Alternatively you can also create alerts whenever HTTP 500 errors occur in your App and use Application Insights to view it using Azure Monitor. I would also suggest to read this Handle errors and exceptions in Azure Logic Apps Microsoft document for more information.

Why is my TC not working when it should in Jmeter?

I am new to JMetet and I am having a lot of difficulties in understanding how it works.
I created a TC to add an object to my system using Blaze meter. Then, I imported the TC in Jmeter.
This TC fails when it should not (at least thats what I think) because whenever I use the system it works correctly:
This is the thread group if you need it to help me:
Am I doing something wrong? AM I missing something?
IMPORTANT: Should I be able to see my object added to the system if the TC passes?
As per HTTP Status Code 403 Forbidden description:
The HTTP 403 Forbidden client error status response code indicates that the server understood the request but refuses to authorize it.
This status is similar to 401, but in this case, re-authenticating will make no difference. The access is permanently forbidden and tied to the application logic, such as insufficient rights to a resource.
If your script assumes authentication most probably it fails somewhere somehow due to missing or improperly working correlation, for example this eedd968fe... bit
looks utterly suspicious, most probably you need to replace it with a some form of dynamic parameter extracted from the previous request using a suitable JMeter Post-Processor
Normally the flow looks like:
Open login page
Identify and extract all dynamic parameters and save them into JMeter Variables
Send the parameters along with credentials in the 2nd request
Check out Using Regular Expressions to Extract Tokens and Session IDs to Variables article for example challenge and solution

Unable to discover devices in smartThings

I am developing an IOT device using smartThings.I am using aws lambda function for getting request and sending responses to the smartThings. I am getting request whenever smartThings app hitting lambda function and sending exact response to that request but still the discover devices are not showing in the smartThings app. Please help me
Refrence link:
https://smartthings.developer.samsung.com/docs/guides/smartthings-schema/smartthings-schema-reference.html#Interaction-types
the first image is the request that i am getting
2nd and 3rd images are the responses that i am getting according to the request
By choosing the correct deviceHandlerType in response the devices started discovering. i.e., "deviceHandlerType": "c2c-rgbw-color-bulb" (reference link for implementing schema for smartThings https://smartthings.developer.samsung.com/develop/guides/smartthings-schema/implement-schema.html)
we can choose deviceHandlerType based on our requirement.

Getting error "Tokens cannot be shared. Please create a new token" in jmeter

I am passing a token that I have received while using the logging API in Http Header Manager as "Authorization : Bearer 'the token that I received'" in Jmeter and then testing another API which needs that token. It's going fine when I am running the request for one thread(user). But as soon as I'm increasing the no. of threads to 2 or 3, I am not able to get a response as it says, "Tokens cannot be shared. Please create a new token". Is there any way where I can login for two users and get different tokens and then pass the respective tokens for those two users separately to perform different tasks. And can this process be automated as I am trying to test for multiple users? Thanks in advance.
My Test Plan Looks like this:
Test Plan
My Http Header Manager Looks Like this:
enter image description here
My Regular Expression Extractor Looks Like this:
enter image description here
If I receive my token response like this
{
"token":"eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJwc2VuMSIsImV4cCI6MTUyNjYzMDA4MywiaXAiOiIxMjcuMC4wLjEifQ.k85RfQgOF2EiCzjVcmcRLgroHMCGb8P1a_Voi4mwzDEMQ3i2xUvNR6sHrHMO05k-b1MKsMBaxxuA-xiZe78_Xw"
}
What should my regular expression be like?
Am I following the procedures properly?
I tried to mimic your request and it seems like your regular expression extractor is not under the Login request and hence it is causing issue.
Try to put it under login instead at the same level as shown below:-
I hope it solves your problem, but if not, do share the error logs as I can see there are some errors reported in the top right hand "yellow" warning sign.

Resources