Add holder documents to an order
After you create an order, you can send the holder's documents through the API, such as the identity document or the proof of address. Amplia Reg adds them to the order, and the agents see them when they validate it.
Before you start
You will need:
- The order number. This is the
numberthat the API returned when you created the order. - An application with the Sales app role, created in a CA or in an RA. If the API returns the
SubscriptionRequirederror, the application does not belong to a CA or an RA. - The code of the holder type. The holder type defines the documents that the order accepts. If the order already has a holder type,
send the same one, because this API cannot change it. To list the holder types, call
GET /api/holder-types?isDisabled=false. Each item hasid,nameandcode. - An order whose data can still be edited. Once the order is waiting issue, for example, the API responds with the
OrderCannotUpdateerror.
Add the documents
- .NET
- REST
- curl
var response = await ampliaRegService.AddHolderFilesAsync(
"800-005-520", // Order number
new List<HolderFileReference2>() {
new HolderFileReference2() {
Type = "Identification",
Subtype = HolderFileSubtypes.Cnh,
DocumentPart = DocumentParts.FrontComplete,
File = FileReference.FromFile(@"C:\AppData\Documents\cnh.pdf"),
},
},
HolderTypeReference.FromCode("PF") // Holder type code
);
The .NET client library uploads the files for you. See Reference files for the ways to reference a file.
First, upload each file. Then add the uploads to the order:
POST /api/orders/800-005-520/holder-files
{
"holderType": {
"code": "PF" // Holder type code
},
"holderFiles": [
{
"type": "Identification",
"subtype": "Cnh",
"documentPart": "FrontComplete",
"file": {
"id": "0195a9dc-c0f0-4f5c-83d3-bf562ae98ed9", // ID returned by the upload
"name": "cnh.pdf",
"contentType": "application/pdf"
}
}
]
}
First, upload each file. Then add the uploads to the order:
curl -X POST "https://ampliareg.yourcompany.com/api/orders/800-005-520/holder-files" \
-H "X-Api-Key: your-app|YOUR_KEY" \
-H "Content-Type: application/json" \
--data-binary @body.json
Content of body.json:
{
"holderType": {
"code": "PF"
},
"holderFiles": [
{
"type": "Identification",
"subtype": "Cnh",
"documentPart": "FrontComplete",
"file": {
"id": "0195a9dc-c0f0-4f5c-83d3-bf562ae98ed9",
"name": "cnh.pdf",
"contentType": "application/pdf"
}
}
]
}
See Fields of each document for the values of type, subtype and documentPart.
You can use each upload only once, because Amplia Reg moves the file into the order and deletes the upload.
Fields of each document
The holder type of the order defines which documents are required and which are optional. Each item of holderFiles has:
type: the document type, such asIdentification,AddressProoforPhoto. Custom document types configured on the instance are prefixed with@(for example,@CustomDoc1). See Add document types.subtypeanddocumentPart(optional): in ICP-Brasil, anIdentificationdocument can state which document it is (Rg,Cnh,Dni,CTPS,Passport,RNE,CIN,OAB,CRC,CRM,ProfessionalLicenseorUndefined). Whensubtypeis given,documentPartis required:FrontCompleteorBackComplete, and alsoDigitalfor every subtype exceptRg,RNEandUndefined.file: the file reference. See Reference files.
Response
{
"holderFileIds": [
"7c1e4b9a-2f3d-4e8a-9b6c-1d2e3f4a5b6c"
]
}
holderFileIds has the ID of each document added, in the same order as holderFiles in the request.
Common errors
| Error code | When it happens |
|---|---|
OrderCannotUpdate | The order's data can no longer be changed because of its status |
CannotChangeHolderType | The order already has a different holder type |
HolderTypeNotAllowed | The order's certificate type does not accept the holder type |
HolderFileTypeCannotBeAdded | The holder type does not accept one of the document types sent |
UnexpectedHolderFileSubtype | The document type does not accept subtypes, or does not accept the given subtype |
See Error codes for the full list.
Example of an error response, with HTTP 422:
{
"code": "OrderCannotUpdate",
"message": "..."
}
Reference files
The options below apply to every API that receives files, such as this one and the pre-approved orders API.
In .NET, you can reference a file:
- By its path:
FileReference.FromFile(@"C:\AppData\Documents\document.pdf") - By a
FileInfoobject:FileReference.FromFile(new FileInfo(@"C:\AppData\Documents\document.pdf")) - By its content, as a byte array. In this case, also give the file name:
FileReference.FromBytes(bytes, "document.pdf") - By a
stream. You also need to give the file name:FileReference.FromStream(stream, "document.pdf")
The library uploads the file for you.
Through the API, the file never goes inside the JSON body. First upload it with a multipart/form-data request with the file, name
and contentType fields:
curl -X POST "https://ampliareg.yourcompany.com/api/uploads" \
-H "X-Api-Key: your-app|YOUR_KEY" \
-F "file=@document.pdf" \
-F "name=document.pdf" \
-F "contentType=application/pdf"
The response has the upload id. Then reference the upload in the API that receives the file:
"file": {
"id": "0195a9dc-c0f0-4f5c-83d3-bf562ae98ed9", // ID returned by the upload
"name": "document.pdf",
"contentType": "application/pdf"
}