IMDB API request GraphQL Error 'ClientError: Cannot query field "Image" on type "MainSearchEntity"'

249 views Asked by At

I'm trying to get the top 10 movie name recommendations that match the search term 'Africa', based on the IMDB API demo here https://developer.imdb.com/documentation/api-documentation/sample-queries/search/?ref_=side_nav.

I need the query to return the movie id, title, image poster and filming location.

However, when I run the graph query below, I get the error 'ClientError: Cannot query field "Image" on type "MainSearchEntity".|Cannot query field "FilmingLocation" on type "MainSearchEntity"."

The query works fine when I remove the code Image { url } FilmingLocation { text } from the script.

What could be the problem with the query below?

How do I include the poster image and filming location in the query?

Thanks!


{
  # Get the top 10 name recommendations that match the search term Africa.
  mainSearch(
    first: 10
    options: {
      searchTerm: "Africa"   
      isExactMatch: false   
      type: TITLE      
      includeAdult:false,
    }
  ) {
    edges {
      node {
        entity {
          # For returned Names, get me the id, name text, image, year, country
          ... on Name {
            id
            nameText {
              text
            }
          }
          Image {
                  url
            }
          FilmingLocation {
                  text
            }
        }
      }
    }
  }
}

2

There are 2 answers

3
Julio César Estravis On

Assuming the two fields that are causing you trouble are called posterImage and filmingLocation (usually field names are in camelCase), I guess your query should be:

query {
    # Get the top 10 name recommendations that match the search term Africa.
    mainSearch(
        first: 10
        options: {
            searchTerm: "Africa"
            isExactMatch: false
            type: TITLE
            includeAdult:false,
        }
    ) {
        edges {
            node {
                entity {
                    # For returned Names, get me the id, name text, image, year, country
                    ... on Name {
                        id
                        nameText {
                            text
                        }
                        image {
                            url
                        }
                        filmingLocation {
                            text
                        }
                    }
                }
            }
        }
    }

}

The problem seems to be that the two fields were not inside the MainSearchEntity. Hope it helps!

0
Vakindu On

Fixed it:

Turns out the image poster field is 'primaryImage' not Image.

Here's the working code:


{
  # Get the top 10 name recommendations that match the search term Jennifer.
  mainSearch(
    first: 10
    options: {
      searchTerm: "Jennifer"   
      isExactMatch: false   
      type: TITLE      
      includeAdult:false,
    }
  ) {
    edges {
      node {
        entity {
          # For returned Names, get me the id, name text, image, year, country
          ... on Title {
            id
            titleText {
              text
            }
            primaryImage {
              url
              }
            filmingLocations(first:1) {
              edges{
                node{
                  text
                }
              }
            }
          }
        }
      }
    }
  }
}