Andrew Little
Andrew Little

Reputation: 27

Smartsheet API Resourcenotfooundexception Creating new sheet

I am creating a new sheet in Smartsheet via the API in Visual Studio 2015 C#.
I have followed the code/API Guide from Smartsheet but i get an error at run time when the code fires.

The error is as follows:

Smartsheet.Api.ResourceNotFoundException was unhandled
  HResult=-2146233088
  Message=Not Found
  Source=smartsheet-csharp-sdk
  StackTrace:
       at Smartsheet.Api.Internal.AbstractResources.HandleError(HttpResponse response)
       at Smartsheet.Api.Internal.AbstractResources.CreateResource[T](String path, Type objectClass, T object)
       at Smartsheet.Api.Internal.FolderSheetResourcesImpl.CreateSheet(Int64 folderId, Sheet sheet)
       at Aviva_Order_Systems.avivaorders.button1_Click(Object sender, EventArgs e) in C:\Dropbox\AL DB\Dropbox\Aviva\Order Project\Aviva Order Systems\avivaorders.cs:line 372
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Aviva_Order_Systems.Program.Main() in C:\Dropbox\AL DB\Dropbox\Aviva\Order Project\Aviva Order Systems\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

"

This section of the code is what is being highlight when i attempt to debug the error.

            Sheet newSheet = ssproj.FolderResources.SheetResources.CreateSheet(
            #####,                   // long folderId
            new Sheet
               {
                Name = "OrderProfile", 
                Columns = new Column[] { CCnum, CCName, Project, Supplier, SEQ }
                } 
            );

Note i have changed the #### on purpose.  It is giving the error here: 
Sheet newSheet = ssproj.FolderResources.SheetResources.CreateSheet(
            #####,                   // long folderId
            new Sheet
               {
                Name = "OrderProfile", 
                Columns = new Column[] { CCnum, CCName, Project, Supplier, SEQ }
                } 
            );

Any ideas on what is causing this? I have tried searching

Upvotes: 1

Views: 407

Answers (1)

Kim Brandl
Kim Brandl

Reputation: 13490

Looks like you're trying to create the sheet in the specified folder. Based on the error you're getting, I'd suspect that the folder ID that you're specifying isn't valid.

To troubleshoot, you can verify whether the folder ID is valid by trying to execute a Get Folder request with that ID. If the ID is valid, the Get Folder request will succeed; if it's invalid, the request will fail. The following C# code example attempts to retrieve folder with ID = 7116448184199044.

Folder folder = smartsheet.FolderResources.GetFolder(
  7116448184199044,           // long folderId
  null                        // IEnumerable<FolderInclusion> include
);

UPDATE (in response to your comment)

  • If you want to create the sheet in a folder and that folder happens to be located within a shared workspace, the API call you're using (Create Sheet in Folder) should work. If you're getting the "resource not found" error in response to this API request, then either the folder ID you're specifying is invalid OR the account that owns the API access token you're using to issue the API request doesn't have access to that folder/workspace. As described previously, you can verify that the folder ID is valid (and that the account that owns the API access token does have access to the folder) by confirming that you're able to successfully issue a Get Folder API request for that folder.

  • If you want to create the sheet at the root of the shared workspace (i.e., not inside a folder, but rather, at the root level of the workspace), you'll need to use the Create Sheet in Workspace API request to do so (specifying the ID of the workspace). The account that owns the API access token used to issue the API request must have access to the workspace in order for this call to succeed.

Upvotes: 2

Related Questions