Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

It may be necessary to delete a query. The Delete query function will allow you to delete a query you have previously created.

In order to do so you will need to know the unique QueryID for the query to be deleted.

...

Code Block
languagephp
themeRDark
firstline1
titleCode Block Example
linenumberstrue
//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);

//Read all saved queries
$res = $query->get();

//find the queryID for the query that you needQueryID you wish to delete
$queryId = $res[0]["_id"]"56de2fr0219b38e071aac27e";
 	
//saveCall the query, 
//remembering to pass in the QueryID to delete thatquery queryfunction
$response = $query->delete($queryId);


Explanation:

The first two "runInteraction" lines will simply "include" the class files you already uploaded. Make sure your have used the correct interaction names. You will need to put both of these lines on any page, or interaction, that you will be calling the class.

  

//Create our query object
$query = new Query(Config::$ANALYTICS_ANALYST);

This line will simply create the $query object, using the analyst credentials from the the Config.class.php file.

 

//Read all saved queries
$res = $query->get();

This line will will read all saved queries (there are no search options available).

 

//find the queryID for the query that you need to update
$queryId = $res[0]["_id"];

 Each query has a unique id, you will need to know the ID of the query that you need to delete.

 

//delete the query, remembering to pass in the queryId for the query to deleted 
$response = $query->delete($queryId);

Delete This function will delete the query , remembering to pass you specify in the correct QueryID$queryId variable.

$queryId (string)

This is the QueryID Query ID of the query you wish to delete. Your QueryID will have been returned (in the return object) when you first saved the query. You can also find the correct QueryID by using $query->get() to return all saved queries.

Example:

 

Code Block
languagephp
themeRDark
firstline1
titleCode Block Example
linenumberstrue
/* --- Method 1: Find the QueryID in the return array after saving a query --- */
//save query, returns object with unique Query ID
$res = $query->save($name, $type, $params);

//find the queryID
$queryId = $res["_id"];


/* --- Method 2: query all saved queries and choose the appropriate QueryID --- */
//Alternately, you can use $query->get() to return all saved queries
$res = $query->get();
           
//find the QueryID
$queryId = $res[0]["_id"];

  You can use the List (Read) Saved Queries function to find your query ID, if you're not sure.

Return:

If the delete was successful the response would be boolean TRUE. If you try to delete a query that does not exist,  it will return boolean FALSE.

Code Block
themeRDark
titleReturn
//If delete was successful 
 
1
 
//If delete was unsuccessful