How to download attachments via API?
My code:
const fetch = require(‘node-fetch’);
async function addAttach(taskGid) {
try {
const attach = global.client.attachments.getAttachmentsForTask(taskGid, {opt_fields: "permanent_url"})
.then((result) => {
result.data.forEach((attach, name, index) => {
setTimeout(() => download(attach.permanent_url), 300 * index)})
});
} catch(e) {
console.log(`Error addattach ${e}`);
}
}
async function download(url) {
const response = await fetch(url);
const body = await response.body;
return body
}
Response is:
<html><head><meta name="window" content="{"clientVersion":"c11912c228842823219b21d1bd6eeddae8b87791","recaptchaV2SiteKey":"6LdkcuISAAAAAAbgBM_0ZV4dH2wVsq2Ck0jJRFdS","recaptchaEnterpriseSiteKey":"6Lf1FtQZAAAAAKGsW3JoCdtQfzfCb2umWbEoyOjE","releaseRevision":"20211123_221625_c11912c228842823219b21d1bd6eeddae8b87791","syncCluster":"prod","userAgent":"","loginConfig":{"targetUrl":"https://app.asana.com/app/asana/-/get_asset?asset_id=1201421973204556","signupUrl":"https://asana.com/create-account","configName":"prod","showSandLoginButtons":false,"error":null,"googleLastEmail":"","googleSsoRequirements":[],"samlTimeoutInfoIfLoginExpired":null,"recentSamlEmail":null,"recentSamlEmailDomain":null,"forceEmail":"","oauthActionUrl":"https://app.asana.com/-/oauth2callback","extraGoogleAuthTokens":[],"shareLinkKey":"","shareLinkDomainId":"","utm_campaign":"","utm_medium":"","utm_source":"","enableCaptchas":true,"showCaptchaCheckbox":false,"showCaptchaScore":true,"xsrfToken":"5cbade8f16d57d8de4abdbb169d0f701:1637762036518","autoDetectLogin":false,"translations":{"14vqnjf":[0,"Back"],"1jgonki":[0,"Asana logo"],"6c7p6e":[2,"This site is protected by reCAPTCHA and the Google <privacylink>Privacy Policy</privacylink> and <termslink>Terms of Service</termslink> apply."],"1qwtlnx":[0,"Log in with Google"],"1cymyzw":[0,"or"],"5rjrso":[0,"Don't have an account?"],"rs0iwj":[0,"Sign up"],"1pr4zrz":[0,"Email address"],"1p2cgqu":[0,"Password"],"xhq4e8":[0,"Please enter a valid email address."],"hem9g3":[0,"Forgot your password?"],"r8w892":[0,"Log in"],"ho39t5":[1,"{googleSsoName} requires you to use a Google account from the {domain} domain."],"1bf7ig9":[0,"You must use a Google account from one of the following domains:"],"z65pvl":[0,"Your account has been disabled. Please contact support@asana.com."],"aua64b":[0,"You can't log in to Asana as this service account."],"k6uh33":[0,"Oops! It looks like that login link has expired. Try logging in again to continue."],"14ezaf7":[0,"Sorry, that password reset link has expired and cannot be used for the safety of your account."],"1pwvtgo":[2,"You can get another one <a>here</a>."],"1d1r0o5":[0,"Sorry, that password reset link has already been used and cannot be used again for the safety of your account."],"1prxpic":[0,"Single sign-on (SSO) is not enabled for your account. Please log in with your email address and password below."],"mxktt9":[0,"Single sign-on (SAML) is not enabled for your account. To enable, please reach out to your admin. In the meantime, log in with your email address and password below."],"1an7k9h":[0,"Single sign-on (SAML) authentication failed. Please contact your domain administrator."],"13yklei":[0,"Single sign-on (SAML) authentication failed due to a certificate error. Please contact your domain administrator."],"10mp3lq":[0,"Google authentication failed. Please try again."],"k1z2fc":[1,"There isn't an Asana account associated with {email}."],"23eye4":[2,"<a>Sign Up</a>"],"5kueq5":[0,"Please fill out the challenge below."],"tbbnjv":[0,"Your response to the challenge was incorrect. Please try again."],"1t93f7g":[2,"You may be having trouble logging in due to your location, we apologize for the inconvenience. Please <a>contact us</a> if you require assistance."],"1ks84ig":[0,"A verification email has been sent to you. Please follow the instructions to log in."],"9jsgm8":[0,"Your password is invalid. Please use the Forgot your password link to reset it."],"gur3f3":[0,"An administrator in your Organization has reset your Asana password."],"1a45du7":[0,"Instructions to create a new password have been sent to the email associated with this account."],"l4btgw":[0,"That invitation has been canceled. Please ask to be re-invited."],"rsebx2":[0,"We believe that you're attempting to create a domain that is in violation of our Terms of Service. If you believe this is an error, please contact terms-questions@asana.com."],"k758tl":[0,"That invitation is invalid. Did you copy the full URL?"],"zet2c7":[0,"The username or password is not correct."],"a37mos":[2,"Did you <forget>forget your password?</forget>"],"5ydeav":[0,"Account belongs to multiple SSO-required domains."],"188ugn5":[0,"The code you entered is invalid. Please try again."],"1ksycox":[0,"You have attempted to enter your code too many times. Please try again later."],"9w28sf":[0,"Your password was successfully updated. Please log in."],"cvuqjc":[0,"An unexpected error occurred while updating your password. Please try again."],"uv4et9":[0,"You must be logged in to view this form"],"g709tu":[0,"An unexpected error occurred, and we couldn't log you in. Please try again in a few minutes."],"1szzfwx":[0,"Your administrator has disabled encryption keys and revoked Asana access. Please contact your administrator to restore access."],"s2xel2":[0,"Asana.com"],"1ush6q3":[0,"Support"],"squ6rv":[0,"Integrations"],"ak3oov":[0,"Forum"],"11s3qgw":[0,"Developers & API"],"1hkszeb":[0,"Resources"],"1gnsi5b":[0,"Guide"],"1yooo5n":[0,"Templates"],"hcswtb":[0,"Pricing"],"hnou9x":[0,"Terms"],"bfeasx":[0,"Privacy"],"1uwrwno":[0,"Confirm login"],"5h2oka":[1,"You are about to log in to Asana as {email}"],"1ocf51d":[0,"Log in with a different account"],"rhvlec":[1,"For your security, {domain} logs you out of Asana after {numberOfUnitsOfTime} {unitsOfTime}. Please log in again."],"15jcji0":[0,"minutes"],"3830xi":[0,"hours"],"yjc5xm":[0,"days"],"16hmvgm":[0,"seconds"],"wqm88m":[0,"Two-factor authentication is enabled"],"u27l2b":[0,"Continue to Asana"],"1twzobx":[0,"Each time you log in with your email and password, you will be required to enter an authentication code."],"1vvgnti":[0,"An organization you belong to requires two-factor authentication"],"1hlp135":[0,"Enable"],"ia0oya":[0,"Scan this QR code"],"ivekyp":[0,"Continue"],"1b5d4f4":[0,"Enter authentication code"],"18kj80t":[0,"This field can only contain numbers (e.g. 123456)"],"1gj9b8n":[1,"Open your authentication app. If you don't already have one, we recommend {duo}, {authy}, or {microsoftAuthenticator}."],"zm0nie":[0,"Twilio Authy"],"tte955":[0,"Duo"],"1wcv93q":[0,"Microsoft Authenticator"],"82rj3z":[0,"Enter the 6-digit code generated by your authentication app."],"1fczwp":[2,"<link>What's an authentication code?</link>"],"ps80su":[1,"Using the app, scan the QR code or manually enter the following code: {code}"]},"loginAppEmitGoogleTagManagerEvent":true,"loginAppUseEmailFirstLogin":false}}"/><script nonce="r5w8gay5pguxow5sz3ipjbvnv">
window_attrs = JSON.parse(document.querySelector('meta[name="window"]').content);
window.global = window;
window.client_version = window_attrs.clientVersion;
window.recaptcha_v2_site_key = window_attrs.recaptchaV2SiteKey;
window.recaptcha_enterprise_site_key = window_attrs.recaptchaEnterpriseSiteKey;
window.release_revision = window_attrs.releaseRevision;
window.sync_cluster = window_attrs.syncCluster;
window.user_agent = window_attrs.userAgent;
window.loginConfig = window_attrs.loginConfig;
</script><link rel="shortcut icon" href="https://d3ki9tyy5l5ruj.cloudfront.net/obj/df5bcec7e9873dddebdd1328901c287f0f069750/asana-logo-favicon@3x.png"/><link href="https://d3ki9tyy5l5ruj.cloudfront.net/build/bundles/c11912c228842823219b21d1bd6eeddae8b87791/login/login.css" rel="stylesheet"/><script src="https://d3ki9tyy5l5ruj.cloudfront.net/build/bundles/c11912c228842823219b21d1bd6eeddae8b87791/login/login_javascript_bundle.js" type="text/javascript" defer="" nonce="r5w8gay5pguxow5sz3ipjbvnv"></script><meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no"/><meta name="apple-mobile-web-app-capable" content="yes"/><meta name="apple-mobile-web-app-status-bar-style" content="black"/><link rel="apple-touch-icon-precomposed" href="https://d3ki9tyy5l5ruj.cloudfront.net/obj/a6b9e5cd80c49ace4d4d1863febef31615d6c227/icon.png"/><link rel="canonical" href="https://app.asana.com/-/login"/><style type="text/css">.grecaptcha-badge { visibility: hidden; }</style></head><body><div id="Login-appRoot"><title>Log in - Asana</title><div class="LoginCardLayout"><div class="LoginCardLayout-card--withCaptchaNotice LoginCardLayout-card"><div class="LoginCardLayout-backButtonContainer"></div><a class="LoginCardLayout-asanaLogoContainer PrimaryLink BaseLink" href="/-/login_page_log?se=%7B%22action%22%3A%22LinkClicked%22%2C%22sub_action%22%3A%22AsanaLogo%22%2C%22location%22%3A%22LoginPage%22%2C%22url%22%3A%22https%3A%2F%2Fasana.com%2F%22%2C%22name%22%3A%22LinkClicked%22%2C%22non_user_action_event%22%3Afalse%7D&allowed=login_page&dest=https%3A%2F%2Fasana.com%2F"><img class="LoginCardLayout-asanaLogo" src="https://d3ki9tyy5l5ruj.cloudfront.net/obj/6c76122a923c696febd26d2a843aa6daf960a3df/logo.png" alt="Asana logo"/></a><div class="LoginDefaultView-content"><div><!-- DEBUG-TAG: login --></div><div name="login" id="debug_page_load_marker"></div><div class="AbstractThemeableRectangularButton--isEnabled AbstractThemeableRectangularButton AbstractThemeableRectangularButton--xlarge SecondaryButton GoogleSignInButton--sparse GoogleSignInButton LoginDefaultView-ssoButton" role="button" tabindex="0"><svg class="AbstractThemeableRectangularButton-leftIcon GoogleSignInButton-logo--sparse GoogleSignInButton-logo" viewBox="0 0 18 18"><path d="M17.64,9.20454545 C17.64,8.56636364 17.5827273,7.95272727 17.4763636,7.36363636 L9,7.36363636 L9,10.845 L13.8436364,10.845 C13.635,11.97 13.0009091,12.9231818 12.0477273,13.5613636 L12.0477273,15.8195455 L14.9563636,15.8195455 C16.6581818,14.2527273 17.64,11.9454545 17.64,9.20454545 L17.64,9.20454545 Z" fill="#4285F4"></path><path d="M9,18 C11.43,18 13.4672727,17.1940909 14.9563636,15.8195455 L12.0477273,13.5613636 C11.2418182,14.1013636 10.2109091,14.4204545 9,14.4204545 C6.65590909,14.4204545 4.67181818,12.8372727 3.96409091,10.71 L0.957272727,10.71 L0.957272727,13.0418182 C2.43818182,15.9831818 5.48181818,18 9,18 L9,18 Z" fill="#34A853"></path><path d="M3.96409091,10.71 C3.78409091,10.17 3.68181818,9.59318182 3.68181818,9 C3.68181818,8.40681818 3.78409091,7.83 3.96409091,7.29 L3.96409091,4.95818182 L0.957272727,4.95818182 C0.347727273,6.17318182 0,7.54772727 0,9 C0,10.4522727 0.347727273,11.8268182 0.957272727,13.0418182 L3.96409091,10.71 L3.96409091,10.71 Z" fill="#FBBC05"></path><path d="M9,3.57954545 C10.3213636,3.57954545 11.5077273,4.03363636 12.4404545,4.92545455 L15.0218182,2.34409091 C13.4631818,0.891818182 11.4259091,0 9,0 C5.48181818,0 2.43818182,2.01681818 0.957272727,4.95818182 L3.96409091,7.29 C4.67181818,5.16272727 6.65590909,3.57954545 9,3.57954545 L9,3.57954545 Z" fill="#EA4335"></path></svg>Log in with Google</div><span class="SeparatorRow LoginDefaultView-separatorRow"><span class="SeparatorRow-horizontalLine"></span><span class="SeparatorRow-label LoginDefaultView-separatorRowLabel">or</span><span class="SeparatorRow-horizontalLine"></span></span><form class="LoginEmailPasswordForm"><div class="LoginEmailPasswordForm-emailAndPassword"><span class="Typography Typography--colorDarkGray1 Typography--s">Email address</span><div><div class="ValidatedInput"><input type="text" class="TextInputBase SizedTextInput SizedTextInput--medium TextInput LoginEmailPasswordForm-emailInput" name="e" value="" autoComplete="username" autofocus="" services="[object Object]"/></div></div><span class="LoginEmailPasswordForm-passwordText Typography Typography--colorDarkGray1 Typography--s">Password</span><div><div class="ValidatedInput"><input type="password" class="TextInputBase SizedTextInput SizedTextInput--medium TextInput LoginEmailPasswordForm-passwordInput" name="p" value="" autoComplete="current-password" services="[object Object]"/></div></div></div><a class="LoginEmailPasswordForm-forgotPassword SecondaryLink BaseLink" href="/-/login_page_log?se=%7B%22action%22%3A%22LinkClicked%22%2C%22sub_action%22%3A%22ForgotPassword%22%2C%22location%22%3A%22LoginPage%22%2C%22url%22%3A%22%2F-%2Fforgot_password%22%2C%22name%22%3A%22LinkClicked%22%2C%22non_user_action_event%22%3Afalse%7D&allowed=login_page&dest=%2F-%2Fforgot_password"><span class="Typography Typography--s">Forgot your password?</span></a><div class="AbstractThemeableRectangularButton--isEnabled AbstractThemeableRectangularButton AbstractThemeableRectangularButton--large NuxButton LoginEmailPasswordForm-logInButton" role="button" aria-disabled="false" tabindex="0">Log in</div></form><div class="LoginDefaultView-signUp"><div><!-- DEBUG-TAG: login-signup --></div><span class="Typography Typography--colorDarkGray1 Typography--m">Don't have an account?</span><a class="LoginDefaultView-signUpButtonLink PrimaryLink BaseLink" href="/-/login_page_log?se=%7B%22action%22%3A%22LinkClicked%22%2C%22sub_action%22%3A%22SignUp%22%2C%22location%22%3A%22LoginPage%22%2C%22url%22%3A%22https%3A%2F%2Fasana.com%2Fcreate-account%22%2C%22name%22%3A%22LinkClicked%22%2C%22non_user_action_event%22%3Afalse%7D&allowed=login_page&dest=https%3A%2F%2Fasana.com%2Fcreate-account">Sign up</a></div></div><span class="LoginCardLayout-captchaNotice Typography Typography--colorDarkGray1 Typography--s Typography--textAlignCenter">This site is protected by reCAPTCHA and the Google <a target="_blank" rel="noreferrer noopener" class="SecondaryLink BaseLink" href="https://policies.google.com/privacy">Privacy Policy</a> and <a target="_blank" rel="noreferrer noopener" class="SecondaryLink BaseLink" href="https://policies.google.com/terms">Terms of Service</a> apply.</span></div><div class="LoginFooter"><nav><ul class="LoginFooter-navRow"><li class="LoginFooter-navRowItem"><a class="HiddenLink HiddenLink--darkGray1 BaseLink" href="https://asana.com/"><span class="Typography Typography--m">Asana.com</span></a></li><li class="LoginFooter-navRowItem"><a class="HiddenLink HiddenLink--darkGray1 BaseLink" href="https://asana.com/support"><span class="Typography Typography--m">Support</span></a></li><li class="LoginFooter-navRowItem"><a class="HiddenLink HiddenLink--darkGray1 BaseLink" href="https://asana.com/apps"><span class="Typography Typography--m">Integrations</span></a></li><li class="LoginFooter-navRowItem"><a class="HiddenLink HiddenLink--darkGray1 BaseLink" href="https://forum.asana.com"><span class="Typography Typography--m">Forum</span></a></li><li class="LoginFooter-navRowItem"><a class="HiddenLink HiddenLink--darkGray1 BaseLink" href="https://developers.asana.com"><span class="Typography Typography--m">Developers & API</span></a></li></ul><ul class="LoginFooter-navRow"><li class="LoginFooter-navRowItem"><a class="HiddenLink HiddenLink--darkGray1 BaseLink" href="https://asana.com/resources"><span class="Typography Typography--m">Resources</span></a></li><li class="LoginFooter-navRowItem"><a class="HiddenLink HiddenLink--darkGray1 BaseLink" href="https://asana.com/guide"><span class="Typography Typography--m">Guide</span></a></li><li class="LoginFooter-navRowItem"><a class="HiddenLink HiddenLink--darkGray1 BaseLink" href="https://asana.com/templates"><span class="Typography Typography--m">Templates</span></a></li><li class="LoginFooter-navRowItem"><a class="HiddenLink HiddenLink--darkGray1 BaseLink" href="https://asana.com/pricing"><span class="Typography Typography--m">Pricing</span></a></li><li class="LoginFooter-navRowItem"><a class="HiddenLink HiddenLink--darkGray1 BaseLink" href="https://asana.com/terms"><span class="Typography Typography--m">Terms</span></a></li><li class="LoginFooter-navRowItem"><a class="HiddenLink HiddenLink--darkGray1 BaseLink" href="https://asana.com/terms#privacy-policy"><span class="Typography Typography--m">Privacy</span></a></li></ul></nav></div></div></div></body></html>