FannySL

Error 403 when updating a package

0 votes
Hi ! I'm trying to update a package and replace the pdf document in it, but I get this error : Unable to update package settings. Exception: Le serveur distant a retourné une erreur : (403) Interdit. HTTP PUT on URI https://sandbox.esignlive.com/api/packages/-bANyCo4NvqdgiEPNbMG2tLdaRE=. Optional details: {"messageKey":"error.forbidden.cannotEditDeletePkg","technical":"package: -bANyCo4NvqdgiEPNbMG2tLdaRE= cannot be edited.","message":"Cannot edit or delete package.","code":403,"name":"Access Denied"} I did not sign the document or click Accept on the first page, but I can't update it. Maybe I'm doing it the wrong way ? What I want is to be able to replace the document in the existing package if it's not signed, so I check the status and use the UpdatePackage method if the status is different than SIGNING_COMPLETE. I did not find any example of document update, so for now I tried this way :
Document doc = package.GetDocument("Declaration");
      doc.Content = args.PdfBytes;

      int docIndex = package.Documents.IndexOf(doc);
      package.Documents[docIndex] = doc;

      EslClient.UpdatePackage(packageId, package);
Is it ok ? Is there another way to update it that wouldnt cause this error ? Thanks :)

Approved Answer

Reply to: Error 403 when updating a package

0 votes
Oh I see. I believe the UpdatePackage() call only updates the package metadata (e.g. package name, expiry date, etc..) and not any actual documents. I think your best bet is to delete the document and reupload your new document. Of course, to do any of this, your package must be in draft. https://developer.esignlive.com/guides/feature-guides/document-management/
Haris Haidary OneSpan Technical Consultant

Reply to: Error 403 when updating a package

0 votes
Thanks ! I did that, at first it didn't work so I added a SendPackage after the Update Package, but it doesn't update the document, the pdf is the same after. I don't have an Is it how it's supposed to be done ? Is there a more "straight forward" way to do it than this :
PackageId packageId = new PackageId(args.PackageId);

EslClient.ChangePackageStatusToDraft(packageId);

DocumentPackage package =  EslClient.GetPackage(packageId);

Document currentDocument = package.GetDocument("Declaration");

Document documentToUpdate = DocumentBuilder.NewDocumentNamed(currentDocument.Name)
                                                .FromStream(new MemoryStream(args.PdfBytes), DocumentType.PDF)
                                                .WithId(currentDocument.Id.ToString()).Build();
documentToUpdate.AddSignatures(currentDocument.Signatures);

int docIndex = package.Documents.IndexOf(currentDocument);
package.Documents[docIndex] = documentToUpdate;

EslClient.UpdatePackage(packageId, package);
EslClient.SendPackage(packageId);
Thanks again !

Reply to: Error 403 when updating a package

0 votes
It worked ! Thanks :)

Hello! Looks like you're enjoying the discussion, but haven't signed up for an account.

When you create an account, we remember exactly what you've read, so you always come right back where you left off