Body item Name |
Default value |
Is required? |
Visibility |
Type |
Format |
body |
N/A (this is the root) |
Yes |
none |
N/A |
N/A |
key-body-output |
|
Yes |
none |
string |
|
Here are the Policies in this connector, in order (originally, it was just the first one, but the other two were added to try to fix my issue):
Name |
Template |
Operations |
Header name |
Header value |
Action if header exists |
Run policy on |
Set HTTP headers |
Set HTTP header |
all Actions except Token |
Authorization |
@headers('Access-Token') |
override |
Request |
Add X-Content-Type-Options nosniff |
Set HTTP header |
Token |
X-Content-Type-Options |
nosniff |
override |
Request |
Set Content-Type to application/x-www-form-urlencoded |
Set HTTP header |
Token |
Content-Type |
application/x-www-form-urlencoded |
override |
Request |
It works when I test it on the custom connector page, and it works in Power Automate. But using it in Power Apps always causes this error:
{
"error": "unsupported_grant_type",
"debugInfo": "clientRequestId: ab506935-dfff-4069-b1fa-4f6774a1a3a0"
}
When using the Monitor, it seems like the Power Platform is possibly overwriting the Content-Type header with its own when I try using it in Power Apps, based on the data.request portion of the Monitor entry:
"request": {
"url": "https://unitedstates-002.azure-apim.net/apim/CONNECTORURL/MORECONNECTORURL/Token",
"method": "POST",
"headers": {
"Accept": "application/json, application/xml",
"x-ms-user-agent": "PowerApps/3.24121.10 (Web AuthoringTool; AppName=GUIDHERE)",
"x-ms-client-session-id": "SESSIONID",
"x-ms-client-request-id": "REQUESTID",
"x-ms-client-environment-id": "/providers/Microsoft.PowerApps/environments/ENVIRONMENTID",
"x-ms-client-app-id": "/providers/Microsoft.PowerApps/apps/CLIENTAPPID",
"x-ms-client-tenant-id": "TENANTID",
"x-ms-client-object-id": "OBJECTID",
"Accept-Language": "en-US",
"Cache-Control": "no-cache, no-store",
"Content-Type": "application/json",
"x-ms-request-method": "POST",
"x-ms-request-url": "/apim/CONNECTORTHINGS/MORECONNECTORTHINGS/Token"
},
"body": "userName=NAMEHERE&password=PASSHERE&grant_type=password"
}
Instead of having the expected Content-Type value of "application/x-www-form-urlencoded", Power Apps is sending "application/json" (or, at least, it seems to be). Based on other threads here, this seems to be a common problem.
I have tried the following fixes, though they haven't worked:
- Changing the header visibility values from "none" (their original value) to "internal" (their current value). It didn't fix the problem, but it kept Power Apps from suggesting these values to me when writing code, which was convenient. (While the value was "none", i also tried explicitly stating the header values in Power Apps, but it didn't fix it either).
- Adding the "Set Content-Type to application/x-www-form-urlencoded" Policy to my connector, as seen above (commonly suggested, but did not fix the issue)
- Adding the "Add X-Content-Type-Options nosniff" Policy to my connector, as seen above (a rarer suggestion, but it didn't work either, regardless of whether it placed it before or after "Set Content-Type to application/x-www-form-urlencoded" in the Policies list order.
I've had issues like this before, where something seems to work everywhere except for Power Apps. Is there a solution for this one, or will I have to resort to Flows to get tokens?