PE Ratio for Entire Market (S&P), Not Individual Stock

Can anyone share an API query that would provide the PE Ratio for the entire market, e.g. S&P, not for an individual stock? I can figure out how to get the price of an ETF that tracks the market, e.g. VTI, but I can’t figure out how to get the PE Ratio for the whole market, either here or IEX. Thoughts? Thanks!