Dear Team,
I hope you are doing well,
I have a little challenge see the below scenario.
I would like to set operators in KVM and the value is above JSON.
Then inside the developer app I would like to set the custom attribute name it operator and value is operator1 for example.
Then once this consumer use his developer app credentials I will take the custom attribute and pass it to json after I extract from KVM to extract specific operator password and then pass it to the backend.
The problem is it is dealing with in in flow variables as a string not json how can I solve this with out any custom code only use KVM, AssignMessage and ExtractVariables.
and I do not want to set in the request payload because my request is post and if I set the value in the request payload it will override my request JSON body.
once I extract value from flow and handle as a JSON.
Best Regards,
Amer Hijazi
Solved! Go to Solution.
Since you want to use the KVM as a JSON and avoid creating multiple separate keys, here’s a creative approach you can try using AssignMessage and ExtractVariables policies.
To be honest, this approach looks a bit unusual to me—personally, I’d recommend splitting the keys for each operator or parse with a JavaScript policy for better clarity. But, if you prefer to stick with a limited set of policies, this method will work.
You can create an AssignMessage policy that converts the value retrieved from the KVM into a JSON object. This policy prepares the JSON path expression to extract the specific password you need based on the operatorKey, which I assume comes from the app object:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage continueOnError="false" enabled="true" name="AM-2">
<DisplayName>AM-2</DisplayName>
<Set>
<Payload contentType="application/json">
{private.operatorPasswords} <!-- This comes from your KVM -->
</Payload>
</Set>
<AssignVariable>
<Name>jsonPathExpr</Name>
<Template>$.{operatorKey}</Template> <!-- Prepare the JSONPath based on the operatorKey -->
</AssignVariable>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="true" transport="http" type="request">operatorPasswordsObject</AssignTo> <!-- Create a new message with JSON payload -->
</AssignMessage>
Step 2: Extract the Password with JSONPath
Next, you can use the ExtractVariables policy to extract the password from the newly created JSON object using the JSONPath expression:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables continueOnError="false" enabled="true" name="EV-1">
<DisplayName>EV-1</DisplayName>
<Properties/>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<JSONPayload>
<Variable name="operatorPassword">
<JSONPath>{jsonPathExpr}</JSONPath> <!-- Use the JSONPath expression to extract the password -->
</Variable>
</JSONPayload>
<Source>operatorPasswordsObject</Source> <!-- Extract from the new JSON object created in the previous step -->
<VariablePrefix>private</VariablePrefix>
</ExtractVariables>
This policy retrieves the specific operatorPassword based on the operatorKey and stores it in the variable private.operatorPassword.
Again, while splitting the keys would simplify things, if you’re set on keeping a single JSON, this method should meet your needs.
This approach can generate a lot of flow variables, especially ones that contain your passwords, like operatorPasswordsObject.content. It’s critical to mask these flow variables to prevent passwords from being exposed in Apigee Trace. Make sure you properly mask any variables containing sensitive information to avoid data leaks.
Let me know if this works for your use case!
Dear @nmarkevich ,
Thank you for your efforts
Your answer to assign the value to the payload will override my current payload.
<Set>
<Payload contentType="application/json">
{private.operatorPasswords} <!-- This comes from your KVM -->
</Payload>
</Set>
I found another solution only using KVM with ExtractVariables policies as below.
Then I will use ExtractVariables as below :
I was got an error because, in the extract variable policy, I was using the wrong source.
I will set the company name inside the custom attribute to pass it automatically once the consumer uses his credentials.
Best Regards,
Amer Hijazi