Run query with parameters with Javascript

#1

So, I am trying to fetch a query with specified parameters using Javascript.
My query is a fairly simple one:

SELECT count(*)
FROM accounts
WHERE company_type = {{compType}}

and the Javascript code is the following:

require('es6-promise').polyfill();
require('isomorphic-fetch');

 //fetching the JSON url as displayed in `Show Api Key ->Results in JSON format:`

fetch('https://dataclips.<accountName>.net/api/queries/<queryID>/results.json?api_key=<APIKey>&p_compType = 1')
  .then(function(response) {
    return response.json();
  })
  .then(myJson => {
  	 	let result = myJson
    	console.log(result);
  });

Ignoring the &p_compType = 1 in the end of url and replacing the parameter from query with company_type = 1, is working fine and returns the correct result.

Although, using the above code with the parameter, result in a JSON Message:

{ message:

‘No cached result found for this query. You have requested this URI [/api/queries/1333/results.json] but did you mean /api/query_results or /api/queries/<query_id>/refresh or /api/query_results/<query_result_id> ?’ }

Using the urls mentioned in the above message doesn’t do the trick. Apologies if this is a duplicate, however I tried solving it by addressing to similar issues and I didn’t figure it out.
Any help will be highly appreciated.

0 Likes

#2

EDIT: SOLVED WITH PYTHON

I made it work using the refresh API but this is in Python, so I guess this is still considered unsolved because of Javascript?

0 Likes