Accessing Calendar Dictionary in For Each Loop

Hello,

I am using the Get Events service on a Google Calendar, which retrieves my a list of events and stores them in a variable I named ‘response’


service: calendar.get_events
metadata: {}
data:
  start_date_time: "2024-02-29 00:00:00"
  end_date_time: "2024-03-06 23:59:00"
target:
  entity_id: calendar.example_gmail_com
response_variable: response

I am returned with following data:


context:
  id: {removed}
  parent_id: {removed}
  user_id: null
response:
  calendar.example_gmail_com:
    events:
      - start: '2024-02-29T07:00:00+01:00'
        end: '2024-02-29T08:00:00+01:00'
        summary: RECYCLING BAG
      - start: '2024-03-02T07:00:00+01:00'
        end: '2024-03-02T08:00:00+01:00'
        summary: Black Bag

I am trying to iterate over the events listed using a For each, in the repeat scope


repeat:
  sequence: []
  for_each: "{{response.calendar.example_gmail_com.events}}"

Although I can see the data there and I know the variable exists with those attributes, I keep getting the error:

Error: UndefinedError: ‘dict object’ has no attribute ‘calendar’

How can I succesfully access the list under events, stored inside my response variable.

Thank you in advance

I believe the below will work. I tested with my own variables with success though this statment just dumps the whole payload.
EDIT: just the for_each: statement was tested.
CORRECTED: The quotes within the response object needs to be escap’d. both " and ’ produced an output without error.

repeat:
  sequence: []
  for_each: "{{ response[\'calendar.example_gmail_com\'][\'events\'] }}"  ### Corrected ###

You need to use single quotes inside the expression if you use double quotes outside (or vice-versa).

repeat:
  sequence: []
  for_each: "{{ response['calendar.example_gmail_com']['events'] }}"

Thanks Didgeridrew, I messed up moving it over from my testbed.