Sending Request with the FormData RequestType

 

Some services and devices require that sent queries include the content-type parameter set as application/x-www-form-urlencoded in the header.


Such situation occurs, for example, in the case with the Tedee lock integration where the following request must be sent to obtain a token:

POST https://tedee.b2clogin.com/tedee.onmicrosoft.com/B2C_1_SignIn_Ropc/oauth2/v2.0/token Content-Type: application/x-www-form-urlencoded
grant_type=password &client_id=02106b82-0524-4fd3-ac57-af774f340979 &scope=openid 02106b82-0524-4fd3-ac57-af774f340979 &response_type=token &username={username} &password={password}
POST https://tedee.b2clogin.com/tedee.onmicrosoft.com/B2C_1_SignIn_Ropc/oauth2/v2.0/token Content-Type: application/x-www-form-urlencoded grant_type=password &client_id=02106b82-0524-4fd3-ac57-af774f340979 &scope=openid 02106b82-0524-4fd3-ac57-af774f340979 &response_type=token &username={username} &password={password}POST
https://tedee.b2clogin.com/tedee.onmicrosoft.com/B2C_1_SignIn_Ropc/oauth2/v2.0/token Content-Type: application/x-www-form-urlencoded grant_type=password &client_id=02106b82-0524-4fd3-ac57-af774f340979 &scope=openid 02106b82-0524-4fd3-ac57-af774f340979 &response_type=token &username={username} &password={password}POST
https://tedee.b2clogin.com/tedee.onmicrosoft.com/B2C_1_SignIn_Ropc/oauth2/v2.0/token Content-Type: application/x-www-form-urlencoded grant_type=password &client_id=02106b82-0524-4fd3-ac57-af774f340979 &scope=openid 02106b82-0524-4fd3-ac57-af774f340979 &response_type=token &username={username} &password={password}

Note! In place of {username} and {password} enter the appropriate data.

In this situation the settings of the HttpRequest virtual object should look as follows:


The script that sets the contents of the RequestBody property looks as follows:

local get_key = {"&grant_type=password&client_id=02106b82-0524-4fd3-ac57-af774f340979&scope=openid+02106b82-0524-4fd3-ac57-af774f340979&response_type=token&username=support%40grenton.com&password=support"} 
Gate_HTTP->TedeeLock_AuthorizationKey->SetRequestBody(get_key)

Note! The & character has appeared before the grant_type parameter.


During setting the value of the RequestBody feature, keep in mind the special characters that need to be encoded:

: / ? # [ ] @ ! $ & '
%3A %2F %3F %23 %5B %5D %40 %21 %24 %26 %27
( ) * + , ; = %  spacja
%28 %29 %2A %2B %2C %3B %3D %25 +

Note! The unencoded characters & and separate the parameters and their values.