Ojonugwa Jude Ochalifu
Ojonugwa Jude Ochalifu

Reputation: 27257

Cannot get list of entries: The resource could not be found (Contentful)

I am trying to retrieve a list of entries based on category_type but I'm getting the exception below:

I/flutter ( 8486): Cannot get list of entries. Finished with error: {
I/flutter ( 8486):   "sys": {
I/flutter ( 8486):     "type": "Error",
I/flutter ( 8486):     "id": "NotFound"
I/flutter ( 8486):   },
I/flutter ( 8486):   "message": "The resource could not be found.",
I/flutter ( 8486):   "requestId": "883045ce-dcc2-4187-ab1d-28c57ad18756"
I/flutter ( 8486): }
I/flutter ( 8486): null

This is the calling code:

Future<List<Category>> getCategories() async {
  try {
     final entries = await _contentfulClient.getEntries<Category>(
      params: {
        'content_type': 'category',
        'skip': '0',
        'limit': '100',
        'order': 'sys.createdAt',
    },
  );

    return entries.items.asList();
  } catch(exception){
    print(exception.message);
  }
}

The content_type name is correct and there is no mistake in the spelling.

I tried a different code to get information about the space I'm trying to access and that works just fine:

Future<Space> getCurrentSpaceDetails() async {
  try {
    return await _contentfulClient.getSpaceDetails(
      spaceid: Secrets.CONTENTFUL_SPACE_ID);
  } on ContentfulError catch (error) {
  throw ContentfulError(message: error.message);
  }
 }

with the output:

I/flutter ( 8486): Space {
I/flutter ( 8486):   sys=SystemFields {
I/flutter ( 8486):     id=5k4zwxslsof9,
I/flutter ( 8486):     type=Space,
I/flutter ( 8486):   },
I/flutter ( 8486):   locales=[Locale {
I/flutter ( 8486):     code=en-US,
I/flutter ( 8486):     name=English (United States),
I/flutter ( 8486):     isDefault=true,
I/flutter ( 8486):   }],
I/flutter ( 8486):   name=afro-quiz,
I/flutter ( 8486): }

So I don't think this has anything to do with the installation.

I am using the contentful_dart 0.0.5 dependency

Upvotes: 1

Views: 3955

Answers (1)

Ojonugwa Jude Ochalifu
Ojonugwa Jude Ochalifu

Reputation: 27257

So what I finally did was go to the content delivery API references for java:

https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters/content-type/query-entries/console/java

where i followed the example to query entries by content type

I modified the url below to fit my use case:

/spaces/{space_id}/environments/{environment_id}/entries?access_token={access_token}&content_type={content_type}

Final result:

 Future getAllCategories(String spaceId,
   String accessToken, String contentTypeId) async {

   try {
     final response = await _contentfulClient.client.get(
         'https://$_baseUrl/spaces/$spaceId/environments/$_baseEnvironment

          /entries?access_token=$accessToken&content_type=$contentTypeId');
        return response.body;
   } catch (exception) {

     print(exception.message);
   }
 }

This finally worked for me.

Upvotes: 0

Related Questions