Why does logic apps retrieve Content-Type must be application/x-www-form-urlencoded if it is passed?

huangapple go评论68阅读模式
英文:

Why does logic apps retrieve Content-Type must be application/x-www-form-urlencoded if it is passed?

问题

我正在开发一个逻辑应用,它应该每天调用特定的API一次,以检索响应(令牌),然后在接下来的步骤中(尚未编写)将联系另一个API,最后将结果存储在Google电子表格中。问题出在第一次调用,根据MailUp文档的阅读,我必须发送一个调用到一个URL来检索令牌,使用用户名和密码进行身份验证(https://help.mailup.com/display/mailupapi/Authenticating+with+OAuth+v2),但它不起作用!有人可以帮助我吗?

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "HTTP": {
                "inputs": {
                    "headers": {
                        "Authorization": "BASE64_ENCODED_CLIENTCREDENTIALS",
                        "Content-Type": "application/x-www-form-urlencoded"
                    },
                    "method": "POST",
                    "queries": {
                        "grant_type": "password",
                        "password": "password",
                        "username": "username"
                    },
                    "uri": "https://services.mailup.com/Authorization/OAuth/Token"
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "Http"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "responseBody",
                            "type": "String",
                            "value": ""
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            },
            "type": "ApiConnection"
        },
        "Set_variable": {
            "inputs": {
                "name": "responseBody",
                "value": "@{body('HTTP')}"
            },
            "runAfter": {
                "HTTP": [
                    "Succeeded"
                ]
            },
            "type": "SetVariable"
        }
    },
    "contentVersion": "1.0.0.0",
    "outputs": {},
    "parameters": {
        "$connections": {
            "defaultValue": {},
            "type": "Object"
        }
    },
    "triggers": {
        "Recurrence": {
            "evaluatedRecurrence": {
                "frequency": "Day",
                "interval": 1
            },
            "recurrence": {
                "frequency": "Day",
                "interval": 1
            },
            "type": "Recurrence"
        }
    }
},
"parameters": {
    "$connections": {
        "value": {
        }
    }
}
}
英文:

I'm developing a Logic app that should call a specific API one time for a day to retrieve the response (a token) and on the next steps (not already written) it will contact another API and finally it will store the result on a Google spreadsheet.
The problem is on the first call, reading the documentation of MailUp I must send a call to an URL to retrieve the token using username e password authentication ( https://help.mailup.com/display/mailupapi/Authenticating+with+OAuth+v2 ) but it doesn't work!
Can someone help me?

{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"HTTP": {
"inputs": {
"headers": {
"Authorization": "BASE64_ENCODED_CLIENTCREDENTIALS",
"Content-Type": "application/x-www-form-urlencoded"
},
"method": "POST",
"queries": {
"grant_type": "password",
"password": "password",
"username": "username"
},
"uri": "https://services.mailup.com/Authorization/OAuth/Token"
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "Http"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "responseBody",
"type": "String",
"value": ""
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"type": "ApiConnection"
},
"Set_variable": {
"inputs": {
"name": "responseBody",
"value": "@{body('HTTP')}"
},
"runAfter": {
"HTTP": [
"Succeeded"
]
},
"type": "SetVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"Recurrence": {
"evaluatedRecurrence": {
"frequency": "Day",
"interval": 1
},
"recurrence": {
"frequency": "Day",
"interval": 1
},
"type": "Recurrence"
}
}
},
"parameters": {
"$connections": {
"value": {
}
}
}
}

答案1

得分: 1

由于访问问题,我将无法在这里使用https://help.mailup.com/display/mailupapi/Authenticating+with+OAuth+v2,但我将使用https://login.microsoft.com/{tenant_id}/oauth2/token 来生成持票人令牌,就像您尝试在逻辑应用中生成它们一样。

尝试按以下格式构造请求体,例如在您的情况下,使用**'&'代替'逗号'**。同时,也要使用clientId和client_password,以及用户名和密码。
这里我使用以下输入来生成令牌:

URL https://login.microsoft.com/{tenant_id}/oauth2/token

Headers Content-Type: application/x-www-form-urlencoded

Body grant_type=password&resource=https://graph.microsoft.com&client_id=<your client ID>&client_secret=<your client secret>&username=<username>&password=<password>

如果您参考上述步骤,您将能够生成访问令牌和刷新令牌。

英文:

Due to access issues, I will not be able to use https://help.mailup.com/display/mailupapi/Authenticating+with+OAuth+v2 here but I will use https://login.microsoft.com/{tenant_id}/oauth2/token to generate bearer token in the same way you are trying to generate them in logic app.

Why does logic apps retrieve Content-Type must be application/x-www-form-urlencoded if it is passed?

Try to structure the body in the following format like use '&' instead of 'comma' in your case. Use clientId and client_password too along with the username and password.
Here I am taking below inputs to generate token:

URL https://login.microsoft.com/{tenant_id}/oauth2/token

Headers Content-Type: application/x-www-form-urlencoded

Body grant_type=password&resource=https://graph.microsoft.com&client_id=<your client ID>&client_secret=<your client secret>&username=<username>&password=<password>

Why does logic apps retrieve Content-Type must be application/x-www-form-urlencoded if it is passed?

Output

Why does logic apps retrieve Content-Type must be application/x-www-form-urlencoded if it is passed?

Why does logic apps retrieve Content-Type must be application/x-www-form-urlencoded if it is passed?

If you refer the above steps, you will be able to generate access token and refresh token too.

huangapple
  • 本文由 发表于 2023年7月17日 17:06:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76702944.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定