How to pull in a Custom Attribute to your output?

Not applicable

Hi everyone,

I would like to pull in my Developer App {{Custom Attributes}} and append them to a couple of URLs for tracking.

This way I can pull in the right {{Custom Attributes}} for each developer based on their key.

Is there a Policy that Apigee has setup already to do this or would a script need to be written?

Any help or thoughts would be greatly appreciated!

Example Output:

  • <link> http://www.test.com/what?intmp=pub:{{Custom Attributes}}</link>
  • <iosLink>app://video/watch?excmp=pub:iosMobile_{{Custom Attributes}}</iosLink>
  • <androidLink>app://video/watch?excmp=pub:andrMobile_{{Custom Attributes}}</androidLink>
  • <universalLink>http://deeplink.me/watch/493151299882?excmp=pub:{{Custom Attributes}}</universalLink>
0 13 501
13 REPLIES 13

Not applicable

The VerifyAPIKey policy will populate any custom attributes associated with the developer and/or the APIKey as flow variables.

Subsequent to the verify you can then use those values in AssignMessage policies, javascript, etc.

hi @jtolerico as @David Allen pointed out , this is a a two step process.

Lets say you have defined a custom attribute for a developer called attribute_1 then after the execution of the verifyAPIKey policy automatically the following variable will be populated ::

verifyapikey.Verify-API-Key.attribute_1

After that you can add a javascript policy where you can simply have the code snippet as :

context.setVariable("link", "http://www.test.com/what?intmp=pub:"+context.getVariable("verifyapikey.Verify-API-Key.attribute_1"));

so now you have a variable called link which contains the desired url which you can use for any further processing.

Optionally you can do the above step using Assign Message policy as well.

Thanks for the javascript. I know I am doing something wrong here. Also, these variables are repeated in each item within the xml and there are hundreds of items. 😕

var weblk = context.getVariable('link');
var ioslk = context.getVariable('iosLink');
var andlk = context.getVariable('androidLink');
var unilk = context.getVariable('universalLink');


context.setVariable("link", weblk + context.getVariable("verifyapikey.Verify-API-Key.attribute_1"));
context.setVariable("iosLink", ioslk + context.getVariable("verifyapikey.Verify-API-Key.attribute_1"));
context.setVariable("androidLink", andlk + context.getVariable("verifyapikey.Verify-API-Key.attribute_1"));
context.setVariable("universalLink", unilk + context.getVariable("verifyapikey.Verify-API-Key.attribute_1"));


Hi @jtolerico I am not sure about the question here. Are you seeing any errors ? Can you please clarify your ask ?

Keep in mind that in this : verifyapikey.Verify-API-Key.attribute_1 the Verify-API-Key is actually the name of the verifyAPI key policy. So you might have a different name than mine.

i'm not even getting the vars to pull in the original URLs with the [ context.getVariable('link'); ] let alone getting the custom attribute to append with [ + context.getVariable("verifyapikey.Verify-API-Key.attribute_1") ]

so I cleaned it up a bit... but nothing... am I missing something here in the Javascript?

Developer Custom Attributes:

Name: Publisher, Value: Foo

Source XML:

<item>

<link> http://www.test.com/what?intmp=pub:</link>;

<iosLink>app://video/watch?excmp=pub:iosMobile_</iosLink>

<androidLink>app://video/watch?excmp=pub:andrMobile_</androidLink>

<universalLink>http://deeplink.me/watch/493151299882?excmp=pub:</universalLink>

</item>

Javascript:

var pkey = context.getVariable("verifyapikey.Verify-API-Key.Publisher");
var weblk = context.getVariable("link") + pkey;
var ioslk = context.getVariable("iosLink") + pkey;
var andlk = context.getVariable("androidLink") + pkey;
var unilk = context.getVariable("universalLink") + pkey;
context.setVariable("link", weblk);
context.setVariable("iosLink", ioslk);
context.setVariable("androidLink", andlk);
context.setVariable("universalLink", unilk);

The Result I'm Looking for:

<item>

<link>http://www.test.com/what?intmp=pub:Foo</link>

<iosLink>app://video/watch?excmp=pub:iosMobile_Foo</iosLink>

<androidLink>app://video/watch?excmp=pub:andrMobile_Foo</androidLink>

<universalLink>http://deeplink.me/watch/493151299882?excmp=pub:Foo</universalLink>

</item>

What am I doing wrong? 😕

Can you attach your proxy bundle here please ? I want to take a look.

Not applicable

In your trace session are you seeing the variables populated out of the verifyAPIKey policy? I would suspect not as those names would not be used. Look at the output of that policy. The values you want will be visible there IF they are properly configured.

Endpoint Default:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>verify-api-key</Name>
            </Step>
            <Step>
                <Name>remove-query-param-apikey</Name>
            </Step>
            <Step>
                <Name>Assign-Message-1</Name>
            </Step>
            <Step>
                <Name>Response-Cache-1</Name>
            </Step>
        </Request>
        <Response>
            <Step>
                <Name>Append-Publisher-Tracking-Code</Name>
            </Step>
            <Step>
                <Name>JavaScript-1</Name>
            </Step>
        </Response>
    </PreFlow>
    <Flows/>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <HTTPProxyConnection>
        <BasePath>/syndication/full-episodes</BasePath>
        <VirtualHost>default</VirtualHost>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="default">
        <TargetEndpoint>default</TargetEndpoint>
    </RouteRule>
</ProxyEndpoint>

Policy Verify API Key:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<VerifyAPIKey async="false" continueOnError="false" enabled="true" name="verify-api-key">
    <DisplayName>Verify API Key</DisplayName>
    <APIKey ref="request.queryparam.apikey"/>
</VerifyAPIKey>

As @David Allen suggested ... can you please check in your "Trace" if you can see the "verifyapikey.Verify-API-Key.Publisher" getting populated ?

If not .. can you please either add me to your org so that I can take a look or upload the whole proxy zip file here ?

Nothing in my script is working. 😕

905-screen-shot-2015-08-04-at-33113-pm.png

Not applicable

This indicates the variables as you request them were not populated in the verify policy. Look at the trace output for that policy and ensure that the full variable names match.