Query entry with its assets

Is there a way to query all entry with their assets.

I am using php SDK and i dont want to make a second call to get the assets of each entries.

Thanks !

Hi @dev3,

You can retrieve the content of your linked entries by simply adding an appropriate level of the include parameter.

If you wish to include the field content in the actual parent entry, you can also use the ResolveLink function as described in here and here.

1 Like

Thank you for your hints,

but i tried using the Include parameter in my query and it did not work…

Could you share with us how exactly you setup your client and query? Please omit any sensitive credentials.

$client = new Client($accessToken, $spaceID, $branchId);

$query = (new \Contentful\Delivery\Query())

$entries = $client->getEntries($query);

I get one entry from my content-type. This entry contains a media (type: image). But, i dont get any of the information about the media. I only get its id like so:

ResourceArray {#582
-items: array:1 [▼
0 => Entry {#673
#fields: array:4 [▼
“title” => array:1 [:arrow_forward:]
“url” => array:1 [:arrow_forward:]
“image” => array:1 [▼
“en-US” => Link {#668
-linkId: “image-id” <--------------
-linkType: “Asset”
“img_alt” => array:1 [:arrow_forward:]
-localeCode: “en-US”
#localeCodes: array:3 [:arrow_forward:]
#client: Client {#656 :arrow_forward:}
#sys: SystemProperties {#666 :arrow_forward:}
-total: 1
-limit: 100
-skip: 0

Thank you

Hi @dev3,

The issue here is that you haven’t yet tried to access the field. If you try $entry->get('image'), an asset object should be returned.

Hi @gabriel,

I see! but is the $entry->get(‘image’) making a other query?

There is no way to get all the information about the assets of an entry all at once without doing $entry->get(‘xxx’) ?

When an asset contains links to other assets, it is hard to make a generic way to retrieve them all with their sub assets…

Thank you.

Actually, when you set $entry->get(‘image’) that won’t send a request to our API, it will simply access the field value of your retrieved entry.

Alright thank you very much for your help!

@gabriel I have the exact same issue. Could you tell me where i do have to put the $entry->get(‘image’) query / where is this method available?

For example:

$query = new \Contentful\Delivery\Query();
$events = $client->getEntries($query);

throws an exception Call to undefined method Contentful\Core\Resource\ResourceArray::get()
I want to query all event content-types with it’s relations (inspirer).