In this paper, we present a distributed algorithm for solving convex, constraint-coupled, optimization problems over peer-to-peer networks. We consider a network of processors that aim to cooperatively minimize the sum of local cost functions, subject to individual constraints and to global coupling constraints. The major assumption of this work is that the cost functions are unknown and must be learned online. We propose a fully distributed algorithm, based on a primal decomposition approach, that uses iteratively refined data-driven estimations of the cost functions over the iterations. The algorithm is scalable and maintains private information of agents. We prove that, asymptotically, the distributed algorithm provides the optimal solution of the problem even though the true cost functions are never used within the algorithm. The analysis requires an indepth exploration of the primal decomposition approach and shows that the distributed algorithm can be thought of as an epsilon-subgradient method applied to a suitable reformulation of the original problem. Finally, numerical computations corroborate the theoretical findings and show the efficacy of the proposed approach.