API - C# - Delete rows from a specific index

HoaLTHoaLT
edited 12/16/21 in API & Developers
12/16/21 Edited 12/16/21
Accepted

Hi there,

I'm newbie on Smartsheet. I am working on integration of data from another system to Smartsheet through API.

The requirement is that we need to delete all rows from the fourth row to the last one of sheet then adding the new data into sheet every time we run API.

I've already implemented adding row data into sheet smoothly. However, the stuck is deleting from the fourth row.

I wonder if there is any way to delete data from a specific row through API. My project is working on the C#.

I would appreciate so much for those who can help me get out of this issue

Many thanks in advance!

Best Answer

Answers

  • I 've figured out on my own the following function in NodeJs

    function resetSheet (sheetId) {

     

      // Get sheet

      smartsheet.sheets.getSheet({sheetId})

        .then(function(sheetInfo) {

          const rowIdList = sheetInfo.rows.map(item => item.id);

          return rowIdList;

        })

        .then(data => {

          const deleteIds = data.splice(3);

          deleteIds.forEach(rowid => {

            smartsheet.sheets.deleteRow({

              sheetId: sheetId,

              rowId: rowid

            })

              .then(function(results) {

                console.log(results);

              })

              .catch(function(error) {

                console.log(error);

              });

          })

        })

        .catch(function(error) {

          console.log(error);

        });

    }

    It works but sometimes, it does not delete all rows from the 4th to the end along with alerting the following error

    errorCode=4004, message=Request failed because sheetId XXX is currently being updated by another request that uses the same access token. Please retry your request once the previous request has completed

    Do i missed anything?

    And is there any better solution we can deal with it? Solution with C# would be appreciated so much

    Many thanks!

  • Genevieve P.Genevieve P. admin
    Answer ✓

    Hi @HoaLT

    Are you looking to clear cell details from row 4 or fully delete out the rows?

    Here's the Delete Row information from the API Documentation: https://smartsheet.redoc.ly/tag/rows#operation/delete-rows

    There's C# details on the right side. You may also want to post in the StackOverflow community for help with C#.

    If you're receiving errors, I would recommend reaching out to Smartsheet Support with your full code and the Sheet ID.

    Cheers,

    Genevieve

  • Hi @Genevieve P.

    Thank you so much for your help.

    I 'm working on it.

    Hope you have a good day.

Sign In or Register to comment.