Skip to content

ReplaceRecord

ngocnicholas edited this page Mar 30, 2017 · 1 revision

AirtableBase.ReplaceRecord Method(string, Fields, string, bool)

Replace a record with a specific ID in a specific table using provided information as an asynchronous operation.

Namespace: AirtableApiClient

Assembly: AirtableApiClient.dll

Syntax

        public async Task<AirtableCreateUpdateReplaceRecordResponse> ReplaceRecord(
            string tableName,
            Fields fields,
            string id,
            bool typeCast = true)

Parameters

tableName

Type: string   
Name of the table where the record will be replaced with information provided by caller.

fields

Type: Fields

id

ID of the record to be replaced.

typeCast

Type: bool
Enable/Disable automatic data conversion. Default to 'true'.

Return Value

The task object representing the asynchronous operation.

Remarks

This operation will not block. The returned task object will complete once the entire response including content is read.

Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AirtableApiClient;

        readonly string baseId = YOUR_BASE_ID;
        readonly string appKey = YOUR_APP_KEY;  

        using (AirtableBase airtableBase = new AirtableBase(appKey, baseId))
        {
            var fields = new Fields();
            fields.AddField("Name", "Pablo Picasso Replaced");
            fields.AddField("On Display?", true);
            var attachment1 = new AirtableAttachment { Url = "https://upload.wikimedia.org/wikipedia/en/d/d1/Picasso_three_musicians_moma_2006.jpg" };
            var attachment2 = new AirtableAttachment { Url = "https://upload.wikimedia.org/wikipedia/en/thumb/6/6a/Pablo_Picasso%2C_1921%2C_Nous_autres_musiciens_%28Three_Musicians%29%2C_oil_on_canvas%2C_204.5_x_188.3_cm%2C_Philadelphia_Museum_of_Art.jpg/800px-Pablo_Picasso%2C_1921%2C_Nous_autres_musiciens_%28Three_Musicians%29%2C_oil_on_canvas%2C_204.5_x_188.3_cm%2C_Philadelphia_Museum_of_Art.jpg" };
            var attachmentList = new List<AirtableAttachment>();
            attachmentList.Add(attachment1);
            attachmentList.Add(attachment1);
            fields.AddField("Attachments", attachmentList);

            Task<AirtableCreateUpdateReplaceRecordResponse> task = airtableBase.ReplaceRecord(tableName, fields, ID_OF_RECORD_TO_BE_REPLACED);
            var response = await task;

            if (!response.Success)
            {
                string errorMessage = null;
                if (response.AirtableApiError is AirtableApiException)
                {
                    errorMessage = response.AirtableApiError.ErrorMessage;
                }
                else
                {
                    errorMessage = "Unknown error";
                }
                // Report errorMessage
            }
            else
            {
                var record = response.Record;
                // Do something with your replaced record.
            }
        }

Clone this wiki locally