How to fetch value from assign message policy output?

aayushi8218
Participant II

I have used javascript call-out policy in which I have added a code in js file. And assign message policy to assign UUID in header. Now I want to fetch UUID to use in different policy. How can I do that? I have tried using extract variable policy but not able to fetch the ID.

JS:

function generateUUID() { // Public Domain/MIT
    var d = new Date().getTime();
    if (typeof performance !== 'undefined' && typeof performance.now === 'function'){
        d += performance.now(); //use high-precision timer if available
    }
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = (d + Math.random() * 16) % 16 | 0;
        d = Math.floor(d / 16);
        return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
    });
}

var uuid = generateUUID();
context.setVariable('x-apigee-uuid', uuid); 

Assign Message Policy:

<AssignMessage async="false" continueOnError="false" enabled="true" 
name="HeaderAddition-123">
    <DisplayName>HeaderAddition-123</DisplayName>
    <Add>
        <Headers>
            <Header name="uuid">{x-apigee-uuid}</Header>
        </Headers>
    </Add>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>
Solved Solved
0 2 447
1 ACCEPTED SOLUTION

Now I want to fetch UUID to use in different policy.

The AssignMessage policy you showed, "fetches" the uuid by setting a Header to the value referred to by the variable named "x-apigee-uuid". The notation like this:

 <Header name="uuid">{x-apigee-uuid}</Header>

...in which a set of curly braces surrounds a variable name, is an example of a Message Template. It tells to obtain the value for that item, by replacing the curlies and what is inside the curlies, with the value held by the named variable.

if the variable "x-apigee-uuid" contains the value "1234-1234-1234", then with the AssignMessage policy you showed, the header named "uuid" will get the value "1234-1234-1234".

"Fetching" the value in another policy involves referring to the variable again.

You'll need to be specific about which policy and which configuration element you want to use, before I can give you an example. Or just read the fine manual on the policy of interest, and it will tell you how to refer to variables.

View solution in original post

2 REPLIES 2

Now I want to fetch UUID to use in different policy.

The AssignMessage policy you showed, "fetches" the uuid by setting a Header to the value referred to by the variable named "x-apigee-uuid". The notation like this:

 <Header name="uuid">{x-apigee-uuid}</Header>

...in which a set of curly braces surrounds a variable name, is an example of a Message Template. It tells to obtain the value for that item, by replacing the curlies and what is inside the curlies, with the value held by the named variable.

if the variable "x-apigee-uuid" contains the value "1234-1234-1234", then with the AssignMessage policy you showed, the header named "uuid" will get the value "1234-1234-1234".

"Fetching" the value in another policy involves referring to the variable again.

You'll need to be specific about which policy and which configuration element you want to use, before I can give you an example. Or just read the fine manual on the policy of interest, and it will tell you how to refer to variables.

I want to fetch the variable and check the condition whether the created GUID is 36 character long and its format is standard or not.

In short, I want to make a shared flow in with I can also validate the generated guid.

I want to use this fetched value to use in Raise Fault policy.