From 56f7d5a4f0a2aeb962e696bde6109606d03383de Mon Sep 17 00:00:00 2001 From: d-klotz Date: Thu, 11 Dec 2025 14:07:20 -0300 Subject: [PATCH 1/2] feat: find nested assets properly --- packages/v1-ready/frontify/api.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/v1-ready/frontify/api.js b/packages/v1-ready/frontify/api.js index 89cdef9..132a596 100644 --- a/packages/v1-ready/frontify/api.js +++ b/packages/v1-ready/frontify/api.js @@ -1125,7 +1125,12 @@ class Api extends OAuth2Requester { status externalId createdAt - modifiedAt + modifiedAt + location { + folder { + id + } + } tags { source value @@ -1208,7 +1213,12 @@ class Api extends OAuth2Requester { status externalId createdAt - modifiedAt + modifiedAt + location { + folder { + id + } + } tags { source value @@ -1220,10 +1230,10 @@ class Api extends OAuth2Requester { } } }`; - + const response = await this._post(this.buildRequestOptions(ql)); this.assertResponse(response); - + const { items, total, From 9471cfc32fef68ab00dab230595acc998d0e31e7 Mon Sep 17 00:00:00 2001 From: d-klotz Date: Thu, 11 Dec 2025 18:09:05 -0300 Subject: [PATCH 2/2] feat: add getAssetWithMetadata and removeAssetCustomMetadata methods --- packages/v1-ready/frontify/api.js | 89 +++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/packages/v1-ready/frontify/api.js b/packages/v1-ready/frontify/api.js index 132a596..c3d8d31 100644 --- a/packages/v1-ready/frontify/api.js +++ b/packages/v1-ready/frontify/api.js @@ -162,6 +162,44 @@ class Api extends OAuth2Requester { return response.data.asset; } + /** + * Gets an asset by ID with custom metadata values + * @param {Object} query - Query parameters + * @param {string} query.assetId - ID of the asset + * @returns {Promise} Asset details with customMetadataValues + */ + async getAssetWithMetadata(query) { + // Query all metadata values - customMetadata returns CustomMetadata interface + // CustomMetadataValue (singular) - for text, url, select, date + // CustomMetadataValues (plural) - for multiselect (uses 'values' array) + const ql = `query AssetWithMetadata { + asset(id: "${query.assetId}") { + id + title + customMetadata { + __typename + ... on CustomMetadataValue { + value + property { + id + } + } + ... on CustomMetadataValues { + values + property { + id + } + } + } + } + }`; + + const response = await this._post(this.buildRequestOptions(ql)); + console.log('[getAssetWithMetadata] Raw response:', JSON.stringify(response.data, null, 2)); + this.assertResponse(response); + return response.data.asset; + } + /** * Gets permissions for an asset * @param {Object} query - Query parameters @@ -951,6 +989,51 @@ class Api extends OAuth2Requester { }; } + /** + * Removes custom metadata values from an asset + * @param {string} assetId - The asset ID + * @param {Array<{propertyId: string, value: any}>} entries - Metadata entries to remove + * @returns {Promise} Result + */ + async removeAssetCustomMetadata(assetId, entries = []) { + if (!entries.length) return null; + + const normalizeValue = (val) => { + if (val === null || val === undefined || val === '') return null; + if (typeof val === 'number') return val; + if (typeof val === 'string') return JSON.stringify(val.trim()); + return JSON.stringify(val); + }; + + const metadataItems = entries + .filter((e) => e && e.propertyId && e.value !== undefined && e.value !== null) + .flatMap((e) => { + if (Array.isArray(e.value)) { + // For multi-select, create separate entries for each value to remove + return e.value + .map((v) => normalizeValue(v)) + .filter((v) => v !== null) + .map((v) => `{ propertyId: "${e.propertyId}", value: ${v} }`); + } + const coerced = normalizeValue(e.value); + if (coerced === null) return []; + return `{ propertyId: "${e.propertyId}", value: ${coerced} }`; + }) + .join(', '); + + if (!metadataItems) return null; + + const ql = `mutation RemoveAssetCustomMetadata {\n` + + ` removeCustomMetadata(input: { parentIds: ["${assetId}"], customMetadata: [ ${metadataItems} ] }) {\n` + + ` __typename\n` + + ` }\n` + + `}`; + + const response = await this._post(this.buildRequestOptions(ql)); + this.assertResponse(response); + return response.data.removeCustomMetadata; + } + /** * Sets or updates custom metadata values on an asset * @param {string} assetId - The asset ID @@ -968,7 +1051,7 @@ class Api extends OAuth2Requester { } return JSON.stringify(val); }; - + const metadataItems = entries .filter((e) => e && e.propertyId && e.value !== undefined && e.value !== null && e.value !== '') .flatMap((e) => { @@ -983,13 +1066,13 @@ class Api extends OAuth2Requester { return `{ propertyId: "${e.propertyId}", value: ${coerced} }`; }) .join(', '); - + const ql = `mutation AddAssetCustomMetadata {\n` + ` addCustomMetadata(input: { parentIds: ["${assetId}"], customMetadata: [ ${metadataItems} ] }) {\n` + ` __typename\n` + ` }\n` + `}`; - + const response = await this._post(this.buildRequestOptions(ql)); this.assertResponse(response); return response.data.addCustomMetadata;