diff --git a/lib/metadataTypes/Automation.js b/lib/metadataTypes/Automation.js index e5d5361ff..5ea15cf66 100644 --- a/lib/metadataTypes/Automation.js +++ b/lib/metadataTypes/Automation.js @@ -1028,7 +1028,7 @@ class Automation extends MetadataType { // the delete endpoint returns a general exception if the automation does not exist; handle it gracefully instead by adding a retrieve first const objectId = customerKey ? await this._getObjectIdForSingleRetrieve(customerKey) : null; if (!objectId) { - Util.logger.error(`- automation not found`); + Util.logger.error(` - automation not found`); return false; } return super.deleteByKeySOAP(customerKey, 'CustomerKey'); diff --git a/lib/metadataTypes/Query.js b/lib/metadataTypes/Query.js index 3a23671b7..ba3b2d27b 100644 --- a/lib/metadataTypes/Query.js +++ b/lib/metadataTypes/Query.js @@ -1,6 +1,7 @@ 'use strict'; const TYPE = require('../../types/mcdev.d'); +const Util = require('../util/util'); const MetadataType = require('./MetadataType'); const File = require('../util/file'); const cache = require('../util/cache'); @@ -32,7 +33,16 @@ class Query extends MetadataType { */ static async retrieve(retrieveDir, _, __, key) { await File.initPrettier('sql'); - const objectId = key ? await this._getObjectIdForSingleRetrieve(key) : null; + let objectId = null; + if (key) { + objectId = await this._getObjectIdForSingleRetrieve(key); + if (!objectId) { + // avoid running the rest request below by returning early + Util.logger.info(`Downloaded: ${this.definition.type} (0) - Key: ${key}`); + return { metadata: {}, type: this.definition.type }; + } + } + return super.retrieveREST( retrieveDir, '/automation/v1/queries/' + (objectId || ''), @@ -51,9 +61,17 @@ class Query extends MetadataType { static async _getObjectIdForSingleRetrieve(key) { const response = await this.client.soap.retrieve('QueryDefinition', ['ObjectID'], { filter: { - leftOperand: 'CustomerKey', - operator: 'equals', - rightOperand: key, + leftOperand: { + leftOperand: 'CustomerKey', + operator: 'equals', + rightOperand: key, + }, + operator: 'AND', + rightOperand: { + leftOperand: 'Status', + operator: 'equals', + rightOperand: 'Active', + }, }, }); return response?.Results?.length ? response.Results[0].ObjectID : null; @@ -351,7 +369,12 @@ class Query extends MetadataType { * @returns {boolean} deletion success status */ static async deleteByKey(customerKey) { + // delete only works with the query's object id const objectId = customerKey ? await this._getObjectIdForSingleRetrieve(customerKey) : null; + if (!objectId) { + Util.logger.error(` - query not found`); + return false; + } return super.deleteByKeyREST('/automation/v1/queries/' + objectId, customerKey); } /**