Amplia Reg quick reference
The main facts about the Amplia Reg API on one page, with links to the full articles.
What it is for
Amplia Reg is the registration authority (RA) that works with Amplia, the certification authority (CA). Your application creates the certificate order through the REST API. Registration agents validate the identity of the holder and approve the order in the control panel. Then the holder issues the certificate through the issue link.
| Use instead | When |
|---|---|
| Amplia | Your application issues certificates directly on the CA, without identity validation by registration agents. |
For the path of an order and its statuses, see How certificate issuance works.
Install
| Language | Package | Registry |
|---|---|---|
| .NET | Lacuna.AmpliaRegNg.Client (latest: 8.11.0) | NuGet |
Install it with dotnet add package Lacuna.AmpliaRegNg.Client. The library works on .NET Framework 4.6.1 or later and on .NET Core 2.0 or later. See Use the .NET library.
In other languages, call the REST API with any HTTP client. The guides show each call in .NET, REST and curl.
Configuration and authentication
- Endpoint: the address of the Amplia Reg instance. It is the same as the address of the control panel, for example
https://ampliareg.yourcompany.com. If you do not know the address, ask the administrator of the instance. - API key: every request sends the key in the
X-Api-Keyheader, in the formatapplication-name|<key>. Create an application in Applications in the control panel and add a key. The key shows only one time. See Get started. - Roles: an application that creates and cancels orders needs the Sales app role. An application that creates pre-approved orders needs the Electronic registration authority role. See Application roles.
- Subscription: each application belongs to a CA or to an RA, and its calls apply to that subscription. See Application subscription.
- Test environment: Amplia Reg has no public test environment. The calls create real orders on the instance. Cancel your test orders.
In .NET, create the service with the endpoint and the API key:
using Lacuna.AmpliaRegNg.Client;
var ampliaRegService = AmpliaRegServiceFactory.GetService(new AmpliaRegOptions() {
Endpoint = "https://ampliareg.yourcompany.com",
ApiKey = "your-app|YOUR_KEY",
});
In ASP.NET Core, use services.AddAmpliaReg() and get an IAmpliaRegService through dependency injection.
Core operations
The blocks below are in C#, with the .NET client library. The Full example in .NET puts the operations together in a console application.
Create an order
POST /api/brazil/orders creates an ICP-Brasil certificate order. First, list the certificate types with GET /api/certificate-types and select one. The number in the response identifies the order in the other calls. Orders for Paraguay, Cabo Verde and SSL use the route of their format, for example POST /api/paraguay/orders. See Create an order and Create orders of other formats.
var order = await ampliaRegService.CreateOrderAsync(new OrderCreateRequest<BrazilOrderCreateParameters> {
CertificateType = CertificateTypeReference.FromCode("ECPFA1"),
IssueType = IssueTypes.Presential,
Parameters = new BrazilOrderCreateParameters {
Cpf = "07917307000",
Name = "Holder Name",
BirthDate = "1995-10-15",
},
Validity = PeriodModel.FromYears(1),
});
Verify the holder before the order
There are three optional checks. POST /api/rfb-query checks the CPF with the Brazilian Federal Revenue Service (RFB). POST /api/bio-enrollment-check tells if the holder has a biometric enrollment in PSBio. GET /api/users/phone-number/validation validates a phone number. If the instance has the RFB query configured, the order creation also does the query. See Verify the holder.
var rfbResponse = await ampliaRegService.PerformRfbQueryAsync("07917307000", "1995-10-15");
if (rfbResponse.Approved) {
// Use rfbResponse.Name when you create the order
}
Pre-fill the holder data
PUT /api/brazil/orders/{number}/holder/pre-fill sends the address and the contact of the holder, so the agent does not type them. The order must be in WaitingValidation. See Pre-fill the holder data.
await ampliaRegService.PreFillHolderAsync(order.Number, new UpdateHolderInformationRequest<BrazilUpdateHolderParameters> {
Parameters = new BrazilUpdateHolderParameters {
Address = new BrazilHolderAddressRequest {
ZipCode = "70000-000",
Street = "Rua Exemplo",
Number = "100",
District = "Centro",
City = "Brasília",
StateCode = "DF",
Country = "Brazil",
},
},
Contact = new ContactData {
Phone = "+5511999990000",
EmailAddress = "holder@example.com",
},
});
Send holder documents
POST /api/orders/{number}/holder-files adds documents to the order, for example the driver's license (CNH). In the REST API, first upload each file with POST /api/uploads. The .NET library uploads the files for you. See Add holder documents to an order.
await ampliaRegService.AddHolderFilesAsync(
order.Number,
new List<HolderFileReference2> {
new HolderFileReference2 {
Type = HolderFileTypes.Identification.ToString(),
Subtype = HolderFileSubtypes.Cnh,
DocumentPart = DocumentParts.FrontComplete,
File = FileReference.FromFile(@"C:\AppData\Documents\cnh.pdf"),
},
},
HolderTypeReference.FromCode("PF")
);
Create a pre-approved order
POST /api/brazil/orders/pre-approved creates an order that does not go to the registration agents. The order starts in WaitingIssue. The response has the issue keys and the issue links. With NotifySubject, Amplia Reg sends the link to the holder by email and SMS. See Creating pre-approved orders.
var response = await ampliaRegService.CreatePreApprovedOrderAsync(new CreatePreApprovedOrderOptions2<CreatePreApprovedOrderBrazilParameters>() {
CertificateType = CertificateTypeReference.FromCode("ECPFA1"),
Parameters = new CreatePreApprovedOrderBrazilParameters() {
Cpf = "07917307000",
Name = "Holder Name",
},
Contact = new ContactData() {
EmailAddress = "holder@example.com",
Phone = "+5511999990000",
},
NotifySubject = true,
});
Receive webhooks
Register the webhook URL on the application, in the Applications menu of the control panel. Amplia Reg sends a POST with JSON at each status change of the orders of the application, with type set to OrderStatusChanged. It sends the registered secret in a header, for example Authorization: Bearer <secret>. Respond with 2xx. Notifications can arrive more than one time or out of order. To get the changes that you missed, use GET /api/orders/status-transitions. See Register and receive webhooks and Event reference.
app.MapPost("/webhooks/amplia-reg", async (HttpRequest request) => {
var header = Encoding.UTF8.GetBytes(request.Headers.Authorization.ToString());
if (!CryptographicOperations.FixedTimeEquals(header, expectedHeader)) {
return Results.Unauthorized();
}
using var body = await JsonDocument.ParseAsync(request.Body);
var root = body.RootElement;
if (root.GetProperty("type").GetString() == "OrderStatusChanged") {
var change = root.GetProperty("orderStatusTransitionModel");
var status = change.GetProperty("status").GetString();
// Update the order change.GetProperty("orderNumber") in your system
}
return Results.Ok();
});
Cancel an order
POST /api/orders/{number}/cancellation cancels an order that is not issued yet. The reason, in description, is required. See Cancel an order.
await ampliaRegService.CancelOrderAsync("800-005-520", new OrderCancelRequest() {
Description = "Cancellation requested by customer",
});
Errors
The API responds with an HTTP status code: 400 for a required field that is missing or has an incorrect value, 401 for a missing or incorrect API key, 403 when the application does not have the necessary role, and 422 for an API error. With 422, the body is an ErrorModel with code and message. Test the code, not the message. See API authentication and errors.
The first errors that an integrator usually gets:
403when you create an order: the application does not have the Sales app role.RegistrationAuthorityRequired: the application belongs to a CA, and the order does not identify the RA.CertificateTypeNotFound: the certificate type code does not exist on the CA of the application.RfbQueryNotApprovedandRfbQueryNameMismatch: the Federal Revenue Service did not approve the holder data, or the name is not the name in its records.OrderNotFound: the order number does not exist.
In .NET, the library throws AmpliaRegException for an API error, with the code in the Code property. See Error codes and Troubleshooting.