Primary metabolites are essential to the plant i.e. proteins, sugars, amino acids, etc.
It is the secondary metabolites that are used as medicines, dyes, flavourings, etc. The function of these products in the plant is for such things as defense to stop them being eaten, inhibition of bacterial or fungal pathogens, or to colour the petals so as to attract pollinators. These secondary products have been used by humans for many useful purposes. They serve as sources and models of industrial oils, gums, spices, saponins, waxes, resins, dyes, tannins, soaps, vegetable oils, natural rubber, pesticides, perfumes, flavours and pharmaceuticals. Secondary metabolites are produced in specialized cell types, at certain developmental stages.