How to retrieve variables in Azure API to construct expression for obtaining OAuth token in body

Quynh Hoang 0 Reputation points
2024-11-04T20:28:39.14+00:00

Hi,

Below is the set-body code block that I have some problems with.Im having problem constructing an expression for obtaining an OAuth token. I use 3 variables {{clientId}}, {{scope}} and {{clientSecrets}} instead of hardcoding those values.

No matter what I tried I always get some syntax errors.

Please help. It's much appreciated.

<set-body>@{
	return "client_id={{clientId}}&scope={{scope}}&client_secret={{clientSecret}}&grant_type=client_credentials";
}
</set-body>

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,184 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JananiRamesh-MSFT 28,086 Reputation points
    2024-11-08T18:09:22.95+00:00

    @Quynh Hoang Thanks for reaching out. From the description i could see you're using named values in the set-body code block, instead of hardcoding the values for client_id, scope, and client_secret.

    I tried at my end using the same syntax and able to fetch the values successfully as shown below,

    User's image User's image could you please share me the error message and the entire policy to investigate further?


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.