Download multiple attachments to local disk
Downloads all attachments for a parent (task, project, or project brief) to a folder. Specify the parent ID and the folder path; saved file names include the attachment ID and original file name. You can choose whether to overwrite existing files. For tasks, this includes inline images in the description; for projects, files in the Key resources section; for project briefs, inline files in the brief.
Standard SQL query example
This is the base query accepted by the connector. To execute it in SQL Server, you have to pass it to the Data Gateway via a Linked Server. See how to accomplish this using the examples below.
SELECT * FROM download_attachments
WITH (
ParentId='1206673375982078' --Id of Task , Project or ProjectBrief
, SaveFolder='c:\temp'
, OverwriteFile=1
)
Using OPENQUERY in SQL Server
SELECT * FROM OPENQUERY([LS_TO_ASANA_IN_GATEWAY], 'SELECT * FROM download_attachments
WITH (
ParentId=''1206673375982078'' --Id of Task , Project or ProjectBrief
, SaveFolder=''c:\temp''
, OverwriteFile=1
)')
Using EXEC in SQL Server (handling larger SQL text)
The major drawback of OPENQUERY is its inability to incorporate variables within SQL statements.
This often leads to the use of cumbersome dynamic SQL (with numerous ticks and escape characters).
Fortunately, starting with SQL 2005 and onwards, you can utilize the EXEC (your_sql) AT [LS_TO_ASANA_IN_GATEWAY] syntax.
DECLARE @MyQuery NVARCHAR(MAX) = 'SELECT * FROM download_attachments
WITH (
ParentId=''1206673375982078'' --Id of Task , Project or ProjectBrief
, SaveFolder=''c:\temp''
, OverwriteFile=1
)'
EXEC (@MyQuery) AT [LS_TO_ASANA_IN_GATEWAY]