export async function createAccountLink(
managerCustomerId,
clientCustomerId,
clientAccessToken
) {
// The payload for the POST request
const body = {
accountLink: {
status: "PENDING_APPROVAL",
},
};
try {
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${clientAccessToken}`, // Bearer token for the client account
"Developer-Token": process.env.GOOGLE_DEV_TOKEN, // Developer token for API access
"Content-Type": "application/json",
"login-customer-id": managerCustomerId, // Manager account ID
},
body: JSON.stringify(body), // Converting the payload to a JSON string
});
if (!response.ok) {
const responseText = await response.text();
console.error(
`Failed to create account link, status: ${response.status}, response: ${responseText}`
);
throw new Error(
`API call failed with status ${response.status}: ${responseText}`
);
}
const data = await response.json();
console.log("Created Account Link:", data);
return data;
} catch (error) {
console.error("Failed to create account link:", error);
throw error;
}
}