how to get the developer app custom attributes into an AssignMessage policy of apigee?

Not applicable

Hi,

we have a requirement in our project where we need to set custom attributes in developer app and need to send this custom attribute value as a header to the request.

we have set 2 custom attributes as source=test and quotarate=60000, we need to send source as a header for request.

For reading these custom attributes ,we have tried to use "app.source" in the AssignMessage policy but when the policy executes this value is populated as empty and thus is not setting to the header. The AssignMessage policy is as below.

<AssignMessage ...>
  <DisplayName>AssignHeaders</DisplayName>
  <Set>
    <Headers>
      <header name="source">{app.source}</header>
    </Headers>
  </Set>
   ...

The source value is set as empty in the request header, i am stuck here and not able to understand how to go ahead with this.

Also when i am using the app.quotarate in the quota policy i am able to get the value into the policy. Quota policy is as below.

<Quota type="flexi" name="quotalimit">
  <DisplayName>quota limit</DisplayName>
  <Allow countRef="app.quotarate"/>
  <Interval ref="request.header.quota_count">1</Interval>
  <Distributed>true</Distributed>
  <Synchronous>true</Synchronous>
  <TimeUnit ref="request.header.quota_timeout">day</TimeUnit>
</Quota>

It is a bit confusing how "app.<<customAttribute>>" variable is working out differently for different policies.

Can anyone please explain and help me in this . Thank you in advance .

Regards,

Sneha.

Solved Solved
0 8 2,631
1 ACCEPTED SOLUTION

@Sneha Manne

You can get the custom app attributes by accessing them as below.

verifyapikey.{your verify apikey policy name}.{name of the custom attribute}

Assign these attributes to some variables and you can access them in the flow. Once they are assigned to some variables you can see these variable values in trace by triggering a request.

Hope this helps.

View solution in original post

8 REPLIES 8

@Sneha Manne

You can get the custom app attributes by accessing them as below.

verifyapikey.{your verify apikey policy name}.{name of the custom attribute}

Assign these attributes to some variables and you can access them in the flow. Once they are assigned to some variables you can see these variable values in trace by triggering a request.

Hope this helps.

Hi Siva,

Thank you for the above explaination .

I tried to create a VerifyAPIKey policy and then tried to give the verifyapikey.{your verify apikey policy name}.{name of the custom attribute} in the AssignMessage policy to assign the attribute to variables but the verifyAPIey policy is failing with "oauth.v2.InvalidApiKey" .

Please find my VerifyAPIKey and AssignMessage policy as below.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<VerifyAPIKey async="false" continueOnError="false" enabled="true" name="Verify-API-Key-1">

<DisplayName>Verify API Key-1</DisplayName>

<Properties/>

<APIKey ref="request.header.Apikey"/>

</VerifyAPIKey>

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignVariable">

<DisplayName>AssignVariable</DisplayName>

<Properties/>

<AssignVariable>

<Name>developerapp.source</Name>

<Ref>verifyapikey.Verify-API-Key-1.source</Ref><!-- Also tried verifyapikey.Verify-API-Key-1.app.source and verifyapikey.Verify-API-Key-1.developer.source --!>

</AssignVariable>

<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

<AssignTo createNew="false" transport="http" type="request"/>

</AssignMessage>

But the verifyAPIKey is failing and nothing is populated into the verifyapikey.Verify-API-Key-1.source variable.

Please let me know if i have missed anything in above .

Hi Sneha

Siva's guidance is good.

Be aware that the variable like

verifyapikey.{your verify apikey policy name}.{name of custom attr}

...gets populated only if the VerifyApiKey policy succeeds. You said

the verifyAPIey policy is failing with "oauth.v2.InvalidApiKey" .

That means the variable you are looking for will not be populated.

First you must correct the VerifyApiKey policy configuration, or the app configuration, ... so that the VerifyApiKey policy works correctly, and succeeds. After that, then you can access the variable as described by Siva.

Hi Sneha,

Siva's answer is good, but... maybe there is something more basic that is impeding you. I see in the code you pasted that your header element is lowercase.

<AssignMessage ...>
  <DisplayName>AssignHeaders</DisplayName>
  <Set>
    <Headers>
      <header name="source">{app.source}</header>
    </Headers>
  </Set>

It must be uppercase.

<AssignMessage ...>
  <DisplayName>AssignHeaders</DisplayName>
  <Set>
    <Headers>
      <Header name="source">{app.source}</Header> . <!-- LOOK -->
    </Headers>
  </Set>

Hi Dino,

Thank you for pointing out the above .

But it was just a typo error while posting the question and i had given as <Header> in the actual policy , However i did try as Siva has suggested above but im still having issues with the policies.

I tried to create a VerifyAPIKey policy and then tried to give the verifyapikey.{your verify apikey policy name}.{name of the custom attribute} in the AssignMessage policy to assign the attribute to variables but the verifyAPIey policy is failing with "oauth.v2.InvalidApiKey" .

Please find my VerifyAPIKey and AssignMessage policy as below.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<VerifyAPIKey async="false" continueOnError="false" enabled="true" name="Verify-API-Key-1">

<DisplayName>Verify API Key-1</DisplayName>

<Properties/>

<APIKey ref="request.header.Apikey"/>

</VerifyAPIKey>

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<AssignMessage async="false" continueOnError="false" enabled="true" name="AssignVariable">

<DisplayName>AssignVariable</DisplayName>

<Properties/>

<AssignVariable>

<Name>developerapp.source</Name>

<Ref>verifyapikey.Verify-API-Key-1.source</Ref><!-- Also tried verifyapikey.Verify-API-Key-1.app.source and verifyapikey.Verify-API-Key-1.developer.source --!>

</AssignVariable>

<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>

<AssignTo createNew="false" transport="http" type="request"/>

</AssignMessage>

But the verifyAPIKey is failing and nothing is populated into the verifyapikey.Verify-API-Key-1.source variable.

Please let me know if i have missed anything in above .

Thanks,

Sneha.

Hi Sneha

See my comment above from 2 days ago. If VerifyApiKey fails, no variables will be populated. This is by design. More details above.

Hi Dino,

Thank you for the above details.

The VerifyApiKey policy was failing and i was not able to find out where the issue was coming from so instead i had used the OAuthV2 policy with operation value as “VerifyAccessToken” which was populating all the custom attributes along with app.<<customvariable>> into the flow.

I had executed the OAuthV2 policy before the AssignMessage policy for using app.<<customAttributes>> values.

Ahh, I see.

VerifyApiKey will work on a value that matches the Consumer Key shown in the Apigee Edge administrative UI.

OAuthV2/VerifyAccessToken will work with a value that is issued from OauthV2/GenerateAccessToken.

You cannot use VerifyApiKey on a token, and you cannot use VerifyAccessToken on a key.