BudgetOrders(): como obter o saldo pré-pago restante? (Conta BR em pagamento manual)

24 views
Skip to first unread message

Felipe Soares BeeAds Configurações

unread,
Jun 8, 2025, 8:40:39 PM6/8/25
to Google Ads Scripts Forum
Olá, equipe do Google Ads Scripts!

Estou tentando capturar via Script o **saldo restante** (pré-pago) de uma conta brasileira que usa pagamentos manuais, para gravar o valor em uma planilha.

### Contexto
* Conta do cliente (CID): **572-050-9807**  
* Forma de pagamento: **manual / pré-pago (R$)**  
* Na UI o quadro “Fundos disponíveis” mostra **R$ 414,58** (print em anexo).  
* Objetivo: retornar exatamente esse número programaticamente via `AdsApp.budgetOrders()`.

### Código testado

```javascript
function getGooglePrepayBalance() {
  var total = 0;
  var it = AdsApp.budgetOrders().get();  // GA Scripts v2

  while (it.hasNext()) {
    var bo = it.next();

    // 1) campo 'novo' (quando existe)
    var ready = bo.getRemainingSpendableAmountMicros ?
                bo.getRemainingSpendableAmountMicros() : 0;
    if (ready) { total += ready / 1e6; continue; }

    // 2) cálculo clássico
    var limit  = bo.getSpendingLimitMicros      ? bo.getSpendingLimitMicros()      : 0;
    var spent  = bo.getApprovedSpendMicros      ? bo.getApprovedSpendMicros()      : 0;
    var adjust = bo.getTotalAdjustmentsMicros   ? bo.getTotalAdjustmentsMicros()   : 0;

    total += (limit + adjust - spent) / 1e6;
  }
  Logger.log('TOTAL R$ %s', total);
  return total;
}

Resultado obtido

TOTAL R$ 0 — sempre.
No log todos os BudgetOrders retornam zero (ou o campo “ready” não existe).

Erros adicionais
  • Ao tentar filtrar (withCondition("account_budget_status IN ('APPROVED','PENDING')"))
    recebo:
    QueryError.BAD_VALUE: Unrecognized field in the query: 'account_budget_status'.

  • A maioria dos objetos BudgetOrder não expõe getRemainingSpendableAmountMicros(), embora a documentação sugira que o campo exista para contas pré-pagas.

Dúvida

Há outro endpoint/relatório no Apps Script para ler o saldo pré-pago?
Qualquer exemplo funcional (Scripts v2) seria de grande ajuda.

Obrigado desde já!

— Felipe (BeeAds, Brasil)

yaml
CopiarEditar

Google Ads Scripts Forum Advisor

unread,
Jun 9, 2025, 12:52:50 AM6/9/25
to adwords...@googlegroups.com
Hi,

Thank you for reaching out to the Google Ads Scripts Support team.

I would like to inform you that the methods used in the script are not present under budget orders documentation. You can refer to the documentation for the available methods and sample examples under budget orders. Kindly share us the documentation link that you are referring to related to "getRemainingSpendableAmountMicros()" method. We don't see any script available under the given account "572-050-9807" to validate on the account budget status error that was reported. Kindly provide us with the exact script name and Google Ads Account ID/CID to check further. You can refer to the sample query on how the specific fields need to be formatted to fetch the data. You can also refer to the account budget query builder to add multiple fields as per your requirement.
SELECT account_budget.adjusted_spending_limit_micros FROM account_budget 
WHERE account_budget.status IN ('APPROVED', 'PENDING')
You can share the requested details via Reply privately to the author option or a direct private reply to this email.

Thanks,
 
Google Logo Google Ads Scripts Team

Feedback
How was our support today?

rating1    rating2    rating3    rating4    rating5
[2025-06-09 04:52:18Z GMT] This message is in relation to case "ref:!00D1U01174p.!500Ht01redAD:ref" (ADR-00311872)



Reply all
Reply to author
Forward
0 new messages