Fetch asset ID
An asset represents a website or application registered in truConsent (e.g. “Main Marketing Website”). You need its assetId to mount TruConsentModal.
Use your VITE_TRU_CONSENT_ADMIN_API_KEY and VITE_TRU_CONSENT_ORGANIZATION_ID from Step 1.
Fetch all assets
Section titled “Fetch all assets”curl -X GET "https://truapi-dev.truconsent.io/api/v1/external/public/assets" \ -H "X-API-Key: $VITE_TRU_CONSENT_ADMIN_API_KEY" \ -H "X-Org-Id: $VITE_TRU_CONSENT_ORGANIZATION_ID"const response = await fetch( "https://truapi-dev.truconsent.io/api/v1/external/public/assets", { headers: { "X-API-Key": import.meta.env.VITE_TRU_CONSENT_ADMIN_API_KEY, "X-Org-Id": import.meta.env.VITE_TRU_CONSENT_ORGANIZATION_ID, }, });const { data } = await response.json();interface Asset { id: string; name: string; asset_type: string;}
const response = await fetch( "https://truapi-dev.truconsent.io/api/v1/external/public/assets", { headers: { "X-API-Key": import.meta.env.VITE_TRU_CONSENT_ADMIN_API_KEY, "X-Org-Id": import.meta.env.VITE_TRU_CONSENT_ORGANIZATION_ID, }, });const { data }: { data: Asset[] } = await response.json();import osimport requests
url = "https://truapi-dev.truconsent.io/api/v1/external/public/assets"headers = { "X-API-Key": os.environ["VITE_TRU_CONSENT_ADMIN_API_KEY"], "X-Org-Id": os.environ["VITE_TRU_CONSENT_ORGANIZATION_ID"],}response = requests.get(url, headers=headers)data = response.json()["data"]Invoke-RestMethod -Method Get ` -Uri "https://truapi-dev.truconsent.io/api/v1/external/public/assets" ` -Headers @{ "X-API-Key" = $env:VITE_TRU_CONSENT_ADMIN_API_KEY "X-Org-Id" = $env:VITE_TRU_CONSENT_ORGANIZATION_ID }Sample response
Section titled “Sample response”{ "data": [ { "asset_type": "Web App", "name": "Main Marketing Website", "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "description": "Primary customer-facing website" }, { "asset_type": "Mobile App", "name": "iOS Application", "id": "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy", "description": "iOS mobile app" } ], "count": 2}Copy the id of the asset that matches your application — this is your assetId.
Result
Section titled “Result”VITE_TRU_CONSENT_ASSET_ID=79bf87f5-xxxx-xxxx-xxxx-xxxxxxxxxxxx