Extracted boolean variable became a string

Hi all,

I am trying to extract a boolean variable using the ExtractVariable policy and store this variable as an attribute when generating an access token. However, the response generated shows the variable as a string in postman (in double quotations). How can I pass the variable on as a boolean datatype?

ExtractVariable policy

<Variable name="isDangerous" type="boolean">

<JSONPath>$.body.isDangerous</JSONPath>

</Variable>

OAuth2.0 policy

<Operation>GenerateAccessToken</Operation>

<Attributes>

<Attribute name="isDangerous" display="true" ref=".body.isDangerous"/>

</Attributes>

Postman

"isDangerous": "false"

0 3 345
3 REPLIES 3

I see an issue with your OAuth config, you need to use the extracted variable as a reference,

<Operation>GenerateAccessToken</Operation>
<Attributes>
<Attribute name="isDangerous" display="true" ref="isDangerous"/>
</Attributes>

If there is a VariablePrefix in your ExtractVariablePolicy then even that should be mentioned above like, ref="myprefix.isDangerous"

Apart from that, there is no issue with extract variable policy,

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
    <DisplayName>Extract Variables-1</DisplayName>
    <Properties/>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="isDangerous" type="boolean">
            <JSONPath>$.isDangerous</JSONPath>
        </Variable>
        <Variable name="isNOTDangerous" type="string">
            <JSONPath>$.isNOTDangerous</JSONPath>
        </Variable>
    </JSONPayload>
    <Source clearPayload="false">request</Source>
</ExtractVariables>

When you mention, type="boolean" it will only give BOOLEAN as a response even if the request variable is a STRING and vice-versa.

Postman screenshot -

9629-boolean.png

While yes, the ref used in the provided oauth policy config wasn't referring to the new variable from the extract variable policy..

I believe the oauth policies will always convert any custom attribute to a string based value anyway and this that can only be changed with additional policies after the oauth policy.

Thanks both! The response I am extracting "isDangerous" from has the prefix, "body", thus I've added it in. I might try to add additional policies to convert the datatype. Can you kindly advise on some policies which can do the conversion?