API Query for new Row

Hi. I would like to add a new row to an existing sheet. I need to create a query to pass into the API so the items I want to add, goes into each of the row columns in the sheet. Can I have a sample or idea of how I can do that? I would like to pass a JSON query. I couldn't find the right inputs. Do I have to be an admin to add rows as as well?

Answers

  • Lucas Rayala
    Lucas Rayala ✭✭✭✭✭

    Hi@Kuna Sheelan, I don't have my code in front of me, but there's example code on the Smartsheet's Redocly page:

    Smartsheet - Official API and SDK Documentation (redoc.ly)

    Navigate to the "row" object on the left scroll bar and click on "Methods" -- that will give you example code.

  • Hi@Lucas Rayala,


    I greatly appreciate the response. Thank you. I will try this. =)

  • Hi,

    I believe I am very close.

    我有一个电流片with a bunch of columns. How can I know/find the IDs for the column? =)

  • Lucas Rayala
    Lucas Rayala ✭✭✭✭✭
    edited 02/28/23

    @Kuna SheelanI put a snip of my append code below (Python) -- you need to pass your data to this function as a panda dataframe ("df"). FYI, the API takes your commands as a single URL which means there are physical character restrictions, so I have this chunk the API calls to 300 rows of data -- that's a default, you can change it if you want to play around. Also, this code wraps your data in a string function iestr(df.iat(i,j))you can remove that function if you need to, but I would keep it while you troubleshoot because Smartsheet is picky with data types.

    ss = smartsheet.Smartsheet(API_TOKEN) def append_df(df, sheet_id, parent_row, chunk_interval=300): # appends df to sheet underneath a single header row list_of_rows = [] list_of_columns = [] for c, column in enumerate(df): # column id list, done here to limit smartsheet server hits list_of_columns.append(ss.Sheets.get_columns(sheet_id, include_all=True).data[c].id) for i, rows in df.iterrows(): # loop to create temp rows for the remainder of the df temp_row = ss.models.Row() temp_row.to_bottom = True for j, columns in enumerate(df): temp_row.cells.append({ 'column_id': list_of_columns[j], 'value': str(df.iat[i,j]) # string function used to eliminate load errors }) list_of_rows.append(temp_row) for x in range(0, len(list_of_rows), chunk_interval): # chunks rows (300 default). more rows may cause failure (URL length limit) ss.Sheets.add_rows(sheet_id, list_of_rows[x:(x + chunk_interval)])
  • Hi,


    I was successfully able to write a new row and execute what I needed. Thank you so much. This was much easier than I anticipated. =) Thank you for your help@Lucas Rayala!

  • bsikes
    bsikes ✭✭✭

    @Kuna SheelanIf it's at all helpful, I would like to point out that ChatGPT has gotten ridiculously close to providing working code that interacts with the Smartsheet API. We have several projects that could have been greatly expedited if we had this tool when we started.

  • Lucas Rayala
    Lucas Rayala ✭✭✭✭✭

    Hi@Kuna Sheelanglad to help and I'm glad you got it working quickly!@bsikesI've played around with ChatGPT for this and SQL code -- it's a great assist. I have a feeling that once it gets more training on the specific API it will really be able to nail down requests. I know some coders who have been at it for twenty years and they say that they pretty much let ChatGPT do 80% of the work. I think it's better the more coding experience you have, because the little hiccups are always hard to catch.

  • bsikes
    bsikes ✭✭✭

    @Lucas RayalaThat's been my experience as well. As long as you're able to understand what it's trying to do and have some skill in troubleshooting why it's not working, it can definitely provide a quick framework for the task at hand. Even then, you can usually ask it to explain what the code it generated is supposed to do, and it can usually do a good job explaining that.

    I've even given it some of my code that I did a poor job documenting, and asked it to provide comments throughout explaining what it does...

Hi @palefty<\/a> <\/p>

The Smartsheet API does not possess a native method to directly fetch or incorporate clickable row permalinks when you export a sheet to an Excel file. So, users need more intuitive, clickable links within their exported Excel sheets.<\/p>

To address this, I have implemented a workaround:<\/p>

(I used Smartsheet SDK to implement the workaround)<\/p>

\n \n https:\/\/gist.github.com\/jmyzk\/5cc4dfbbf79b010d374f0b5ad3fa0a4b\n <\/a>\n<\/div>


<\/p>

Fetching Permalinks:<\/strong> The code interacts with the Smartsheet API to retrieve each row's permalink values.<\/p>

Incorporating into the sheet:<\/strong> These permalink values are then populated into a designated column. When you export the sheet as an Excel file, you'll notice a column filled with URLs corresponding to the permalinks for each row in Smartsheet.<\/p>

\n
\n \n \"export<\/img><\/a>\n <\/div>\n<\/div>\n
\n \n https:\/\/app.smartsheet.com\/b\/publish?EQBCT=adda95b9ed0d49f192faa76e1535bc47\n <\/a>\n<\/div>

Making the Links Clickable:<\/strong> As a final step, to enhance user experience and ease of access, the code processes the Excel file to convert these plain URL texts into clickable hyperlinks. Thus, when users click these links in the Excel sheet, they're directed to the appropriate Smartsheet row online.<\/p>

With the implemented code, users can easily navigate to Smartsheet rows directly from their Excel sheets.<\/p>

\n
\n \n \"expoerted<\/img><\/a>\n <\/div>\n<\/div>\n


<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":320,"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[{"tagID":227,"urlcode":"api-and-developers","name":"API and Developers"}]},{"discussionID":108411,"type":"question","name":"Is it possible to update a shared with sheet, by the shared with user via the APIs?","excerpt":"I'm updating sheets via the API, I have a sheet that was shared with me, where I have admin level access. Doing a SheetResources.UpdateSheet(sheetObject) returns an unauthorized error on the shared with sheet. Only the sheets that I own seem to be updatable via the API, any sheets that were shared with me, I am not…","snippet":"I'm updating sheets via the API, I have a sheet that was shared with me, where I have admin level access. Doing a SheetResources.UpdateSheet(sheetObject) returns an unauthorized…","categoryID":320,"dateInserted":"2023-08-02T13:50:08+00:00","dateUpdated":null,"dateLastComment":"2023-08-11T08:41:34+00:00","insertUserID":157588,"insertUser":{"userID":157588,"name":"sbryon","url":"https:\/\/community.smartsheet.com\/profile\/sbryon","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-11T20:50:08+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"updateUserID":null,"lastUserID":91566,"lastUser":{"userID":91566,"name":"Genevieve P.","title":"Community Manager","url":"https:\/\/community.smartsheet.com\/profile\/Genevieve%20P.","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/KHY4Y67W0VRX\/nF76D5N9MFB28.png","dateLastActive":"2023-08-11T17:39:53+00:00","banned":0,"punished":0,"private":false,"label":"Employee Admin"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":3,"countViews":67,"score":null,"hot":3382729302,"url":"https:\/\/community.smartsheet.com\/discussion\/108411\/is-it-possible-to-update-a-shared-with-sheet-by-the-shared-with-user-via-the-apis","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/108411\/is-it-possible-to-update-a-shared-with-sheet-by-the-shared-with-user-via-the-apis","format":"Rich","lastPost":{"discussionID":108411,"commentID":390158,"name":"Re: Is it possible to update a shared with sheet, by the shared with user via the APIs?","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/390158#Comment_390158","dateInserted":"2023-08-11T08:41:34+00:00","insertUserID":91566,"insertUser":{"userID":91566,"name":"Genevieve P.","title":"Community Manager","url":"https:\/\/community.smartsheet.com\/profile\/Genevieve%20P.","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/userpics\/KHY4Y67W0VRX\/nF76D5N9MFB28.png","dateLastActive":"2023-08-11T17:39:53+00:00","banned":0,"punished":0,"private":false,"label":"Employee Admin"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"Get Help","url":"https:\/\/community.smartsheet.com\/categories\/get-help"},{"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers"}],"groupID":null,"statusID":3,"attributes":{"question":{"status":"accepted","dateAccepted":"2023-08-11T13:16:14+00:00","dateAnswered":"2023-08-11T08:41:34+00:00","acceptedAnswers":[{"commentID":390158,"body":"

@sbryon<\/a> <\/p>

Thanks for confirming! Yes you're correct, only the owner of a sheet can rename it, unless the Admin has been shared to the entire workspace where the sheet resides. <\/p>

This chart has more information on permission levels and actions you can take:<\/p>

\n \n https:\/\/help.smartsheet.com\/sharing-permission-levels\n <\/a>\n<\/div>

Cheers,<\/p>

Genevieve<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":320,"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[]},{"discussionID":108367,"type":"question","name":"Is there any way to get the email faster?","excerpt":"Email Trigger takes 3-5 mins. I need to get it faster. Is there any possible to get faster?. can you please update this issue as soon as possible?","snippet":"Email Trigger takes 3-5 mins. I need to get it faster. Is there any possible to get faster?. can you please update this issue as soon as possible?","categoryID":320,"dateInserted":"2023-08-01T17:39:46+00:00","dateUpdated":null,"dateLastComment":"2023-08-02T14:33:54+00:00","insertUserID":164348,"insertUser":{"userID":164348,"name":"Tamilselvan","title":"Associate","url":"https:\/\/community.smartsheet.com\/profile\/Tamilselvan","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-09T18:06:12+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"updateUserID":null,"lastUserID":164348,"lastUser":{"userID":164348,"name":"Tamilselvan","title":"Associate","url":"https:\/\/community.smartsheet.com\/profile\/Tamilselvan","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-09T18:06:12+00:00","banned":0,"punished":0,"private":false,"label":"✭"},"pinned":false,"pinLocation":null,"closed":false,"sink":false,"countComments":4,"countViews":75,"score":null,"hot":3381900820,"url":"https:\/\/community.smartsheet.com\/discussion\/108367\/is-there-any-way-to-get-the-email-faster","canonicalUrl":"https:\/\/community.smartsheet.com\/discussion\/108367\/is-there-any-way-to-get-the-email-faster","format":"Rich","lastPost":{"discussionID":108367,"commentID":388479,"name":"Re: Is there any way to get the email faster?","url":"https:\/\/community.smartsheet.com\/discussion\/comment\/388479#Comment_388479","dateInserted":"2023-08-02T14:33:54+00:00","insertUserID":164348,"insertUser":{"userID":164348,"name":"Tamilselvan","title":"Associate","url":"https:\/\/community.smartsheet.com\/profile\/Tamilselvan","photoUrl":"https:\/\/us.v-cdn.net\/6031209\/uploads\/defaultavatar\/nWRMFRX6I99I6.jpg","dateLastActive":"2023-08-09T18:06:12+00:00","banned":0,"punished":0,"private":false,"label":"✭"}},"breadcrumbs":[{"name":"Home","url":"https:\/\/community.smartsheet.com\/"},{"name":"Get Help","url":"https:\/\/community.smartsheet.com\/categories\/get-help"},{"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers"}],"groupID":null,"statusID":3,"attributes":{"question":{"status":"accepted","dateAccepted":"2023-08-01T19:01:47+00:00","dateAnswered":"2023-08-01T18:58:51+00:00","acceptedAnswers":[{"commentID":388283,"body":"

Feel free to submit a Product Idea!<\/p>

There's nothing we can do as users. It would require a rebuild of that system. I'm pretty sure it's resource intensive, and runs on a schedule performing the automations.<\/p>"},{"commentID":388346,"body":"

No problem. Sorry I didn't have a way to help solve your problem. <\/p>

Having to wait is especially frustrating for me when I'm giving a demo, but that's not the only time I'd like them to execute faster. <\/p>

Consider submitting a Product Idea here (if a search for an already made suggestion isn't available for you to upvote. <\/p>

\n \n https:\/\/community.smartsheet.com\/post\/idea\n <\/a>\n<\/div>

All the best,<\/p>

-Ray<\/p>"}]}},"status":{"statusID":3,"name":"Accepted","state":"closed","recordType":"discussion","recordSubType":"question"},"bookmarked":false,"unread":false,"category":{"categoryID":320,"name":"API & Developers","url":"https:\/\/community.smartsheet.com\/categories\/api-developers","allowedDiscussionTypes":[]},"reactions":[{"tagID":3,"urlcode":"Promote","name":"Promote","class":"Positive","hasReacted":false,"reactionValue":5,"count":0},{"tagID":5,"urlcode":"Insightful","name":"Insightful","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":11,"urlcode":"Up","name":"Vote Up","class":"Positive","hasReacted":false,"reactionValue":1,"count":0},{"tagID":13,"urlcode":"Awesome","name":"Awesome","class":"Positive","hasReacted":false,"reactionValue":1,"count":0}],"tags":[]}],"initialPaging":{"nextURL":"https:\/\/community.smartsheet.com\/api\/v2\/discussions?page=2&categoryID=320&includeChildCategories=1&type%5B0%5D=Question&excludeHiddenCategories=1&sort=-hot&limit=3&expand%5B0%5D=all&expand%5B1%5D=-body&expand%5B2%5D=insertUser&expand%5B3%5D=lastUser&status=accepted","prevURL":null,"currentPage":1,"total":211,"limit":3},"title":"Trending in API & Developers","subtitle":null,"description":null,"noCheckboxes":true,"containerOptions":[],"discussionOptions":[]}">

Trending in API & Developers