I'm trying to hide an API key within a YQL query. To do so, I've tried following this post (also explained by the same author here). When I try and run a query using the URI template, I get the following warning returned:
"warning": "Missing template variables (BungieAPIKey)"
Here are the steps I have taken:
yql.storage.admin
by running insert into yql.storage.admin (value) values ("set BungieAPIKey='YOUR_KEY' on uritemplate;")
https://developer.yahoo.com/yql/console/?env=store://XXXXXXXXXX
)select * from json where url in (select url from uritemplate where template='http://bungie.net/videos/{BungieAPIKey}/{user}/{page}' and user='foo' and page='bar')
Here is the JSON that is returned:
{
"query": {
"count": 0,
"created": "2015-01-13T16:58:57Z",
"lang": "en-US",
"diagnostics": {
"publiclyCallable": "true",
"warning": "Missing template variables (BungieAPIKey)",
"redirect": {
"from": "http://bungie.net/videos//foo/bar",
"status": "301",
"content": "http://www.bungie.net/videos/foo/bar"
},
"url": {
"execution-start-time": "0",
"execution-stop-time": "573",
"execution-time": "573",
"http-status-code": "404",
"http-status-message": "Not Found",
"content": "http://bungie.net/videos//foo/bar"
},
"error": "Invalid JSON document http://bungie.net/videos//foo/bar",
"user-time": "574",
"service-time": "573",
"build-version": "0.2.212"
},
"results": null
}
}
In an attempt to narrow down the issue, I tried the following query in a clean YQL console (no env set):
set BungieAPIKey='YOUR_KEY' on uritemplate;
select url from uritemplate where template='http://bungie.net/videos/{BungieAPIKey}/'
Running this gives me the same warning. Why aren't my template variables pulling from what I have set as environment variables?
It looks like set x='y' on uritemplate is not being honored for some reason. In the absence of this, you have the option of having a custom table which accepts a typed parameter say apiKey. You could then have the following:
use 'http://location-of-custom-table' as tablename;
set apiKey='foo' on tablename;
select * from tablename;
In the above case, the apiKey would be passed in to the custom table and you can append it in javascript and create your url.