Create sensor from cURL command

Hi

im trying to create a sensor from this curl command, but I cant get it to work

curl --request GET \
     --url 'https://api.themoviedb.org/3/movie/upcoming?language=en-US&page=1' \
     --header 'Authorization: Bearer  TOKEN' \
     --header 'accept: application/json'

i thought this would work but it doesn’t

rest:
  - resource: https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&language=en-US&page=1&sort_by=popularity.desc&with_release_type=2|3&release_date.gte=2023-12-07&release_date.lte=2024-01-06
    scan_interval: 21600  # Adjust as needed
    headers:
      Authorization: "Bearer TOKEN"
      accept: application/json
    sensor:
      - name: tmdb upcoming movie 0
        json_attributes_path: '$.results[0]'
        json_attributes:
          - '*'
        value_template: "{{ value_json.results[0].title }}"

      - name: tmdb upcoming movie 1
        json_attributes_path: '$.results[1]'
        json_attributes:
          - '*'
        value_template: "{{ value_json.results[1].title }}"

What do you get back from the curl command?

I get this

{
    "dates": {
        "maximum": "2024-01-03",
        "minimum": "2023-12-13"
    },
    "page": 1,
    "results": [{
        "adult": false,
        "backdrop_path": "/xgGGinKRL8xeRkaAR9RMbtyk60y.jpg",
        "genre_ids": [16, 10751, 10402, 14, 35],
        "id": 901362,
        "original_language": "en",
        "original_title": "Trolls Band Together",
        "overview": "When Branch's brother, Floyd, is kidnapped for his musical talents by a pair of nefarious pop-star villains, Branch and Poppy embark on a harrowing and emotional journey to reunite the other brothers and rescue Floyd from a fate even worse than pop-culture obscurity.",
        "popularity": 1745.484,
        "poster_path": "/bkpPTZUdq31UGDovmszsg2CchiI.jpg",
        "release_date": "2023-10-12",
        "title": "Trolls Band Together",
        "video": false,
        "vote_average": 7.175,
        "vote_count": 297
    }, {
        "adult": false,
        "backdrop_path": "/uIk2g2bRkNwNywKZIhC5oIU94Kh.jpg",
        "genre_ids": [35, 10751, 14],
        "id": 787699,
        "original_language": "en",
        "original_title": "Wonka",
        "overview": "Willy Wonka – chock-full of ideas and determined to change the world one delectable bite at a time – is proof that the best things in life begin with a dream, and if you’re lucky enough to meet Willy Wonka, anything is possible.",
        "popularity": 748.278,
        "poster_path": "/qhb1qOilapbapxWQn9jtRCMwXJF.jpg",
        "release_date": "2023-12-06",
        "title": "Wonka",
        "video": false,
        "vote_average": 6.833,
        "vote_count": 21
    }, {
        "adult": false,
        "backdrop_path": "/g9YlEHnShgNAnvN0jOoYn6U87rV.jpg",
        "genre_ids": [18, 878, 28, 27],
        "id": 940721,
        "original_language": "ja",
        "original_title": "ゴジラ-1.0",
        "overview": "In postwar Japan, a new terror rises. Will the devastated people be able to survive... let alone fight back?",
        "popularity": 497.327,
        "poster_path": "/fk62hm95sVNHy5Lkx3d18wj1v19.jpg",
        "release_date": "2023-11-03",
        "title": "Godzilla Minus One",
        "video": false,
        "vote_average": 8.402,
        "vote_count": 61
    }, {
        "adult": false,
        "backdrop_path": "/f1AQhx6ZfGhPZFTVKgxG91PhEYc.jpg",
        "genre_ids": [18, 36, 10752],
        "id": 753342,
        "original_language": "en",
        "original_title": "Napoleon",
        "overview": "An epic that details the checkered rise and fall of French Emperor Napoleon Bonaparte and his relentless journey to power through the prism of his addictive, volatile relationship with his wife, Josephine.",
        "popularity": 407.172,
        "poster_path": "/jE5o7y9K6pZtWNNMEw3IdpHuncR.jpg",
        "release_date": "2023-11-22",
        "title": "Napoleon",
        "video": false,
        "vote_average": 6.435,
        "vote_count": 591
    }, {
        "adult": false,
        "backdrop_path": "/ehumsuIBbgAe1hg343oszCLrAfI.jpg",
        "genre_ids": [16, 10751, 14, 12],
        "id": 1022796,
        "original_language": "en",
        "original_title": "Wish",
        "overview": "Asha, a sharp-witted idealist, makes a wish so powerful that it is answered by a cosmic force – a little ball of boundless energy called Star. Together, Asha and Star confront a most formidable foe - the ruler of Rosas, King Magnifico - to save her community and prove that when the will of one courageous human connects with the magic of the stars, wondrous things can happen.",
        "popularity": 312.81,
        "poster_path": "/AcoVfiv1rrWOmAdpnAMnM56ki19.jpg",
        "release_date": "2023-11-13",
        "title": "Wish",
        "video": false,
        "vote_average": 6.683,
        "vote_count": 90
    }, {
        "adult": false,
        "backdrop_path": "/lsJC9T6vo5HnqxEDjzGaczPUn6U.jpg",
        "genre_ids": [18, 35],
        "id": 839369,
        "original_language": "en",
        "original_title": "May December",
        "overview": "Twenty years after their notorious tabloid romance gripped the nation, a married couple buckles under pressure when an actress arrives to do research for a film about their past.",
        "popularity": 312.248,
        "poster_path": "/yibtHDMO70RueiEmtrcJeTiiHFo.jpg",
        "release_date": "2023-11-16",
        "title": "May December",
        "video": false,
        "vote_average": 6.571,
        "vote_count": 63
    }, {
        "adult": false,
        "backdrop_path": "/dZbLqRjjiiNCpTYzhzL2NMvz4J0.jpg",
        "genre_ids": [27, 53],
        "id": 951491,
        "original_language": "en",
        "original_title": "Saw X",
        "overview": "Between the events of 'Saw' and 'Saw II', a sick and desperate John Kramer travels to Mexico for a risky and experimental medical procedure in hopes of a miracle cure for his cancer, only to discover the entire operation is a scam to defraud the most vulnerable. Armed with a newfound purpose, the infamous serial killer returns to his work, turning the tables on the con artists in his signature visceral way through devious, deranged, and ingenious traps.",
        "popularity": 280.032,
        "poster_path": "/aQPeznSu7XDTrrdCtT5eLiu52Yu.jpg",
        "release_date": "2023-09-26",
        "title": "Saw X",
        "video": false,
        "vote_average": 7.392,
        "vote_count": 1216
    }, {
        "adult": false,
        "backdrop_path": "/zgQQF04u3OgNBJqClRNby1FPz9s.jpg",
        "genre_ids": [16, 10751, 28, 878, 35],
        "id": 893723,
        "original_language": "en",
        "original_title": "PAW Patrol: The Mighty Movie",
        "overview": "A magical meteor crash lands in Adventure City and gives the PAW Patrol pups superpowers, transforming them into The Mighty Pups.",
        "popularity": 272.512,
        "poster_path": "/aTvePCU7exLepwg5hWySjwxojQK.jpg",
        "release_date": "2023-09-21",
        "title": "PAW Patrol: The Mighty Movie",
        "video": false,
        "vote_average": 6.9,
        "vote_count": 185
    }, {
        "adult": false,
        "backdrop_path": "/4kmNLwmVeT3xMciSRefE6SCi2hX.jpg",
        "genre_ids": [80, 18, 53],
        "id": 1027073,
        "original_language": "en",
        "original_title": "In the Land of Saints and Sinners",
        "overview": "In a remote Irish village, a damaged Finbar is forced to fight for redemption after a lifetime of sins, but what price is he willing to pay? In the land of saints and sinners, some sins can't be buried.",
        "popularity": 264.704,
        "poster_path": "/443c0xNTLackGkFOKfbPClKMpIk.jpg",
        "release_date": "2023-10-06",
        "title": "In the Land of Saints and Sinners",
        "video": false,
        "vote_average": 6.9,
        "vote_count": 35
    }, {
        "adult": false,
        "backdrop_path": "/bckxSN9ueOgm0gJpVJmPQrecWul.jpg",
        "genre_ids": [28, 12, 14],
        "id": 572802,
        "original_language": "en",
        "original_title": "Aquaman and the Lost Kingdom",
        "overview": "Black Manta, still driven by the need to avenge his father's death and wielding the power of the mythic Black Trident, will stop at nothing to take Aquaman down once and for all. To defeat him, Aquaman must turn to his imprisoned brother Orm, the former King of Atlantis, to forge an unlikely alliance in order to save the world from irreversible destruction.",
        "popularity": 246.524,
        "poster_path": "/8xV47NDrjdZDpkVcCFqkdHa3T0C.jpg",
        "release_date": "2023-12-20",
        "title": "Aquaman and the Lost Kingdom",
        "video": false,
        "vote_average": 0.0,
        "vote_count": 0
    }, {
        "adult": false,
        "backdrop_path": "/igwshQHV36aBkPyWp7En5P4Kn2V.jpg",
        "genre_ids": [27, 53, 9648],
        "id": 1071215,
        "original_language": "en",
        "original_title": "Thanksgiving",
        "overview": "After a Black Friday riot ends in tragedy, a mysterious Thanksgiving-inspired killer terrorizes Plymouth, Massachusetts - the birthplace of the holiday. Picking off residents one by one, what begins as random revenge killings are soon revealed to be part of a larger, sinister holiday plan.",
        "popularity": 183.562,
        "poster_path": "/f5f3TEVst1nHHyqgn7Z3tlwnBIH.jpg",
        "release_date": "2023-11-16",
        "title": "Thanksgiving",
        "video": false,
        "vote_average": 6.3,
        "vote_count": 82
    }, {
        "adult": false,
        "backdrop_path": "/ptz5ETMxDoRRiE69BVuIxJzyTEO.jpg",
        "genre_ids": [16, 35, 12, 10751],
        "id": 940551,
        "original_language": "en",
        "original_title": "Migration",
        "overview": "After a migrating duck family alights on their pond with thrilling tales of far-flung places, the Mallard family embarks on a family road trip, via New York City, to tropical Jamaica.",
        "popularity": 132.642,
        "poster_path": "/ldfCF9RhR40mppkzmftxapaHeTo.jpg",
        "release_date": "2023-12-06",
        "title": "Migration",
        "video": false,
        "vote_average": 7.583,
        "vote_count": 6
    }, {
        "adult": false,
        "backdrop_path": "/iEFuHjqrE059SmflBva1JzDJutE.jpg",
        "genre_ids": [16, 10751, 14, 28, 10749, 10402],
        "id": 496450,
        "original_language": "fr",
        "original_title": "Miraculous - le film",
        "overview": "A life of an ordinary Parisian teenager Marinette goes superhuman when she becomes Ladybug. Bestowed with magical powers of creation, Ladybug must unite with her opposite, Cat Noir, to save Paris as a new villain unleashes chaos unto the city.",
        "popularity": 136.654,
        "poster_path": "/dQNJ8SdCMn3zWwHzzQD2xrphR1X.jpg",
        "release_date": "2023-07-05",
        "title": "Miraculous: Ladybug \u0026 Cat Noir, The Movie",
        "video": false,
        "vote_average": 7.8,
        "vote_count": 673
    }, {
        "adult": false,
        "backdrop_path": "/zZnsfR6BRqtxyLyAhsi2TMukEBx.jpg",
        "genre_ids": [16, 28, 80, 9648],
        "id": 1047041,
        "original_language": "ja",
        "original_title": "名探偵コナン 黒鉄の魚影(サブマリン)",
        "overview": "Many engineers from around the world gather at the Interpol marine facility \"Pacific Buoy\" on Hachijo-jima, in the sea south of central Tokyo Prefecture coast, to witness the launch of a new system that connects all law enforcement camera systems around the world and enables facial recognition worldwide. Conan, along with his friends Kogoro, Ran, Agasa, Haibara, and the Detective Boys, also heads to the island with an invitation from Sonoko to see the whales. He receives a message from Subaru, who says that a Europol agent has been murdered in Germany by Gin. Perturbed, Conan sneaks onto the police ship led by Kuroda, which is bringing them to the island to protect the completion work, and tours the new facility, just in time for the Black Organization to kidnap a female engineer, seeking a piece of important data in her USB drive. A terrifying howl of screws is heard from the ocean as an unknown person approaches Haibara.",
        "popularity": 133.299,
        "poster_path": "/ksQ8uNgoWsVH6a0oPB6zx08pOwU.jpg",
        "release_date": "2023-04-14",
        "title": "Detective Conan: Black Iron Submarine",
        "video": false,
        "vote_average": 6.6,
        "vote_count": 53
    }, {
        "adult": false,
        "backdrop_path": "/sQLMaESdeELB7Dl8HdxfGlZYRzu.jpg",
        "genre_ids": [35, 18],
        "id": 840430,
        "original_language": "en",
        "original_title": "The Holdovers",
        "overview": "A curmudgeonly instructor at a New England prep school is forced to remain on campus during Christmas break to babysit the handful of students with nowhere to go. Eventually, he forms an unlikely bond with one of them — a damaged, brainy troublemaker — and with the school’s head cook, who has just lost a son in Vietnam.",
        "popularity": 127.162,
        "poster_path": "/VHSzNBTwxV8vh7wylo7O9CLdac.jpg",
        "release_date": "2023-10-27",
        "title": "The Holdovers",
        "video": false,
        "vote_average": 7.797,
        "vote_count": 91
    }, {
        "adult": false,
        "backdrop_path": "/qElNES0sHVQcbzvGrTx7ccpGzij.jpg",
        "genre_ids": [878, 28, 18],
        "id": 842675,
        "original_language": "zh",
        "original_title": "流浪地球2",
        "overview": "Humans built huge engines on the surface of the earth to find a new home. But the road to the universe is perilous. In order to save earth, young people once again have to step forward to start a race against time for life and death.",
        "popularity": 123.418,
        "poster_path": "/pR858ihc6Ls9xohpdRJVjV787ml.jpg",
        "release_date": "2023-01-22",
        "title": "The Wandering Earth II",
        "video": false,
        "vote_average": 7.227,
        "vote_count": 403
    }, {
        "adult": false,
        "backdrop_path": "/A1g8AvP3KpDyu0iyjS6roRxK77v.jpg",
        "genre_ids": [53, 80],
        "id": 978870,
        "original_language": "it",
        "original_title": "L'ultima notte di Amore",
        "overview": "On the night before his retirement, police lieutenant Franco Amore is called to investigate the death of a long-time partner of his in a diamond heist in which he was involved.",
        "popularity": 107.818,
        "poster_path": "/dBp0REsZkZ1HK1PycwlLdBtYdsd.jpg",
        "release_date": "2023-03-09",
        "title": "Last Night of Amore",
        "video": false,
        "vote_average": 7.2,
        "vote_count": 302
    }, {
        "adult": false,
        "backdrop_path": "/gsVC7HMf4VR2XFOyqjTSklY2Tms.jpg",
        "genre_ids": [878, 10749, 35],
        "id": 792307,
        "original_language": "en",
        "original_title": "Poor Things",
        "overview": "Brought back to life by an unorthodox scientist, a young woman runs off with a lawyer on a whirlwind adventure across the continents. Free from the prejudices of her times, she grows steadfast in her purpose to stand for equality and liberation.",
        "popularity": 85.945,
        "poster_path": "/kCGlIMHnOm8JPXq3rXM6c5wMxcT.jpg",
        "release_date": "2023-12-07",
        "title": "Poor Things",
        "video": false,
        "vote_average": 0.0,
        "vote_count": 0
    }, {
        "adult": false,
        "backdrop_path": "/czbn0za9QyP5umRBikimxQ2iNm9.jpg",
        "genre_ids": [10749, 35],
        "id": 970948,
        "original_language": "en",
        "original_title": "What Happens Later",
        "overview": "Two ex-lovers get snowed in at a regional airport overnight. Indefinitely delayed, Willa, a magical thinker, and Bill, a catastrophic one, find themselves just as attracted to and annoyed by one another as they did decades earlier. But as they unpack the riddle of their mutual past and compare their lives to the dreams they once shared, they begin to wonder if their reunion is mere coincidence, or something more enchanted.",
        "popularity": 67.858,
        "poster_path": "/5TrWftAac3EeMcatyiCdAglWKb6.jpg",
        "release_date": "2023-11-02",
        "title": "What Happens Later",
        "video": false,
        "vote_average": 5.813,
        "vote_count": 8
    }, {
        "adult": false,
        "backdrop_path": "/w1ZeZ8XYTBCovnXi9bwi7D7glM4.jpg",
        "genre_ids": [28, 80],
        "id": 891699,
        "original_language": "en",
        "original_title": "Silent Night",
        "overview": "A tormented father witnesses his young son die when caught in a gang's crossfire on Christmas Eve. While recovering from a wound that costs him his voice, he makes vengeance his life's mission and embarks on a punishing training regimen in order to avenge his son's death.",
        "popularity": 91.999,
        "poster_path": "/tlcuhdNMKNGEVpGqBZrAaOOf1A6.jpg",
        "release_date": "2023-11-30",
        "title": "Silent Night",
        "video": false,
        "vote_average": 6.978,
        "vote_count": 23
    }],
    "total_pages": 34,
    "total_results": 679
}

When you say “doesn’t work”, what happens? Is there anything in the logs?

Things I’d try:

  • Put the resource URL in quotes: if has a lot of odd characters in it
  • Add Content-Type: application/json to the existing headers
  • Un-wildcard the json_attributes: explicitly list the ones you want.

I tried this now, but sensor still says unknown

rest:
  - resource: "https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&language=en-US&page=1&sort_by=popularity.desc&with_release_type=2|3&release_date.gte=2023-12-07&release_date.lte=2024-01-06"
    scan_interval: 21600  
    headers:
      Authorization:  "Bearer Token"
    Content-Type: application/json
    sensor:
      - name: tmdb upcoming movie 0
        json_attributes_path: '$.results[0]'
        json_attributes:
          - title
        value_template: "{{ value_json.results[0].id }}"

      - name: tmdb upcoming movie 1
        json_attributes_path: '$.results[1]'
        json_attributes:
          - title
        value_template: "{{ value_json.results[1].id }}"

I assume you are actually putting your real token into the Authorization header?

Cut it right back: does this work (with indentation fixed)? If not, check the full logs to see what it says.

rest:
  - resource: "https://api.themoviedb.org/3/discover/movie?include_adult=false&include_video=false&language=en-US&page=1&sort_by=popularity.desc&with_release_type=2|3&release_date.gte=2023-12-07&release_date.lte=2024-01-06"
    scan_interval: 21600  
    headers:
      Authorization:  "Bearer [YOUR TOKEN HERE]"
      accept: application/json
      Content-Type: application/json
    sensor:
      - name: tmdb upcoming movie 0
        value_template: "{{ value[:100] }}"

State should be the first 100 characters of the JSON response.