When running netlify build or npm run build locally the site builds fine no problems at all.
When using a web hook, triggering a build via UI or merging code the build fails with 502 error from the endpoint. This is only happening in the Netlify environment.
502s and 504s are server-side errors. Have you tried contacting the API you’re trying to use? They control their servers and would be able to tell you why they responded with a 5xx status.