Update a Query

It may be necessary to update or modify an existing query. In order to do so you will need to know the unique QueryID for the query to be updated.

The updated query can be used when you need to run a report or reused across multiple projects.


Updating a query:

 

Code Block Example
//Include the analytics class and the configuration class
$t->runInteraction("Analytics.class.php");
$t->runInteraction("Config.class.php");
 
//Create our query object
$query = new Query(Config::$ANALYTICS_ANALYST);

//find the queryID for the query that you need to update
$queryId = "56de2fr0219b38e071aac27e"; 

//re-set variables as required
  $name = "List all Events for given #event#";
  $type = "find"; 
  $params = array(
    "name" => "#event#"
  );
	
//save the query, 
//remembering to pass in the QueryID to update a previously saved query
$response = $query->save($name, $type, $params, $queryId);


Explanation:

//save the query, remembering to pass in the queryId for the query to update 
$response = $query->save($name, $type, $params, $queryId);

Save the query as you normally would but remember to also pass the QueryID for the query you wish to update. 
Please see Create a Query for more information on saving a query. 
 

$name (string)

This is the name of your query. This can be any string.
Please see Create a Query for more information.  

$type (string: find|aggregate)

This is the type of query you are doing. It's value can be either "find" or "aggregate". 
Please see Create a Query for more information. 

$params (array)

This array will contain your query.
Please see Create a Query for more information.

$queryId (string)

This is the Query ID of the query you wish to update.
Please see List (Read) Saved Queries for more information. 

Return:

The return would be an array containing the updated query. If you have been following the examples in this documentation your response would look similar to this:

Return
Array
(
    [_id] => 56de2fr0219b38e071aac27e
    [type] => find
    [params] => null
    [date] => 2016-03-15T04:03:52.998Z
    [name] => List all Events for given #event#
)

 

 

Next Steps: