Smartsheet API Resourcenotfooundexception创建新表

时间:2018-11-10 23:40:24

标签: c# visual-studio-2015 smartsheet-api

我正在通过Visual Studio 2015 C#中的API在Smartsheet中创建一个新工作表。
我遵循了Smartsheet的代码/ API指南,但是当代码触发时,在运行时出现错误。

错误如下:

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: 

"

这部分代码是我尝试调试错误时突出显示的内容。

            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 }
                } 
            );

关于什么原因的任何想法?我尝试搜索

1 个答案:

答案 0 :(得分:2)

好像您正在尝试在指定的文件夹中创建工作表。根据您收到的错误,我怀疑您指定的文件夹ID 无效。

要进行故障排除,您可以通过尝试使用该ID来执行Get Folder请求,以验证文件夹ID 是否有效。如果该ID有效,则获取文件夹请求将成功;如果无效,则请求将失败。以下C#代码示例尝试使用 ID = 7116448184199044来检索文件夹。

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

更新(回复您的评论)

  • 如果您想在一个文件夹中创建工作表,而该文件夹恰好位于共享工作空间的,则您正在使用的API调用(Create Sheet in Folder)工作。如果响应此API请求而收到“找不到资源”错误,则您指定的文件夹ID无效,或者拥有用于发出API请求的API访问令牌的帐户不存在”不能访问该文件夹/工作区。如前所述,您可以通过确认能够成功发布获取文件夹来验证文件夹ID有效(并且拥有API访问令牌的帐户确实有权访问该文件夹) >该文件夹的API请求。

  • 如果要在共享工作区的根目录(即不在文件夹内,而是在工作区的根目录)创建工作表,则需要使用{{3 }} API请求这样做(指定工作空间的ID)。拥有用于发出API请求的API访问令牌的帐户必须有权访问工作空间,此调用才能成功。