16 lines
540 B
TypeScript
16 lines
540 B
TypeScript
|
|
export async function dolibarrFetch(endpoint: string, options: RequestInit = {}) {
|
||
|
|
const apiKey = process.env.NEXT_PUBLIC_DOLIBARR_API_KEY
|
||
|
|
console.log(apiKey)
|
||
|
|
const url = `${process.env.NEXT_PUBLIC_API_URL}/${endpoint}?DOLAPIKEY=${process.env.NEXT_PUBLIC_DOLIBARR_API_KEY}`;
|
||
|
|
// ${process.env.DOLIBARR_API_KEY}
|
||
|
|
console.log(url)
|
||
|
|
|
||
|
|
const res = await fetch(url);
|
||
|
|
|
||
|
|
if (!res.ok) {
|
||
|
|
console.error("Error en la llamada Dolibarr:", res.status, await res.text());
|
||
|
|
throw new Error("Dolibarr API error");
|
||
|
|
}
|
||
|
|
|
||
|
|
return res.json();
|
||
|
|
}
|