Fix SambaPOS GraphQL token endpoint: /Token (SambaPOS OAuth) not /connect/token, GraphQL at /api/graphql

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-14 13:40:09 +00:00
parent e6470ad865
commit d6449d8b52

View file

@ -161,8 +161,8 @@ export async function integrationRoutes(app) {
try { try {
if (!creds.graphql_endpoint || !creds.graphql_username || !creds.graphql_password || !creds.graphql_client_id) if (!creds.graphql_endpoint || !creds.graphql_username || !creds.graphql_password || !creds.graphql_client_id)
throw new Error('GraphQL endpoint, username, password and client ID are required') throw new Error('GraphQL endpoint, username, password and client ID are required')
const origin = new URL(creds.graphql_endpoint).origin const base = creds.graphql_endpoint.replace(/\/$/, '')
const tokenRes = await fetch(`${origin}/connect/token`, { const tokenRes = await fetch(`${base}/Token`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({ body: new URLSearchParams({
@ -170,14 +170,13 @@ export async function integrationRoutes(app) {
username: creds.graphql_username, username: creds.graphql_username,
password: creds.graphql_password, password: creds.graphql_password,
client_id: creds.graphql_client_id, client_id: creds.graphql_client_id,
scope: 'api',
}), }),
signal: AbortSignal.timeout(8000), signal: AbortSignal.timeout(8000),
}) })
if (!tokenRes.ok) throw new Error(`Token request failed (${tokenRes.status})`) if (!tokenRes.ok) throw new Error(`Token request failed (${tokenRes.status})`)
const { access_token } = await tokenRes.json() const { access_token } = await tokenRes.json()
if (!access_token) throw new Error('No access token returned') if (!access_token) throw new Error('No access token returned')
const gqlRes = await fetch(creds.graphql_endpoint.replace(/\/$/, ''), { const gqlRes = await fetch(`${base}/api/graphql`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${access_token}` }, headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${access_token}` },
body: JSON.stringify({ query: '{ __typename }' }), body: JSON.stringify({ query: '{ __typename }' }),