Cannot edit or delete package
Wednesday, April 19, 2023 at 09:39pmHi,
I am getting following error while trying to update the expiry date of a package
OneSpanSign.Sdk.OssServerException: Could not send the package. Exception: The remote server returned an error: (403) Forbidden. HTTP POST on URI https://sandbox.esignlive.com/api/packages/2nHUDBSB23inrZk_XfnR9b4sM4Y=. Optional details: {\"technical\":\"package: 2nHUDBSB23inrZk_XfnR9b4sM4Y= cannot be edited.\",\"messageKey\":\"error.forbidden.cannotEditDeletePkg\",\"message\":\"Cannot edit or delete package.\",\"code\":403,\"name\":\"Access Denied\"} ---> OneSpanSign.Sdk.OssServerException: The remote server returned an error: (403) Forbidden. HTTP POST on URI https://sandbox.esignlive.com/api/packages/2nHUDBSB23inrZk_XfnR9b4sM4Y=. Optional details: {\"technical\":\"package: 2nHUDBSB23inrZk_XfnR9b4sM4Y= cannot be edited.\",\"messageKey\":\"error.forbidden.cannotEditDeletePkg\",\"message\":\"Cannot edit or delete package.\",\"code\":403,\"name\":\"Access Denied\"} ---> System.Net.WebException: The remote server returned an error: (403) Forbidden.\r\n at System.Net.HttpWebRequest.GetResponse()\r\n at OneSpanSign.Sdk.Internal.HttpMethods.PostHttp(String apiKey, String path, Byte[] content, IDictionary`2 headers)\r\n --- End of inner exception stack trace ---\r\n at OneSpanSign.Sdk.Internal.HttpMethods.PostHttp(String apiKey, String path, Byte[] content, IDictionary`2 headers)\r\n at OneSpanSign.Sdk.RestClient.Post(String path, String jsonPayload)\r\n at OneSpanSign.Sdk.Services.PackageService.SendPackage(PackageId packageId)\r\n --- End of inner exception stack trace ---\r\n at OneSpanSign.Sdk.Services.PackageService.SendPackage(PackageId packageId)\r\n at OneSpanSign.Sdk.OssClient.SendPackage(PackageId id)
The code I am using to update the package is
PackageId ossPackageId = new PackageId(documentSignatureResendDto.PackageId);
DocumentPackage package = ossClient.GetPackage(ossPackageId);
ossClient.ChangePackageStatusToDraft(ossPackageId);
package.ExpiryDate = documentSignatureResendDto.ExpiresOn;
ossClient.UpdatePackage(ossPackageId, package);
ossClient.SendPackage(ossPackageId);
Can you please check what is wrong here?
Thanks,
Kamran
Reply to: Cannot edit or delete package
Thursday, April 20, 2023 at 10:42amHi Kamran,
Thanks for your post! I can reproduce the same error with this code, and you just need to change the order to these two lines to resolve the issue (change package to draft first, then get package):
PackageId ossPackageId = new PackageId("C_ejhz7t2XqlHiEodYrdo1beMXc=");
ossClient.ChangePackageStatusToDraft(ossPackageId);
DocumentPackage package = ossClient.GetPackage(ossPackageId);
package.ExpiryDate = DateTime.Parse("2023-05-01");
ossClient.UpdatePackage(ossPackageId, package);
ossClient.SendPackage(ossPackageId);
PS: This is because if you get package first, the local package.Status is still SENT and this attribute has higher priority than package.Due, which will directly send out the transaction without setting the expiry in .UpdatePackage(), and cause this 403 error in the last .SendPackage() since the transaction is already SENT.
Duo
Reply to: Cannot edit or delete package
Thursday, April 20, 2023 at 08:13pmHi Duo,
Changing the order worked.
Thanks,
Kamran