I developed a LINE chatbot using Google Apps Script and encountered an issue while working with the rich menu. After generating three menus, I attempted to switch between them using richMenuSwitch. I am certain that the richMenuId was successfully created, but the aliasId fails to link to the existing rich menu, resulting in a "richmenu not found" error. Here is the error message:
Exception: Request failed for https://api.line.me returned code 400. Truncated server response: {"message":"richmenu not found","details":[]} (use muteHttpExceptions option to examine full response)
createRichMenuAlias @ setupRichMenu.gs:140
setupRichMenu @ setupRichMenu.gs:12
Below is the code I used to connect the aliasId to the rich menu:
function createRichMenuAlias(richMenuId, aliasId) {
let url = "https://api.line.me/v2/bot/richmenu/alias";
let aliasData = {
richMenuAliasId: aliasId,
richMenuId: richMenuId
};
let options = {
"method": "post",
"headers": { "Authorization": `Bearer ${CHANNEL_ACCESS_TOKEN}`, "Content-Type": "application/json" },
"payload": JSON.stringify(aliasData)
};
let response = UrlFetchApp.fetch(url, options);
console.log(`Alias ${aliasId} created for Rich Menu ID: ${richMenuId}`);
console.log(response.getContentText()); // 輸出目前所有的 Alias
}
I would really appreciate any insights on what might be causing this issue and how I can fix it. Thank you in advance!