Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Obtain an API key from one query to use in another

Some of the REST API calls I make require that I use an API key (that has a short time to live).   I can call the query to get a new API key easily enough, but is there any way to save that key so that the other queries can use it?  I thought maybe putting it into a parameter that the other queries would then use but I cannot see a way to do that (even tried the new dynamic parameter preview but was unable to get that to work)

2 Replies

  • You can only use variables inside a query/partition. Beware of the formula firewall monster.

  • v-jingzhang's avatar
    v-jingzhang
    Icon for Community Support rankCommunity Support

    Hi Anonymous 

     

    The dynamic parameter preview feature is only supported for some DirectQuery data sources. It cannot be applied in your scenario. 

     

    As you can call the query to get a new API key, you can try using a query to get the key first and transforming the query to only return the key result (usually it is a text string). Then transform this query into a custom function. The result of the custom function is the key. In other queries, use this function to replace key string. As a result, when other queries need a key, they will call the custom function to query the key and get the result.

     

    Here is an example which queries an access_token in a query and uses it in other queries then. The logic is similar. Have a try!

    https://community.powerbi.com/t5/Power-Query/Channel-Advisor-API-Connection-with-auth-key-creation/td-p/2208091 

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.