0

Within Postman, using the form-data option, I am able to successfully request an access token from the Petfinder API (see screenshot 1) but I am unable to reproduce this in an Azure Logic App

Screenshot 1

Access Token through Petfinder API in Azure Logic App

I have tried using the following HTTP action in Azure Logic Apps, with and without the Headers populated. (see screenshots 2 and 3)

Screenshot 2 Azure Logic App Petfinder API Access Token Screenshot 3 Pet Finder Access Token Bad Request

This is the error message I get back in the output

    "body": {
        "type": "https://httpstatus.es/400",
        "status": 400,
        "title": "unsupported_grant_type",
        "detail": "The authorization grant type is not supported by the authorization server.",
        "errors": [
            {
                "code": "unsupported_grant_type",
                "title": "Unauthorized",
                "message": "The authorization grant type is not supported by the authorization server. - Check that all required parameters have been provided",
                "details": "The authorization grant type is not supported by the authorization server. - Check that all required parameters have been provided",
                "href": "http://developer.petfinder.com/v2/errors.html#unsupported_grant_type"
            }
        ],
        "hint": "Check that all required parameters have been provided"
    }
}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
jch
  • 187
  • 3
  • 17

1 Answers1

1

I tried to reproduce the issue at my environment using URL Post https://login.microsoft.com/tenant_id/oauth2/token as I can't create account in https://www.petfinder.com/developers/v2/docs/ due to country limitation but the process of getting the token is similar in both the cases.

My workflow looks like below-

enter image description here

In When a HTTP request request is received trigger, I am taking the below schema.

{
"properties": {
"client_id": {
"type": "string"
},
"client_secret": {
"type": "string"
},
"tenant_id": {
"type": "string"
}
},
"type": "object"
}

Then I have added HTTP to get the bearer token. Please note, here Content-Type = multipart/form-data; boundary=--boundary and request body is in this format

----boundary
Content-Disposition: form-data; name="grant_type"

client_credentials
----boundary
Content-Disposition: form-data; name="client_id"

your client_id
----boundary
Content-Disposition: form-data; name="client_secret"

your client_secret
----boundary--

enter image description here enter image description here

Then added Data Operation - Parse JSON action, using the following schema

{
"properties": {
"access_token": {
"type": "string"
},
"expires_in": {
"type": "string"
},
"expires_on": {
"type": "string"
},
"ext_expires_in": {
"type": "string"
},
"not_before": {
"type": "string"
},
"resource": {
"type": "string"
},
"token_type": {
"type": "string"
}
},
"type": "object"
}

Trigger Output-

enter image description here

enter image description here

enter image description here

enter image description here

For Content-type: application/x-www-form-urlencoded

enter image description here

Test Result

enter image description here

enter image description here

Ikhtesam Afrin
  • 897
  • 1
  • 1
  • 6
  • Thank you for your reply. My workflow is a little different with "Content-Type": "multipart/form-data; boundary=--boundary". Am I using the wrong boundary parameter? – jch Jun 23 '23 at 17:30
  • "HTTP_GET_TOKEN": { "inputs": { "body": "grant_type=client_credentials&client_id=@{body('Get_secret_PetFinderApiKey')?['value']}&client_secret=@{body('Get_secret_PetFinderApiSecret')?['value']}", "headers": { "Content-Type": "multipart/form-data; boundary=--boundary" }, "method": "POST", "uri": "https://api.petfinder.com/v2/oauth2/token" } – jch Jun 23 '23 at 17:31
  • I have modified my answer, please check – Ikhtesam Afrin Jun 23 '23 at 19:45
  • Will you post the picture of your original answer as that would be very helpful for another API I am working on. This works like a dream – jch Jun 26 '23 at 16:29
  • added the screenshot – Ikhtesam Afrin Jun 27 '23 at 07:36