Needs review
Project:
Acquia DAM
Version:
1.1.2
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
18 Jun 2025 at 21:02 UTC
Updated:
25 Aug 2025 at 20:37 UTC
Jump to comment: Most recent
It is difficult to understand how to retrieve external urls to files which are stored in the DAM in a programmatic way, either via Twig or PHP.
Some use cases:
TBD
TBD
My current approach to handling this is to create a new service in Drupal that connects to the API. The method looks like this:
public function getAssetDamUrl(string $asset_id, string $format = 'original'): string {
$search_url = $this->getAssetLookupUrl($asset_id);
$access_token = $this->settings->get('dam_access_key');
$headers = [
'Authorization' => "Bearer " . $access_token,
];
try {
$request = $this->httpClient->request('GET', $search_url, ['headers' => $headers]);
$item_data = json_decode($request->getBody()->getContents(), TRUE);
return $item_data['embeds'][$format]['url'] ?? "";
}
catch (RequestException $e) {
return "";
}
}
But I wonder if:
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
rajeshreeputraTry using
getAsset($asset_id)method.Comment #3
rajeshreeputraYou can also try
Comment #4
dan612 commentedThank you! these are working for me. Much more streamlined 😁.
Would it be worth adding these to the README in a ## DEVELOPER USAGE section?
Comment #5
rajeshreeputraYou can also use a stream wrapper if both asset_id and version_id are available.
\Drupal::service('stream_wrapper.acquia_dam')->getViaUri('acquia-dam://<asset_id>/<version_id>')->getExternalUrl();Comment #6
rajeshreeputraAdding this to README sound good, let's make it.
Comment #8
dan612 commentedAdded some info to the README!