Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get list of linked assets for an entry when using the Javascript Plain API #1506

Open
caprica opened this issue Sep 27, 2022 · 3 comments

Comments

@caprica
Copy link

caprica commented Sep 27, 2022

Expected Behavior

When using the Javascript Plain API, invoking entry.getMany() should return linked entries and assets in a field named "includes" in the JSON response.

Actual Behavior

The "includes" field is not present in the JSON response.

Steps to Reproduce

This is representative code:

import * as contentful from 'contentful-management';

const client = contentful.createClient({ accessToken: API_KEY }, { type: 'plain' } );

const test = async () => {
    const args = {
        spaceId: 'whatever',
        environmentId: 'whatever',
        query: {
            content_type: 'whatever',
            include: 10
        }
    };
    return await client.entry.getMany(args);
}

test().then(result => {
    console.log(JSON.stringify(result, null, 2));
});

The result object contains "items" fields with the entry fields as expected - but the entry does not contain an "includes" field with the list of referred entries or assets.

Since I specified "include" in the request, I expected the linked assets would be returned with the entries.

Context

I was referring to this article, and trying to apply it to the Javascript Plain API:

https://www.contentful.com/blog/2021/04/14/exploring-linked-entries-assets-contentful/

I need to get the list of assets referenced by an entry, without having to know the field names of the entry in advance, and without having to search object keys in the entry.

I need this list of assets so I can easily copy them to another space.

Is there another way to get the list of assets for an entry?

Environment

  • Language Version: node v16.16.0
  • Package Manager Version: npm 8.11.0
  • Browser Version: n/a
  • Operating System: Windows 10 (64-bit)
  • Package Version: 10.14.0
  • Which API are you using?: Management
@marcolink
Copy link
Member

Hi @caprica,

the article is describing the Contentful delivery API. The provided code example is using the Contentful management API 🙃

Your first line just read

import * as contentful from 'contentful-management';
// ...

I hope that solves your problem!

best
Marco

@caprica
Copy link
Author

caprica commented Oct 12, 2022

OK, but is it not possible to get that same list of assets through the management API?

Ideally I don't want to have this code use both the management and the delivery APIs.

@rajeevRVU
Copy link

Hey, Im also having a similar issue. Would be great if we could have this functionality added to the Contentful management API.

Thanks

@marcolink marcolink transferred this issue from contentful/contentful.js Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants