contentstack / contentstack-javascript

Javascript SDK for Contentstack's Content Delivery API (Nodejs and Browser)
MIT License
27 stars 23 forks source link

Can't pull single entry with 3.19 #142

Closed littlefengers closed 3 weeks ago

littlefengers commented 8 months ago

Hey, I'm getting this error when I try to pull a specific entry

Using: let query = Stack.ContentType(contentTypeUid).Entry(entryUid)

Error fetching entries: { message: 'Cannot call a class as a function' }

I can still get all the entries if only providing contentId.

I can confirm that it works when I'm on 3.17.1

marcinlad commented 7 months ago

I confirm, it doesn't work for me either

peterbartels commented 7 months ago

We have the same issue, had to downgrade

alexemurphy commented 7 months ago

Yes same, even on a bare CRA

c0pp3rt0p commented 6 months ago

Can confirm this is still an issue. Reverted versions and works again.

nadeem-cs commented 6 months ago

Hey , thanks for raising this. Could any of you please provide more clarity on the query? The fetch call seems to be working on my side. Here's how I did it:

import contentstack from 'contentstack';
import 'dotenv/config';

const stack = contentstack.Stack({
  api_key: process.env.API_KEY,
  delivery_token: process.env.DELIVERY_TOKEN,
  environment: process.env.ENVIRONMENT,
})

const result = await stack
  .ContentType("author")
  .Entry("bltf01a781af0dda942")
  .toJSON()
  .fetch();

console.log({ result });

cc @littlefengers @c0pp3rt0p

c0pp3rt0p commented 5 months ago

@nadeem-cs

Here's how we're currenlty calling it.

     const Query = this._contentStack
      .ContentType('author')
      .Entry('bltf01a781af0dda942')
      .includeContentType()
      .includeEmbeddedItems()
      .language(locale)
      .includeFallback()
      .includeReference('some_sub_type');
    const content = (await Query.fetch()).toJSON();
nadeem-cs commented 5 months ago

@c0pp3rt0p the toJSON method should be called before fetch call. So your query would become

const Query = this._contentStack
    .ContentType('author')
    .Entry('bltf01a781af0dda942')
    .includeContentType()
    .includeEmbeddedItems()
    .language(locale)
    .includeFallback()
    .includeReference('some_sub_type');
const content = await Query.toJSON().fetch();

Try this and let me know if that works.

dmoss18 commented 5 months ago

@nadeem-cs Can you update the QuickStart guide? It does not designate that in the instructions here. The example it gives is

const Stack = Contentstack.Stack({ "api_key": "api_key", "delivery_token": "delivery_token", "environment": "environment" });
const entry = Stack.ContentType('blog').Entry("entry_uid");
const result = await entry.fetch()
c0pp3rt0p commented 5 months ago

@nadeem-cs That fixes my issues. Calling toJSON() prior to fetch() corrects the problem for my case. Thank you!

cefn commented 4 months ago

I had the same problem after upgrading from a previously working version, and calling toJSON() before .fetch() was the resolution that allowed me to use the latest package.

cs-raj commented 3 weeks ago

Closing the issue as it has been resolved