If it's about magnetostatics there are two general ways to address the problem. I'm assuming a "hard ferromagnet", i.e., you have a given magnetization ##\vec{M}## within the magnet, vanishing outside. Then the macroscopic Maxwell equations for the magnetic field read
$$\vec{\nabla} \times \vec{H}=0, \quad \vec{\nabla} \cdot \vec{B}=0$$
and the constitutive equation (in HL units)
$$\vec{B}=\vec{H}+\vec{M}.$$
(a) Use of a scalar potential for ##\vec{H}##
This works only for this special case of magnetostatics without "free currents", i.e., for ##\vec{j}=0##. Since ##\vec{H}## is then vortex free there's a scalar potential,
$$\vec{H}=-\vec{\nabla} \Phi.$$
Together with the constitutive equation you get
$$\vec{\nabla} \cdot \vec{B}=\vec{\nabla} \cdot (\vec{H}+\vec{M})=-\Delta \Phi + \vec{\nabla} \cdot \vec{M}=0.$$
Since ##\vec{M}## is given by assumption, we have
$$-\Delta \Phi=-\vec{\nabla} \cdot \vec{M}.$$
With the Green's function of the Laplace operator you get
$$\Phi(\vec{x})=-\int_{\mathbb{R}^3} \mathrm{d}^3 x' \frac{-\vec{\nabla}' \cdot \vec{M}(\vec{x}')}{4 \pi |\vec{x}-\vec{x}'|}.$$
Integrating by parts gives
$$\Phi(\vec{x})=+\int_{\mathbb{R}^3} \mathrm{d}^3 x' \vec{M}(\vec{x}') \cdot \vec{\nabla}' \frac{1}{4 \pi|\vec{x}-\vec{x}'|} = -\vec{\nabla} \cdot \int_{\mathbb{R}^3} \mathrm{d}^3 x' \frac{\vec{M}(\vec{x}')}{4 \pi |\vec{x}-\vec{x}'|}.$$
(b) Use of a vector potential for ##\vec{B}##
Since ##\vec{B}## is source free there's a vector potential,
$$\vec{B}=\vec{\nabla} \times \vec{A}.$$
Since it is determined only up to a gradient of a scalar field we can impose one "gauge fixing condition", and for static fields the Coulomb gauge is the most convenient one:
$$\vec{\nabla} \cdot \vec{B}=0.$$
Then using the constituent equation we have
$$\vec{\nabla} \times \vec{H}=\vec{\nabla} \times (\vec{B}-\vec{M})=\vec{\nabla} (\vec{\nabla} \times \vec{A}-\vec{M})=0,$$
from which you get
$$\vec{\nabla} \times (\vec{\nabla} \times \vec{A})=-\Delta \vec{A}=\vec{\nabla} \times \vec{M}=\vec{j}_m,$$
which means that the magnetization is equivalent to a current density ##\vec{j}_m##, and again you can use the Green's function of the Laplacian,
$$\vec{A}(\vec{x})=\int_{\mathbb{R}^3} \mathrm{d}^3 x' \frac{\vec{j}_m(\vec{x}')}{4 \pi |\vec{x}-\vec{x}'|}.$$