Last active
January 24, 2026 19:37
-
-
Save danperrout/b27197056fa38d0d669332647ab89d7a to your computer and use it in GitHub Desktop.
API Função TESOURODIRETO Google Sheets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * @return Acessa radaropcoes.com e retorna informações de um título específico do Tesouro Direto | |
| * Endpoint: https://api.radaropcoes.com/bonds/{bondName} | |
| */ | |
| function TESOURODIRETO(bondName, argumento = "r") { | |
| let srcURL = "https://api.radaropcoes.com/bonds/" + encodeURIComponent(bondName); | |
| let response = UrlFetchApp.fetch(srcURL, { | |
| muteHttpExceptions: true | |
| }); | |
| console.log(srcURL) | |
| if (response.getResponseCode() !== 200) { | |
| throw new Error("Erro ao acessar a API ou título não encontrado."); | |
| } | |
| let bond = JSON.parse(response.getContentText()); | |
| // argumento: | |
| // "r" → valor de resgate | |
| // qualquer outro → valor unitário de investimento | |
| if (argumento === "r") { | |
| return bond.unitaryRedemptionValue; | |
| } else { | |
| return bond.unitaryInvestmentValue; | |
| } | |
| } |
@andreluistosato agradeço por ter compartilhado seu conhecimento. Resolveu aqui. Vida longa a você.
Author
Tem algum lugar com mais instruções de como utilizar? O código, instruções de como puxar para o Google planilhas, etc? Obrigado! Sucesso!
Funcionou perfeitamente para mim, parabéns Daniel.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quão difícil é isso para alguém que não tem esse conhecimento técnico todo?
Eu estou frustrado com toda esse mudança do site do Tesouro Direto pois o script que eu usava funcionou muito bem por muitos anos.
Ficarei muito grato se puder me dar orientações ou referências para que eu consiga implementar isso na minha planilha.
Sei que estou pedindo muito e entenderei caso não consiga.
Muito obrigado por toda informação compartilhada até agora.