A convenience class To help create a SmartsheetClient instance with the appropriate fields.

Thread Safety: This class is not thread safe since it's mutable, one builder instance is NOT expected To be used in multiple threads.

        private static void UseOAuthFlow()
        {
            OAuthFlow oauth = new OAuthFlowBuilder()
                     .SetClientId("1tziajulcsbqsswgy37")
                     .SetClientSecret("sxouqll7zluvzmact3")
                     .SetRedirectURL("https://www.google.com")
                     .Build();

            string url = oauth.NewAuthorizationURL
            (
                new Smartsheet.Api.OAuth.AccessScope[]
                {
                    Smartsheet.Api.OAuth.AccessScope.READ_SHEETS,
                    Smartsheet.Api.OAuth.AccessScope.WRITE_SHEETS,
                    Smartsheet.Api.OAuth.AccessScope.SHARE_SHEETS,
                    Smartsheet.Api.OAuth.AccessScope.DELETE_SHEETS,
                    Smartsheet.Api.OAuth.AccessScope.CREATE_SHEETS,
                    Smartsheet.Api.OAuth.AccessScope.READ_USERS,
                    Smartsheet.Api.OAuth.AccessScope.ADMIN_USERS,
                    Smartsheet.Api.OAuth.AccessScope.ADMIN_SHEETS,
                    Smartsheet.Api.OAuth.AccessScope.ADMIN_WORKSPACES,
                },
                "key=Test"
            );

            // Take the user to the following URL
            Debug.WriteLine(url);

            // After the user accepts or declines the authorization they are taken to the redirect URL. The URL of the page
            // the user is taken to can be used to generate an authorization RequestResult object.
            string authorizationResponseURL = "https://www.google.com/?code=yn8kl1kvruh31uj&expires_in=599957&state=key%3DTest";

            // On this page pass in the full URL of the page to create an authorizationResult object
            AuthorizationResult authResult = oauth.ExtractAuthorizationResult(authorizationResponseURL);

            // Get the token from the authorization result
            Token token = oauth.ObtainNewToken(authResult);

            Assert.IsTrue(token.AccessToken == "ACCESS_TOKEN");

            Token tokenRefreshed = oauth.RefreshToken(token);
            Assert.IsTrue(token.AccessToken != "ACCESS_TOKEN");

            oauth.RevokeToken(token);
            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(token.AccessToken).Build();
            try
            {
                smartsheet.SheetResources.ListSheets(null, null);
                Assert.Fail();
            }
            catch
            {

            }
        }
        public void TestSheetCopyResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();
            // Before
            // Sheet
            // Folder

            // After
            // Sheet
            // Folder-----SheetCopy
            long folderId = CreateFolderInHome(smartsheet, "Folder1");

            long sheetId = CreateSheet(smartsheet);

            ContainerDestination destination = new ContainerDestination
            {
                DestinationId = folderId,
                DestinationType = DestinationType.FOLDER,
                NewName = "SheetCopy"
            };
            Sheet newCopiedSheet = smartsheet.SheetResources.CopySheet(sheetId, destination, new SheetCopyInclusion[] { SheetCopyInclusion.ALL });

            Assert.IsTrue(newCopiedSheet.Name == "SheetCopy");

            long copiedSheetId = newCopiedSheet.Id.Value;

            Sheet copiedSheet = smartsheet.SheetResources.GetSheet(copiedSheetId, null, null, null, null, null, null, null);
            Assert.IsTrue(copiedSheet.Name == "SheetCopy");

            DeleteFolders(smartsheet, folderId);
            smartsheet.SheetResources.DeleteSheet(sheetId);
        }
        public void TestSheetMoveResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();
            // Before
            // Sheet
            // Folder

            // After
            //
            // Folder-----SheetCopy
            long folderId = CreateFolderInHome(smartsheet, "Folder1");

            long sheetId = CreateSheet(smartsheet);

            ContainerDestination destination = new ContainerDestination
            {
                DestinationId = folderId,
                DestinationType = DestinationType.FOLDER,
                //NewName = "hello"
            };
            Sheet newMovedSheet = smartsheet.SheetResources.MoveSheet(sheetId, destination);

            Assert.IsTrue(newMovedSheet.Name == "new sheet");

            long movedSheetId = newMovedSheet.Id.Value;

            Sheet movedSheet = smartsheet.SheetResources.GetSheet(movedSheetId, null, null, null, null, null, null, null);
            Assert.IsTrue(movedSheet.Name == "new sheet");

            //Deleting the folder will also delete the sheet.
            DeleteFolders(smartsheet, folderId);
        }
        public void TestFolderCopyResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();
            // Before
            // Folder1-----SubFolder1
            // Folder2

            // After
            // Folder1-----SubFolder1
            // Folder2-----SubFolder1Copy
            long createdFolderInHomeId1 = CreateFolderInHome(smartsheet, "Folder1");
            long createdFolderInHomeId2 = CreateFolderInHome(smartsheet, "Folder2");

            long createdFolderInFolderId = CreateFolderInFolder(smartsheet, createdFolderInHomeId1, "SubFolder1");

            ContainerDestination destination = new ContainerDestination
            {
                DestinationId = createdFolderInHomeId2,
                DestinationType = DestinationType.FOLDER,
                NewName = "SubFolder1Copy"
            };
            Folder newCopiedFolder = smartsheet.FolderResources.CopyFolder(createdFolderInFolderId, destination, new FolderCopyInclusion[] { FolderCopyInclusion.ALL }, new FolderRemapExclusion[] { FolderRemapExclusion.CELL_LINKS });

            Assert.IsTrue(newCopiedFolder.Name == "SubFolder1Copy");

            long copiedFolderId = newCopiedFolder.Id.Value;

            Folder copiedFolder = smartsheet.FolderResources.GetFolder(copiedFolderId, null);
            Assert.IsTrue(copiedFolder.Name == "SubFolder1Copy");

            DeleteFolders(smartsheet, createdFolderInHomeId1, createdFolderInHomeId2);
        }
        public void TestAttachmentResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();
            long sheetId = CreateSheet(smartsheet);

            long discussionId = AttachFileAndUrlToComment(smartsheet, sheetId);

            ListDiscussionAttachments(smartsheet, sheetId, discussionId);

            long rowId = AttachFileAndUrlToRow(smartsheet, sheetId);

            ListRowAttachments(smartsheet, sheetId, rowId);

            long attachmentId = AttachFileAndUrlToSheet(smartsheet, sheetId);

            GetAttachment(smartsheet, sheetId, attachmentId);

            AttachNewVersion(smartsheet, sheetId, attachmentId);

            ListAttachmentVersions(smartsheet, sheetId, attachmentId);

            DeleteAttachment(smartsheet, sheetId, attachmentId);

            smartsheet.SheetResources.DeleteSheet(sheetId);
        }
        public void TestContactResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            PaginatedResult<Contact> contactResults = smartsheet.ContactResources.ListContacts(null);
            Assert.IsTrue(contactResults.TotalCount >= 0);
        }
        public void TestHomeResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            Home home = smartsheet.HomeResources.GetHome(new HomeInclusion[] { HomeInclusion.SOURCE });

            Assert.IsTrue(home != null);
        }
        public void TestServerInfoResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            ServerInfo info = smartsheet.ServerInfoResources.GetServerInfo();
            Assert.IsTrue(info.FeatureInfo != null);
            Assert.IsTrue(info.Formats != null);
            Assert.IsTrue(info.SupportedLocales != null);
        }
        public void TestColumnResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();
            long sheetId = CreateSheet(smartsheet);
            AddColumns(smartsheet, sheetId);

            long columnId = ListColumns(smartsheet, sheetId);
            UpdateColumn(smartsheet, sheetId, columnId);
            DeleteAndGetColumn(smartsheet, sheetId, columnId);
        }
        public void TestSheetResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();
            long sheetId = CreateSheet(smartsheet);
            SendSheet(smartsheet, sheetId);
            UpdateSheet(smartsheet, sheetId);
            UpdatePublishSheetStatus(smartsheet, sheetId);
            GetSheetAsPDF(smartsheet, sheetId);
            DeleteSheet(smartsheet, sheetId);
        }
        public void TestFolderResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            long createdFolderInHomeId = CreateFolderInHome(smartsheet);
            long createdFolderInFolderId = CreateFolderInFolder(smartsheet, createdFolderInHomeId);
            ListFoldersInFolder(smartsheet, createdFolderInHomeId, createdFolderInFolderId);
            UpdateFolderInFolder(smartsheet, createdFolderInFolderId);
            GetFolderInHome(smartsheet, createdFolderInHomeId, createdFolderInFolderId);
            DeleteFolders(smartsheet, createdFolderInHomeId, createdFolderInFolderId);
        }
        public void TestSearchingResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            string query = GenerateRandomQuery();

            long sheetId = CreateSheet(smartsheet);
            AddValuesToSheet(smartsheet, sheetId, query);
            System.Threading.Thread.Sleep(5000);
            SearchEverywhere(smartsheet, query, sheetId);

            SearchSheet(smartsheet, query, sheetId);
        }
        public void TestWorkspaceResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            long workspaceId = CreateWorkspace(smartsheet);

            UpdateWorkspace(smartsheet, workspaceId);

            GetWorkspace(smartsheet, workspaceId);

            ListWorkspaces(smartsheet, workspaceId);

            DeleteWorkspace(smartsheet, workspaceId);
        }
        public void TestGroupResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            long groupId = CreateGroup(smartsheet);

            UpdateGroup(smartsheet, groupId);

            AddGroupMember(smartsheet, groupId);

            GetGroup(smartsheet, groupId);

            ListGroups(smartsheet);

            DeleteGroup(smartsheet, groupId);
        }
        public void TestCellResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build(); long sheetId = CreateSheet(smartsheet);

            PaginatedResult<Column> columnsResult = smartsheet.SheetResources.ColumnResources.ListColumns(sheetId, null, null);
            long columnId = columnsResult.Data[0].Id.Value;

            Cell[] cellsToAdd = new Cell[] { new Cell.AddCellBuilder(columnId, true).SetValue("hello").SetStrict(false).Build() };

            long rowId = AddRows(smartsheet, sheetId, columnId, cellsToAdd);

            PaginatedResult<CellHistory> histories = smartsheet.SheetResources.RowResources.CellResources.GetCellHistory(sheetId, rowId, columnId, new CellInclusion[] { CellInclusion.COLUMN_TYPE }, null);
            Assert.IsTrue(histories.Data[0].ColumnType == ColumnType.TEXT_NUMBER);
            Assert.IsTrue(histories.Data.Count == 1);
            Assert.IsTrue(histories.Data[0].ColumnId == columnId);
        }
        public void TestFavoriteResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            RemoveAllFavoritesBeforeRunningTest(smartsheet);

            long sheetId;
            long folderId;
            //long reportId;
            //long templateId;
            long workspaceId;

            AddFavorites(smartsheet, out sheetId, out folderId, out workspaceId);

            RemoveAndListFavorites(smartsheet, sheetId, folderId, workspaceId);
        }
        public void TestCommentResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            long sheetId = CreateSheet(smartsheet);

            long discussionId = CreateDiscussion(smartsheet, sheetId);

            AddCommentWithoutAttachment(smartsheet, sheetId, discussionId);

            long commentId = AddCommentWithAttachment(smartsheet, sheetId, discussionId);

            GetComment(smartsheet, sheetId, commentId);

            DeleteComment(smartsheet, sheetId, commentId);

            smartsheet.SheetResources.DeleteSheet(sheetId);
        }
        public void TestRowResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            long templateId = smartsheet.TemplateResources.ListPublicTemplates(null).Data[0].Id.Value;
            long sheetId = CreateSheetFromTemplate(smartsheet, templateId);

            PaginatedResult<Column> columnsResult = smartsheet.SheetResources.ColumnResources.ListColumns(sheetId, null, null);
            long columnId = columnsResult.Data[0].Id.Value;

            Cell[] cellsToAdd = new Cell[] { new Cell.AddCellBuilder(columnId, true).SetValue("hello").SetStrict(false).Build() };

            long rowId = AddRows(smartsheet, sheetId, columnId, cellsToAdd);

            CopyRowToCreatedSheet(smartsheet, sheetId, rowId);

            SendRows(smartsheet, sheetId, columnId, rowId);

            DeleteRowAndGetRow(smartsheet, sheetId, rowId);
        }
        public void TestDiscussionResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build(); long sheetId = CreateSheet(smartsheet);

            Discussion discussionToCreate = new Discussion.CreateDiscussionBuilder("A discussion", new Comment.AddCommentBuilder("a comment").Build()).Build();
            Discussion createdDiscussion = smartsheet.SheetResources.DiscussionResources.CreateDiscussion(sheetId, discussionToCreate);
            long createdDiscussionId = createdDiscussion.Id.Value;
            string path = "../../../IntegrationTestSDK/TestFile.txt";
            Discussion createdDiscussionWithFile = smartsheet.SheetResources.DiscussionResources.CreateDiscussionWithAttachment(sheetId, discussionToCreate, path, null);
            Assert.IsTrue(createdDiscussionWithFile.Comments[0].Attachments[0].Name == "TestFile.txt");

            PaginatedResult<Discussion> discussions = smartsheet.SheetResources.DiscussionResources.ListDiscussions(sheetId, new DiscussionInclusion[] { DiscussionInclusion.COMMENTS, DiscussionInclusion.ATTACHMENTS }, null);
            Assert.IsTrue(discussions.TotalCount == 2);
            Assert.IsTrue(discussions.Data.Count == 2);
            Assert.IsTrue(discussions.Data[0].Id.Value == createdDiscussion.Id.Value || discussions.Data[0].Id.Value == createdDiscussionWithFile.Id.Value);
            Assert.IsTrue(discussions.Data[1].Id.Value == createdDiscussion.Id.Value || discussions.Data[1].Id.Value == createdDiscussionWithFile.Id.Value);

            Discussion getDiscussionWithFile = smartsheet.SheetResources.DiscussionResources.GetDiscussion(sheetId, createdDiscussionWithFile.Id.Value);
            Assert.IsTrue(getDiscussionWithFile.Title == "A discussion");
            Assert.IsTrue(getDiscussionWithFile.Comments.Count == 1);
            Assert.IsTrue(getDiscussionWithFile.Comments[0].Attachments.Count == 1);
            Assert.IsTrue(getDiscussionWithFile.Comments[0].Attachments[0].Name == "TestFile.txt");

            Row row = new Row.AddRowBuilder(true, null, null, null, null).Build();
            IList<Row> rows = smartsheet.SheetResources.RowResources.AddRows(sheetId, new Row[] { row });
            Assert.IsTrue(rows.Count == 1);
            Assert.IsTrue(rows[0].Id.HasValue);
            long rowId = rows[0].Id.Value;
            Comment comment = new Comment.AddCommentBuilder("a comment!").Build();
            Discussion discussionToCreateOnRow = new Discussion.CreateDiscussionBuilder("discussion on row", comment).Build();
            Discussion discussionCreatedOnRow = smartsheet.SheetResources.RowResources.DiscussionResources.CreateDiscussionWithAttachment(sheetId, rowId, discussionToCreateOnRow, path, null);
            PaginatedResult<Discussion> discussionsOnRow = smartsheet.SheetResources.RowResources.DiscussionResources
            .ListDiscussions(sheetId, rowId, new DiscussionInclusion[] { DiscussionInclusion.COMMENTS }, null);
            Assert.IsTrue(discussionsOnRow.Data.Count == 1);
            Assert.IsTrue(discussionsOnRow.Data[0].Title == "discussion on row");
            Assert.IsTrue(discussionsOnRow.Data[0].Comments[0].Text == "discussion on row\n\na comment!");
        }
        public void TestSheetUpdateRequestResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            long sheetId = CreateSheet(smartsheet);

            PaginatedResult<Column> columnsResult = smartsheet.SheetResources.ColumnResources.ListColumns(sheetId, null, null);
            long columnId = columnsResult.Data[0].Id.Value;

            Cell[] cellsToAdd = new Cell[] { new Cell.AddCellBuilder(columnId, true).SetValue("hello").SetStrict(false).Build() };

            IList<long> rowIds = AddRows(smartsheet, sheetId, columnId, cellsToAdd);

            UpdateRequest updateReq = new UpdateRequest
            {
                RowIds = rowIds,
                IncludeAttachments = true,
                IncludeDiscussions = true,
                CcMe = true,
                SendTo = new Recipient[]
                {
                    new Recipient
                    {
                        Email = "*****@*****.**"
                    }
                },
                Subject = "hello",
                Message = "tada"
            };
            UpdateRequest updateRequest = smartsheet.SheetResources.UpdateRequestResources.CreateUpdateRequest(sheetId, updateReq);

            Assert.IsNotNull(updateRequest.Id);

            Sheet a = smartsheet.SheetResources.GetSheet(sheetId, new SheetLevelInclusion[] { SheetLevelInclusion.ROW_PERMALINK }, null, null, null, null, null, null);

            smartsheet.SheetResources.DeleteSheet(sheetId);
        }
        public void TestRowDeleteSendResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            long templateId = smartsheet.TemplateResources.ListPublicTemplates(null).Data[0].Id.Value;

            long sheetId = CreateSheetFromTemplate(smartsheet, templateId);

            PaginatedResult<Column> columnsResult = smartsheet.SheetResources.ColumnResources.ListColumns(sheetId, null, null);
            long columnId = columnsResult.Data[0].Id.Value;

            Cell[] cellsToAdd = new Cell[] { new Cell.AddCellBuilder(columnId, true).SetValue("hello").SetStrict(false).Build() };

            IList<long> rowIds = AddRows(smartsheet, sheetId, columnId, cellsToAdd);

            MultiRowEmail multiEmail = new MultiRowEmail
            {
                RowIds = rowIds,
                IncludeAttachments = true,
                IncludeDiscussions = true,
                SendTo = new Recipient[]
                {
                    new Recipient
                    {
                        Email = "*****@*****.**"
                    }
                },
                Subject = "hello",
                Message = "tada"
            };
            smartsheet.SheetResources.RowResources.SendRows(sheetId, multiEmail);

            DeleteRows(smartsheet, sheetId, rowIds);

            smartsheet.SheetResources.DeleteSheet(sheetId);
        }
        public void TestFolderMoveResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();
            // Before
            // Folder1-----SubFolder1
            // Folder2

            // After
            // Folder1
            // Folder2-----SubFolder1
            long createdFolderInHomeId1 = CreateFolderInHome(smartsheet, "Folder1");
            long createdFolderInHomeId2 = CreateFolderInHome(smartsheet, "Folder2");

            long createdFolderInFolderId = CreateFolderInFolder(smartsheet, createdFolderInHomeId1, "SubFolder1");

            ContainerDestination destination = new ContainerDestination
            {
                DestinationId = createdFolderInHomeId2,
                DestinationType = DestinationType.FOLDER,
                //NewName = "NotSupported"
            };
            Folder newMovedFolder = smartsheet.FolderResources.MoveFolder(createdFolderInFolderId, destination);

            Assert.IsTrue(newMovedFolder.Name == "SubFolder1");

            long movedFolderId = newMovedFolder.Id.Value;

            Folder movedFolder = smartsheet.FolderResources.GetFolder(movedFolderId, null);
            Assert.IsTrue(movedFolder.Name == "SubFolder1");

            // Assert the Folder which use to contain the moved Folder is now empty.
            PaginatedResult<Folder> foldersResult = smartsheet.FolderResources.ListFolders(createdFolderInHomeId1, null);
            Assert.IsTrue(foldersResult.Data.Count == 0);

            DeleteFolders(smartsheet, createdFolderInHomeId1, createdFolderInHomeId2);
        }
        public void TestWorkspaceCopyResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();
            // Before
            // Workspace1
            // Folder2

            // After
            // Workspace1
            // Folder2-----Workspace1Copy

            Workspace workspace = smartsheet.WorkspaceResources.CreateWorkspace(new Workspace.CreateWorkspaceBuilder("Workspace1").Build());
            long workspaceId = workspace.Id.Value;

            long createdFolderInHomeId2 = CreateFolderInHome(smartsheet, "Folder2");

            ContainerDestination destination = new ContainerDestination
            {
                //DestinationId = createdFolderInHomeId2,
                //DestinationType = DestinationType.FOLDER,
                NewName = "Workspace1Copy"
            };
            Folder newCopiedWorkspace = smartsheet.WorkspaceResources.CopyWorkspace(workspaceId, destination, new WorkspaceCopyInclusion[] { WorkspaceCopyInclusion.ALL }, new WorkspaceRemapExclusion[] { WorkspaceRemapExclusion.CELL_LINKS });

            Assert.IsTrue(newCopiedWorkspace.Name == "Workspace1Copy");

            long copiedWorkspaceId = newCopiedWorkspace.Id.Value;

            Workspace copiedWorkspace = smartsheet.WorkspaceResources.GetWorkspace(copiedWorkspaceId, null, null);
            Assert.IsTrue(copiedWorkspace.Name == "Workspace1Copy");

            DeleteFolders(smartsheet, createdFolderInHomeId2);
            smartsheet.WorkspaceResources.DeleteWorkspace(workspaceId);
        }
        public void TestShareResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();

            long sheetId = CreateSheet(smartsheet);
            //long reportId = CreateReport(smartsheet);
            long workspaceId = CreateWorkspace(smartsheet);

            Share share = new Share.CreateShareBuilder("*****@*****.**", AccessLevel.EDITOR).Build();
            //string reportShareId = ShareReport(smartsheet, reportId, share);
            string sheetShareId = ShareSheet(smartsheet, sheetId, share);
            string workspaceShareId = ShareWorkspace(smartsheet, workspaceId, share);

            UpdateObjectShares(smartsheet, sheetId, workspaceId, sheetShareId, workspaceShareId);

            //ListReportShares(smartsheet, reportId);
            ListSheetShares(smartsheet, sheetId);
            ListWorkspaceShares(smartsheet, workspaceId);

            smartsheet.SheetResources.DeleteSheet(sheetId);
            smartsheet.WorkspaceResources.DeleteWorkspace(workspaceId);
        }
        public static void SampleCode()
        {
            // Set the Access Token
            Token token = new Token();
            token.AccessToken = "YOUR_TOKEN";

            // Use the Smartsheet Builder to create a Smartsheet
            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(token.AccessToken).Build();

            #pragma warning disable 0162
            if (false)
            {
                // List all contents (specify 'include' parameter with value of "source").
                Home home = smartsheet.HomeResources.GetHome(new HomeInclusion[] { HomeInclusion.SOURCE });

                // List folders in "Sheets" folder (specify 'includeAll' parameter with value of "true").
                IList<Folder> homeFolders = home.Folders;
                foreach (Folder tmpFolder in homeFolders)
                {
                    Console.WriteLine("folder:" + tmpFolder.Name);
                }

                // List sheets (omit 'include' parameter and pagination parameters).
                PaginatedResult<Sheet> homeSheetsResult = smartsheet.SheetResources.ListSheets(null, null);
                foreach (Sheet tmpSheet in homeSheetsResult.Data)
                {
                    Console.WriteLine("sheet:" + tmpSheet.Name);
                }

                // Create folder in home
                Folder folder = new Folder.CreateFolderBuilder("New Folder").Build();
                folder = smartsheet.HomeResources.FolderResources.CreateFolder(folder);
                Console.WriteLine("Folder ID:" + folder.Id + ", Folder Name:" + folder.Name);
                //=========================================
            }

            // Setup text Column Object
            Column textColumn = new Column.CreateSheetColumnBuilder("To Do List", true, ColumnType.TEXT_NUMBER).Build();

            // Setup checkbox Column Object
            Column checkboxColumn = new Column.CreateSheetColumnBuilder("Finished", false, ColumnType.CHECKBOX).Build();

            // Add the 2 Columns (flag & text) to a new Sheet Object
            Sheet sheet = new Sheet.CreateSheetBuilder("New Sheet", new Column[] { textColumn, checkboxColumn }).Build();
            // Send the request to create the sheet @ Smartsheet
            sheet = smartsheet.SheetResources.CreateSheet(sheet);
            //=========================================
            // Example: Add two rows
            Func<string, Row> addRowHelper = primaryColVal =>
            {
                var cells = new Cell[] { new Cell.AddCellBuilder(sheet.GetColumnByIndex(0).Id, primaryColVal).Build() };
                var rows = new Row[] { new Row.AddRowBuilder(true, null, null, null, null).SetCells(cells).Build() };
                return smartsheet.SheetResources.RowResources.AddRows(sheet.Id.Value, rows)[0];
            };

            var rowA = addRowHelper("a");
            var rowB = addRowHelper("b");

            // Example: Move rowB above rowA
            var updateRowRequest = new Row.UpdateRowBuilder(rowB.Id)
                    .SetSiblingId(rowA.Id)
                    .SetAbove(true)
                    .Build();
            var updateRowResponse = smartsheet.SheetResources.RowResources.UpdateRows(sheet.Id.Value, new Row[] { updateRowRequest });

            //Indent rowA under rowB
            updateRowRequest = new Row.UpdateRowBuilder(rowA.Id)
                    .SetParentId(rowB.Id)
                    .Build();
            updateRowResponse = smartsheet.SheetResources.RowResources.UpdateRows(sheet.Id.Value, new Row[] { updateRowRequest });

            //=========================================
            // Example: Add two rows
            PaginatedResult<Sheet> sheetsSince = smartsheet.SheetResources.ListSheets(null, null, DateTime.UtcNow.AddDays(-5));

            PaginatedResult<Sheet> orgSheetsSince = smartsheet.UserResources.SheetResources.ListOrgSheets(null, DateTime.UtcNow.AddDays(-10));

            PaginatedResult<Report> reportsSince = smartsheet.ReportResources.ListReports(null, DateTime.UtcNow.AddDays(-5));

            PaginatedResult<Sight> sightsSince = smartsheet.SightResources.ListSights(null, DateTime.Now.AddDays(-5));

            //=========================================
            // Example: setup a webhook
            Webhook webhook = new Webhook();
            webhook.Name = "Test webhook";
            webhook.CallbackUrl = "https://someurl.com";
            webhook.Scope = "sheet";
            webhook.ScopeObjectId = 6810644029695876L;
            IList<string> events = new List<string>();
            events.Add("*.*");
            webhook.Events = events;
            webhook.Version = 1;
            webhook = smartsheet.WebhookResources.CreateWebhook(webhook);

            PaginatedResult<Webhook> webhooks = smartsheet.WebhookResources.ListWebhooks(null);

            //// Update the shared secret
            webhook = smartsheet.WebhookResources.GetWebhook(webhooks.Data[0].Id.Value);

            Webhook update_webhook = new Webhook();
            update_webhook.Enabled = true;
            update_webhook.Id = webhooks.Data[0].Id;
            update_webhook = smartsheet.WebhookResources.UpdateWebhook(update_webhook);

            WebhookSharedSecret shared = smartsheet.WebhookResources.ResetSharedSecret(update_webhook.Id.Value);

            smartsheet.WebhookResources.DeleteWebhook(update_webhook.Id.Value);

            //=========================================
            // Example: sights example
            PaginatedResult<Sight> sights = smartsheet.SightResources.ListSights(null);

            if (sights.TotalCount > 0)
            {
                Sight sight = smartsheet.SightResources.GetSight(sights.Data[0].Id.Value);

                ContainerDestination dest = new ContainerDestination();
                dest.DestinationType = DestinationType.FOLDER;
                dest.DestinationId = 3167806247200644L;
                dest.NewName = "My New Sight";

                sight = smartsheet.SightResources.CopySight(sights.Data[0].Id.Value, dest);

                Sight newsight = new Sight();
                newsight.Id = sight.Id;
                newsight.Name = "My New New Sight";
                smartsheet.SightResources.UpdateSight(newsight);

                ContainerDestination destToo = new ContainerDestination();
                destToo.DestinationType = DestinationType.FOLDER;
                destToo.DestinationId = 3110683182163844L;
                sight = smartsheet.SightResources.MoveSight(sight.Id.Value, destToo);

                smartsheet.SightResources.DeleteSight(sight.Id.Value);

                PaginatedResult<Share> sightShares = smartsheet.SightResources.ShareResources.ListShares(sights.Data[0].Id.Value, null, ShareScope.Workspace);
            }

            //=========================================
            // Example: cell images and partial success
            Sheet imageSheet = smartsheet.SheetResources.GetSheet(6810644029695876L, null, null, null, null, null, null, null);

            Cell[] cellsA = new Cell[] { new Cell.AddCellBuilder(imageSheet.Columns[0].Id.Value, true).Build(), new Cell.AddCellBuilder(imageSheet.Columns[1].Id.Value, "Foobar").Build() };
            rowA = new Row.AddRowBuilder(true, null, null, null, null).SetCells(cellsA).Build();

            Cell[] cellsB = new Cell[] { new Cell.AddCellBuilder(imageSheet.Columns[1].Id.Value, true).Build(), new Cell.AddCellBuilder(imageSheet.Columns[1].Id.Value, "Barfoo").Build() };
            rowB = new Row.AddRowBuilder(true, null, null, null, null).SetCells(cellsB).Build();

            BulkItemRowResult bulkAddResult = smartsheet.SheetResources.RowResources.AddRowsAllowPartialSuccess(6810644029695876L, new Row[] { rowA, rowB });

            Cell[] cellsC = new Cell[] { new Cell.AddCellBuilder(imageSheet.Columns[0].Id.Value, true).Build(), new Cell.AddCellBuilder(imageSheet.Columns[1].Id.Value, "FoobarII").Build() };
            Row rowC = new Row.UpdateRowBuilder(imageSheet.Rows[2].Id.Value).SetCells(cellsC).Build();

            Cell[] cellsD = new Cell[] { new Cell.AddCellBuilder(imageSheet.Columns[1].Id.Value, true).Build(), new Cell.AddCellBuilder(imageSheet.Columns[1].Id.Value, "BarfooII").Build() };
            Row rowD = new Row.UpdateRowBuilder(imageSheet.Rows[1].Id.Value).SetCells(cellsD).Build();

            BulkItemRowResult bulkUpdateResult = smartsheet.SheetResources.RowResources.UpdateRowsAllowPartialSuccess(6810644029695876L, new Row[] { rowC, rowD });

            ImageUrl imageUrl = new ImageUrl.ImageUrlBuilder("aVbWbXMsD5KsOu2 - CWtwSA").Build();
            IList<ImageUrl> imageUrls = new List<ImageUrl>();
            imageUrls.Add(imageUrl);

            ImageUrlMap imageUrlMap = smartsheet.ImageUrlResources.GetImageUrls(imageUrls);

            smartsheet.SheetResources.RowResources.CellResources.AddImageToCell(6810644029695876L, imageSheet.Rows[0].Id.Value, imageSheet.Columns[1].Id.Value,
                "d:\\Smartsheet\\vHepGiJaeL6GPOX3wAx8yaxD75ym5eAbk0GB-MSz0gc.png", "image/png");

            //=========================================
            //// Update two cells on a row
            //IList<Cell> cells = new Cell.UpdateRowCellsBuilder().AddCell(5111621270955908L, "test11", false).
            //		AddCell(2859821457270660L, "test22").Build();
            //smartsheet.Rows().UpdateCells(6497447011739524L, cells);
            ////=========================================

            //// Create a row and sheet level discussion with an initial comment
            //Comment comment = new Comment.AddCommentBuilder().SetText("Hello World").Build();
            //Discussion discussion = new Discussion.CreateDiscussionBuilder().SetTitle("New Discussion").
            //	SetComment(comment).Build();
            //smartsheet.Rows().Discussions().CreateDiscussion(6497447011739524L, discussion);
            //smartsheet.Sheets().Discussions().CreateDiscussion(7370846613333892L, discussion);
            ////=========================================

            //// Update a folder name
            //folder = new Folder.UpdateFolderBuilder().SetName("A Brand New New Folder").SetID(2545279862892420L).Build();
            //smartsheet.Folders().UpdateFolder(folder);
            ////=========================================

            //// Create 3 users to share a sheet with
            //IList<User> users = new List<User>();
            //User user = new User();
            //user.Email = "*****@*****.**";
            //users.Add(user);

            //User user1 = new User();
            //user1.Email = "*****@*****.**";
            //users.Add(user1);

            //User user2 = new User();
            //user2.Email = "*****@*****.**";
            //users.Add(user2);

            //// Add the message, subject & users to share with
            //MultiShare multiShare = new MultiShare.ShareToManyBuilder().SetMessage("Here is the sheet I am sharing with you").
            //	SetAccessLevel(AccessLevel.VIEWER).SetSubject("Sharing a Smartsheet with you").SetUsers(users).Build();

            //// Share the specified sheet with the users.
            //smartsheet.Sheets().Shares().ShareTo(7370846613333892L, multiShare, true);
            ////=========================================

            //// Create a single share to a specified email address with the specified access level
            //Share share = new Share.ShareToOneBuilder().SetEmail("*****@*****.**").SetAccessLevel(AccessLevel.VIEWER)
            //		.Build();
            //// Add the share to a specific sheet
            //smartsheet.Sheets().Shares().ShareTo(7370846613333892L, share);
            ////=========================================

            //// Create a share with the specified access level
            //share = new Share.UpdateShareBuilder().SetAccessLevel(AccessLevel.VIEWER).Build();
            //// Update the share permission on the specified sheet for the specified user.
            //smartsheet.Sheets().Shares().UpdateShare(7370846613333892L, 3433212006426500L, share);
            ////=========================================

            //// Create 3 cells
            //Cell cell = new Cell();
            //cell.Value = "Cell1";
            //cell.Strict = false;
            //cell.ColumnId = 5111621270955908L;
            //Cell cell2 = new Cell();
            //cell2.Value = "Cell2";
            //cell2.ColumnId = 2859821457270660L;
            //Cell cell3 = new Cell();
            //cell3.Value = "cell3";
            //cell3.ColumnId = 7877251644581764L;

            //// Store the cells in a list
            //List<Cell> cells1 = new List<Cell>();
            //cells1.Add(cell);
            //cells1.Add(cell2);
            //cells1.Add(cell3);

            //// Create a row and add the list of cells to the row
            //Row row = new Row();
            //row.Cells = cells1;

            //// Add two rows to a list of rows.
            //List<Row> rows = new List<Row>();
            //rows.Add(row);
            //rows.Add(row);

            //// Add the rows to the row wrapper and set the location to insert the rows
            //RowWrapper rowWrapper = new RowWrapper.InsertRowsBuilder().SetRows(rows).SetToBottom(true).Build();

            //// Add the rows to the specified sheet
            //smartsheet.Sheets().Rows().InsertRows(7370846613333892L, rowWrapper);

            //// Setup a row to be moved to the top of a sheet
            //RowWrapper rowWrapper1 = new RowWrapper.MoveRowBuilder().SetToTop(true).Build();
            //// Move the specified row
            //smartsheet.Rows().MoveRow(5701744190613380L, rowWrapper1);
            ////=========================================

            //// Create a sheet that is a copy of a template
            //Sheet sheet1 = new Sheet.CreateFromTemplateOrSheetBuilder().SetFromId(7370846613333892L).
            //	SetName("Copy of a Template").Build();
            //// Create the new sheet from the template
            //smartsheet.Sheets().CreateSheetFromExisting(sheet1, new ObjectInclusion[] { ObjectInclusion.DATA,
            //	ObjectInclusion.ATTACHMENTS, ObjectInclusion.DISCUSSIONS });
            ////=========================================

            //// Setup a sheet with a new name
            //Sheet sheet2 = new Sheet.UpdateSheetBuilder().SetName("TESTING123").SetID(7370846613333892L).Build();

            //// Update the sheet with the new name
            //smartsheet.Sheets().UpdateSheet(sheet2);
            ////=========================================

            //// Setup a publishing status to give a rich version of the sheet as read only
            //SheetPublish publish = new SheetPublish.PublishStatusBuilder().SetReadOnlyFullEnabled(true).
            //	SetReadOnlyLiteEnabled(false).SetIcalEnabled(false).SetReadWriteEnabled(false).Build();
            //// Setup the specified sheet with the new publishing status
            //smartsheet.Sheets().UpdatePublishStatus(7370846613333892L, publish);
            ////=========================================

            //// Setup a user with an email address and full permission
            //User user3 = new User.AddUserBuilder().SetEmail("*****@*****.**").SetAdmin(true).
            //		SetLicensedSheetCreator(true).Build();
            //// Create the user account
            //smartsheet.Users().AddUser(user3);
            ////=========================================

            //// Setup a user with new privileges
            //User user4 = new User.UpdateUserBuilder().SetAdmin(false).SetLicensedSheetCreator(false).
            //	SetID(4187958019417988L).Build();
            //// Send the request to update the users account with the new privileges
            //smartsheet.Users().UpdateUser(user4);
            ////=========================================

            //// Create a workspace with a specific name and ID
            //Workspace workspace = new Workspace.UpdateWorkspaceBuilder().SetName("Workspace Name1").
            //	SetID(8257948486002564L).Build();
            //// Update the workspace with the new name.
            //smartsheet.Workspaces().UpdateWorkspace(workspace);
            ////=========================================

            //smartsheet.Sheets().Attachments().AttachFile(4844590336370564L,
            //	@"../../../TestSDK/resources/getPDF.pdf", "application/pdf");

            //Attachment attach = new Attachment();
            //attach.Name = "Test";
            //attach.Url = "http://google.com";
            //attach.AttachmentType = AttachmentType.LINK;
            //smartsheet.Sheets().Attachments().AttachURL(4844590336370564L, attach);
        }
        private static void UseTokenResources()
        {
            string accessToken = ConfigurationManager.AppSettings["accessToken"];

            SmartsheetClient smartsheet = new SmartsheetBuilder().SetAccessToken(accessToken).Build();
            try
            {
                smartsheet.TokenResources.GetAccessToken();
                Assert.Fail();
            }
            catch
            {

            }
            try
            {
                smartsheet.TokenResources.RefreshAccessToken();
                Assert.Fail();
            }
            catch
            {

            }
            smartsheet.TokenResources.RevokeAccessToken();
            try
            {
                smartsheet.SheetResources.ListSheets(null, null);
                Assert.Fail();
            }
            catch
            {

            }
        }