Is it possible to send multiple documents with metadata?
Monday, July 31, 2023 at 08:08amHello, I need to send multiple documents, I saw this post: https://community.onespan.com/forum/adding-multiple-documents-meta-data And in this post it informs that it would not be possible, but it is from 2018, is there any current solution for this?
This is the payload I'm using:
{
"roles": [
{
"id": "Role1",
"signers": [
{
"email": "[email protected]",
"firstName": "Example",
"lastName": "Example",
"company": "OneSpan Sign"
}
]
},
{
"id": "Role2",
"signers": [
{
"email": "[email protected]",
"firstName": "Example",
"lastName": "Example",
"company": "OneSpan Sign"
}
]
},
{
"id": "Role3",
"signers": [
{
"email": "[email protected]",
"firstName": "Example",
"lastName": "Example",
"company": "OneSpan Sign"
}
]
}
],
"documents": [
{
"approvals": [
{
"role": "Role1",
"fields": [
{
"page": 0,
"top": 100,
"subtype": "FULLNAME",
"height": 50,
"left": 100,
"width": 200,
"type": "SIGNATURE"
}
]
},
{
"role": "Role2",
"fields": [
{
"page": 0,
"top": 100,
"subtype": "FULLNAME",
"height": 50,
"left": 100,
"width": 200,
"type": "SIGNATURE"
}
]
}
],
"name": "Teste"
}
],
"name": "Teste",
"type": "PACKAGE",
"language": "en",
"emailMessage": "",
"description": "Esse é um teste para a aplicação",
"autocomplete": True,
"status": "DRAFT"
}
)
Reply to: Is it possible to send multiple documents with metadata?
Monday, July 31, 2023 at 02:45pmHi Matheus,
Try with the attached code base.
Duo
Reply to: Is it possible to send multiple documents with metadata?
Monday, July 31, 2023 at 09:15amHi Matheus,
Please disregard the information in the post you referred to, it's possible to send multiple documents in a single call. Try with the attached example JSON where I added multiple JSON nodes under "documents", and add the corresponding "file" binary in the form-data (see the screenshot).
Duo
Reply to: Is it possible to send multiple documents with metadata?
Monday, July 31, 2023 at 01:19pmI need to send via python, but the request is returning 500,
I am sending this way:
files = {
"document1": ("file1.pdf", open("doc1.pdf", "rb").read(), 'application/pdf'),
"document2": ("file2.pdf", open("doc2.pdf", "rb").read(), 'application/pdf'),
}
data = {"Payload": json.dumps(
{"roles": [
{"id": "Role1", "signers": [
{"email": "[email protected]", "firstName": "Matheus", "lastName": "teste", "company": "JumpLabel"}
]
},
{"id": "Role2", "signers": [{"email": "[email protected]", "firstName": "Matheus ", "lastName": "teste", "company": "Jump"}]}],
"documents": [
{"approvals": [
{"role": "Role1", "fields": [
{"page": 0, "top": 0, "subtype": "FULLNAME", "height": 50, "left": 0, "width": 200, "type": "SIGNATURE"}]}],
"name": "document1.pdf", "id": 51},
{"approvals": [{"role": "Role2", "fields": [
{"page": 0, "top": 0, "subtype": "FULLNAME", "height": 50, "left": 0, "width": 200, "type": "SIGNATURE"}]}],
"name": "document1.pdf", "id": 51}],
"name": "Teste", "type": "PACKAGE", "language": "en", "emailMessage": "Segue para assinatura o acordo de serviço.", "description": "Envio de documento para assinatura", "autocomplete": True, "status": "DRAFT"}
)}
headers = {
'authorization': "api key",
'Content-Type': 'multipart/form-data'
}
response = requests.post(url, files=files, data=data, headers=headers)
in requests, sending as files=files and payload data=data?
Reply to: Is it possible to send multiple documents with metadata?
Monday, July 31, 2023 at 01:25pmHi Matheus,
Few things:
(1)Set the form-data name as "file" for both files. They will match the metadata in sequence.
files = {
"file": ("file1.pdf", open("doc1.pdf", "rb").read(), 'application/pdf'),
"file": ("file2.pdf", open("doc2.pdf", "rb").read(), 'application/pdf'),
}
(2)In metadata, "documents" need to have unique id. Now both documents have id of "51".
Duo
Reply to: Is it possible to send multiple documents with metadata?
Monday, July 31, 2023 at 01:36pmI got the return <Response [500]>
I changed the ids, and the file dictionary:
files = {
"file": ("file1.pdf", open("doc1.pdf", "rb").read(), 'application/pdf'),
"file": ("file2.pdf", open("doc2.pdf", "rb").read(), 'application/pdf')
}
data = {"Payload": json.dumps(
{"roles": [
{"id": "Role1", "signers": [
{"email": "[email protected]", "firstName": "Matheus", "lastName": "Teste", "company": "JumpLabel"}
]
},
{"id": "Role2", "signers": [{"email": "[email protected]", "firstName": "Matheus ", "lastName": "Teste", "company": "Jump"}]}],
"documents": [
{"approvals": [
{"role": "Role1", "fields": [
{"page": 0, "top": 0, "subtype": "FULLNAME", "height": 50, "left": 0, "width": 200, "type": "SIGNATURE"}]}],
"name": "document1.pdf", "id": 50},
{"approvals": [{"role": "Role2", "fields": [
{"page": 0, "top": 0, "subtype": "FULLNAME", "height": 50, "left": 0, "width": 200, "type": "SIGNATURE"}]}],
"name": "documen2.pdf", "id": 51}],
"name": "Teste", "type": "PACKAGE", "language": "en", "emailMessage": "Segue para assinatura o acordo de serviço.", "description": "Envio de documento para assinatura", "autocomplete": True, "status": "DRAFT"}
)}
headers = {
'authorization': "api key",
'Content-Type': 'multipart/form-data'
}
response = requests.post(url, files=files, data=data, headers=headers) is this part correct?
Reply to: Is it possible to send multiple documents with metadata?
Monday, July 31, 2023 at 02:37pmHi Matheus,
I think I found the issue - remove the 'Content-Type': 'multipart/form-data' from your headers, it will override/remove your request boundary.
Duo
Reply to: Is it possible to send multiple documents with metadata?
Monday, July 31, 2023 at 02:42pmheaders = {
'authorization': "Basic api_key"
}
I removed it, but now the return is now: <Response [400]>
Reply to: Is it possible to send multiple documents with metadata?
Monday, July 31, 2023 at 02:52pmThank you Duo Liang, it worked!!