10-03-2016 07:55 AM
Hi,
Is anyone else using the CLI Template Configuration API end point to get template IDs based on tag?
The behaviour seems to be inconsistent for me. I've got a bunch of templates with the tag ZEN and as shown below, doing a query with tags=ZEN I get back a list of template IDs:
curl -u carls-username https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate?tags=ZEN
Enter host password for user 'carls-username':
<?xml version="1.0" ?>
<queryResponse last="14" first="0" count="15" type="CliTemplate" responseType="listEntityIds" requestUrl="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate?tags=ZEN" rootUrl="https://myprimeserver.example.com/webacs/api/v2/data">
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/664668">664668</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/664669">664669</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/664675">664675</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/664679">664679</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/664680">664680</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/664681">664681</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/664682">664682</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/664686">664686</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/4555552">4555552</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/4555553">4555553</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/4555554">4555554</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/11047036">11047036</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/13190177">13190177</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/15789774">15789774</entityId>
<entityId type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/16716703">16716703</entityId>
</queryResponse>
If I select the last template ID above for a closer look you can see that I've also added an additional tag of CARLSTAG so it has both ZEN and CARLSTAG:
$ curl -u carls-username https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/16716703
Enter host password for user 'carls-username':
<?xml version="1.0" ?>
<queryResponse type="CliTemplate" responseType="getEntity" requestUrl="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/16716703" rootUrl="https://myprimeserver.example.com/webacs/api/v2/data">
<entity dtoType="cliTemplateDTO" type="CliTemplate" url="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate/16716703">
<cliTemplateDTO displayName="16716703" id="16716703">
<author>the.author</author>
<content>### Content removed as it's not relevant</content>
<createdOn>2016-09-28T10:20:37.230+01:00</createdOn>
<deployCount>0</deployCount>
<description>Example Template Commands</description>
<deviceType>Routers</deviceType>
<name>ZEN-TEMPLATE-HELP</name>
<path>My Templates/Provisioning Templates</path>
<tags>CARLSTAG,ZEN</tags>
<templateId>16716703</templateId>
<variables>
<variable>
<defaultValue>10000</defaultValue>
<description>Downstream BW in bps</description>
<displayLabel>bpsDown</displayLabel>
<name>bpsDown</name>
<required>false</required>
<type>String</type>
</variable>
</variables>
</cliTemplateDTO>
</entity>
</queryResponse>
If I query for CARLSTAG specifically I get a response count of 0.
$ curl -u carls-username https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate?tags=CARLSTAG
Enter host password for user 'carls-username':
<?xml version="1.0" ?>
<queryResponse count="0" type="CliTemplate" responseType="listEntityIds" requestUrl="https://myprimeserver.example.com/webacs/api/v2/data/CliTemplate?tags=CARLSTAG" rootUrl="https://myprimeserver.example.com/webacs/api/v2/data"></queryResponse>
Can anyone explain this behaviour, am I missing something?
Carl
Solved! Go to Solution.
10-03-2016 09:27 AM
The tags response parameter is of the type String. So when you filter with tags=CARLSTAG this is called literal filtering. So the API will look for templates where the tag field is, and only is, "CARLSTAG". In other words, this filters to those templates that exclusively have that tag.
Since you're trying to find templates that have the tag, but could have other tags, use the contains() expression. For example, tags=contains("CARLSTAG") will filter to all templates that have CARLSTAG, even if they have other tags.
10-03-2016 09:27 AM
The tags response parameter is of the type String. So when you filter with tags=CARLSTAG this is called literal filtering. So the API will look for templates where the tag field is, and only is, "CARLSTAG". In other words, this filters to those templates that exclusively have that tag.
Since you're trying to find templates that have the tag, but could have other tags, use the contains() expression. For example, tags=contains("CARLSTAG") will filter to all templates that have CARLSTAG, even if they have other tags.
10-05-2016 02:17 AM
Hi Spencer,
Thanks, makes sense. It's a shame matching a full tag name isn't possible, to avoid having to worry about a short tag being a sub-string of a longer tag name.
Cheers,
Carl
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide