Pular para o conteúdo principal

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 number that 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 SubscriptionRequired error, 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 has id, name and code.
  • An order whose data can still be edited. Once the order is waiting issue, for example, the API responds with the OrderCannotUpdate error.

Add the documents​

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.

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 as Identification, AddressProof or Photo. Custom document types configured on the instance are prefixed with @ (for example, @CustomDoc1). See Add document types.
  • subtype and documentPart (optional): in ICP-Brasil, an Identification document can state which document it is (Rg, Cnh, Dni, CTPS, Passport, RNE, CIN, OAB, CRC, CRM, ProfessionalLicense or Undefined). When subtype is given, documentPart is required: FrontComplete or BackComplete, and also Digital for every subtype except Rg, RNE and Undefined.
  • 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 codeWhen it happens
OrderCannotUpdateThe order's data can no longer be changed because of its status
CannotChangeHolderTypeThe order already has a different holder type
HolderTypeNotAllowedThe order's certificate type does not accept the holder type
HolderFileTypeCannotBeAddedThe holder type does not accept one of the document types sent
UnexpectedHolderFileSubtypeThe 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 FileInfo object: 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"
}

See also​

View as Markdown