saraizad | Posts: 17

Copying Documents from one package to another

0 votes
Hi, Is there an API available to copy a document from one package to another package?

Approved Answer
Duo_Liang | Posts: 3776

Reply to: Copying Documents from one package to another

1 votes
Hi Sara, Yes, you can use below API to upload an almost empty document (only containing ID and name), and then use this ID to apply layout:
HTTP Request
POST /api/packages/{packageId}/documents

HTTP Headers
Accept: text/html
Content-Type: multipart/form-data
Authorization: Basic api_key

Request Payload
------WebKitFormBoundary1bNO60n7FqP5WO4t
Content-Disposition: form-data; name="file"; filename="testDocumentExtraction.pdf"
Content-Type: application/pdf

%PDF-1.5
%µµµµ
1 0 obj
>>>
endobj.... 

------WebKitFormBoundary1bNO60n7FqP5WO4t
Content-Disposition: form-data; name="payload"

{
  "id": "document_id",
 "name": "document_name"
}

------WebKitFormBoundary1bNO60n7FqP5WO4t--
Duo

Duo_Liang | Posts: 3776

Reply to: Copying Documents from one package to another

0 votes
Hi saraizad, Yes, I think Layout Feature fits your scenario. #1. create a layout out of your document:
HTTP Request
POST /api/layouts

HTTP Headers
Accept: application/json
Content-Type: application/json
Authorization: Basic api_key

Request Payload
{ 
   "name":"layout_name",    
   "type":"LAYOUT",
   "id":"source_package_id",
   "visibility":"SENDER",
   "documents":[ 
      { 
         "id":"source_document_id"
      }
   ]
}
#2. retrieve the layout ID from response payload of #1 REST call #3. apply the layout to target document:
HTTP Request
POST /api/packages/{packageId}/documents/{documentId}/layout?layoutId={layoutId}

HTTP Headers
Accept: application/json
Content-Type: application/json
Authorization: Basic api_key
Note: 1.layoutID is the one you got from #2 2.no need for request payload Hope this could help! Duo

saraizad | Posts: 17

Reply to: Copying Documents from one package to another

0 votes
Hi Duo, Thank you for your response, but I'm not sure if I can use that, here is the scenario: Package A has Document#1 and Document#2 Package B has Document#3 and Document#4 I need to create a package C that has Document#1 and Document#3. I was wondering if there is a way maybe like an API that gets DocumentIds and would clone them into the Package C. based on your response, I'm wondering if I can use your solution and create empty files(so smaller payload) and put them into Package C and then use Layout to copy them over to C, do you think that would work? Thanks, Sara

Duo_Liang | Posts: 3776

Reply to: Copying Documents from one package to another

0 votes
Just a little correction, both ID and name are necessary for uploading a document. Duo

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