How to structure variables for passing to script?

Hi I’m still new to HA and, despite reading a lot of posts and examples (and a bit about jinja2), am unclear on the syntax neccessary for passing variables between components. It seems there are a number of different ways of nesting things and I’m not sure which to use in which situation.

For example it took me a while to figure out that to pass a variable in from an API call, you need need to use the last option for your JSON:

{"data": {"variables": {"minutes": "5"}}}
{"data": {"minutes": "5"} }
{"variables": {"minutes": "5"}}
{"minutes": "5"}  <--- this works

I have an automation, which (surprisingly) works even though it’s using data: for the first service instead of data_template:. It’s also using a mix of data: -> variables: -> varname/value and data_template: -> varname/value which I’m also surprised works:

- id: start_pump_when_motion
  alias: Start the pump when motion detected
  trigger:
    - platform: state
      entity_id: sensor.vision_zp3111_multisensor_4in1_burglar
      to: '8'
  action:
    - service: script.turn_on
      data:  # <-- Why does this work without it being "data_template:"?
        entity_id: script.notify_slack_pushbullet
        variables:  # <-- Why does this need to exist?
          message: "Motion. Pump started for {{ states.input_number.pump_run_minutes.state | int }} minutes"
    - service: shell_command.pump_start_variable_time
      data_template:   # Maybe this should be "data:"?
        seconds: '{{ states.input_number.pump_run_minutes_guest.state | int * 60 }}'

This calls a script which uses a variables: subsection (as well as data_template instead of data, since it’s rendering an incoming variable):

notify_slack_pushbullet:
  alias: Notify Slack and PushBullet
  sequence:
    - service: notify.slack
      data_template:
        message: "{{ message }}"
    - service: notify.pushbullet
      data:
        title: ''
      data_template:
        message: "{{ message }}"

Is there some documentation showing when it’s appropriate to using data:, variables:, or both?

Also, why does my action that turns on script.notify_slack_pushbullet correctly resolve the state.input_number variable even though it’s not using a data_template section?

Any enlightenment would be much appreciated.