Let's have generating functional $Z(J)$: $$ Z(J) = \langle 0|\hat {T}e^{i \int d^{4}x (L_{Int}(\varphi (x)) + J(x) \varphi (x))}|0 \rangle , \qquad (1) $$ where $J(x)$ is the functional argument (source), $\hat {T}$ is the chronological operator, $\varphi (x)$ - some field.
I want to understand the reasons for its introduction for the summands of expansion of S-matrix. As I read in the books, it helps to consider only the vacuum expectation values, forgetting about in- and out-states. But in $(1)$ appear summands like $\int \frac{J(p)dp}{p^2 - m^2 + i0}$ instead of the contributions from external lines. It may refer to the internal lines. So what to do with them and are there some other reasons to introducing $(1)$ except written by me?