public async Task <(bool, string)> PostAttachmentToRecord(string magazineCoverUrl, string table, string recordId) { AirtableAttachment attachment = new AirtableAttachment() { Url = magazineCoverUrl }; List <AirtableAttachment> attachmentList = new List <AirtableAttachment> { attachment }; using (AirtableBase airtableBase = new AirtableBase(ApiKey, BaseId)) { var fields = new Fields(); fields.AddField("Cover", attachmentList); var task = airtableBase.UpdateRecord(table, fields, recordId); var response = await task; if (response.Success) { return(true, null); } else if (response.AirtableApiError is AirtableApiException) { return(false, response.AirtableApiError.GetBaseException().Message); } else { return(false, "Unknown error"); } } }
public async Task <(bool, string, List <(string, string)>)> GetIdsAndAttachmentUrlsFromRecordsFilterByFormula(string table, string formula, List <string> fields) { (bool success, string errorMessage, List <AirtableRecord> records) = await FetchRecordsFilterByFormula(table, formula, fields); Console.WriteLine($"found {records.Count} records"); List <(string, string)> idsAndUrls = new List <(string, string)>(); foreach (AirtableRecord record in records) { JArray attachmentJson = (JArray)record.Fields["Cover"]; AirtableAttachment attach = JsonConvert.DeserializeObject <AirtableAttachment>(attachmentJson[0].ToString()); if (attach.Url != null) { Console.WriteLine($"{record.Id}: {attach.Url}"); idsAndUrls.Add((record.Id, attach.Url)); } else { Console.WriteLine($"Attachment for {record.Fields["Date"]} is null!"); } } return(success, errorMessage, idsAndUrls); }