尝试更新 BillingInfo 时获取 "The caller does not have permission"

Getting "The caller does not have permission" when trying to updateBillingInfo

我正在尝试以编程方式更新我的一个项目的结算帐户。我正在为 googleapis REST 使用节点客户端库。这是我的代码:

const { google } = require('googleapis');
const cloudbilling = google.cloudbilling('v1');
async function main() {
  let authClient;
  try {
    authClient = await authorize();
    console.log('AUTH', authClient);
  } catch (err) {
    console.error(err);
  }
  const request = {            
      name: "projects/rensi-28",   
      requestBody: {
        billingAccountName: "billingAccounts/My Billing Account" 
      }    
           
  };
  google.options({auth: authClient});
  try {
    const response = (await cloudbilling.projects.updateBillingInfo(request)).data;    
    console.log(JSON.stringify(response, null, 2));
  } catch (err) {
    console.error('error:', err);
  }
  
}
main();

async function authorize() {
  const auth = new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform']
  });
  return await auth.getClient();
}

这是我得到的错误:

errors: [
    {
      message: 'The caller does not have permission',
      domain: 'global',
      reason: 'forbidden'
    }
  ]

我正在使用服务帐户并且环境变量设置正确,因为我可以创建项目并使用其他 API。

我的服务帐户具有以下角色:

Level Role
Project Project Billing Manager
Project Owner
Organization Billing Account Administrator
Organization Billing Account Creator
Organization Project Billing Manager
Organization Billing Account Viewer
Organization Owner
Billing Account Billing Account Administrator
Billing Account Billing Account User
Billing Account Billing Account Viewer

如果使用相同的服务帐户从 gcloud 启用计费,它会起作用:

gcloud alpha billing projects link p001  --billing-account 45FG32-45FG32-45FG32
gcloud alpha billing projects link p001  --billing-account 45FG32-45FG32-45FG32
billingAccountName: billingAccounts/45FG32-45FG32-45FG32
billingEnabled: true
name: projects/p001/billingInfo
projectId: bxtrb-rensi-28

我错过了什么?

billingAccountName 的格式不正确。

使用格式 billingAccounts/45FG32-45FG32-45FG32.

参考:ProjectBillingInfo.

参数名称不清楚,尝试使用

项目ID而不是项目名称 而不是计费帐户名称使用计费帐户 id

const request = { 
      name: "projects/rensi-28",   // projectId
      requestBody: {
        billingAccountName: "billingAccounts/My Billing Account" //billingAcountId
      }    
           
  };