Factory bulk issuance
This is the flow for collecting CSRs on a production line and issuing them in one go, up to 1,000 devices per call.
-
Register the shipping list. Send serials, device types and chip IDs (and RTU IDs) to
POST /v1/devices, up to 1,000 at a time. If any item is invalid nothing is saved and the error names the item (e.g.devices.12.chipId). Resending the same list counts existing devices asunchanged. -
Collect CSRs. Each device (its secure element) generates a P-256 private key and a CSR. The private key never leaves the device.
-
Request bulk issuance. Send pairs of
deviceSerialandcsrPemtoPOST /v1/certificates/batch. You get202and a batchidright away. Add anIdempotency-Keyso retries are safe. -
Wait for completion. Poll
GET /v1/batches/{id}every few seconds untilstatusiscompleted. Each item isissued,pending(manual issuance) orfailed(with error code and message). One failure does not stop the others. -
Download and install chains. For each
issueditem, callGET /v1/certificates/{serial}/chainwith itscertificateSerialand write it to the device. -
Mark as shipped. When the device leaves the factory, send
status: "shipped"withPATCH /v1/devices/{serial}.
Example
Section titled “Example”import json, time, uuid, requests
API = "https://api.pki-dev.solar-on.org"s = requests.Session()s.cert = ("client.crt", "client.key") # client certificate (mTLS)s.headers["Authorization"] = f"Bearer {API_KEY}"
# 1. Shipping listdevices = [{"serial": d["serial"], "deviceType": "module", "chipId": d["chip"]} for d in lot]s.post(f"{API}/v1/devices", json={"devices": devices}).raise_for_status()
# 3. Bulk issuance (Idempotency-Key makes retries safe)items = [{"deviceSerial": d["serial"], "csrPem": d["csr"]} for d in lot]r = s.post(f"{API}/v1/certificates/batch", json={"items": items}, headers={"Idempotency-Key": str(uuid.uuid4())})r.raise_for_status()batch_id = r.json()["id"]
# 4. Waitwhile True: batch = s.get(f"{API}/v1/batches/{batch_id}").json() if batch["status"] == "completed": break time.sleep(3)
# 5. Chainsfor item in batch["items"]: if item["status"] == "issued": chain = s.get(f"{API}/v1/certificates/{item['certificateSerial']}/chain").text write_to_device(item["deviceSerial"], chain) elif item["status"] == "failed": print(item["deviceSerial"], item["error"]["code"], item["error"]["message"])# items.json: {"items":[{"deviceSerial":"SN-0001","csrPem":"-----BEGIN CERTIFICATE REQUEST-----\n…"}, …]}BATCH=$(pki -X POST "$PKI_API/v1/certificates/batch" \ -H "Idempotency-Key: $(uuidgen)" -d @items.json | jq -r .id)
until [ "$(pki "$PKI_API/v1/batches/$BATCH" | jq -r .status)" = completed ]; do sleep 3; done
pki "$PKI_API/v1/batches/$BATCH" \ | jq -r '.items[] | select(.status == "issued") | .certificateSerial' \ | while read SERIAL; do pki "$PKI_API/v1/certificates/$SERIAL/chain" -o "$SERIAL.pem"; doneThe pki helper is defined in the Quickstart.
Good to know
Section titled “Good to know”- Limits. Registration and bulk issuance take up to 1,000 items and a 2 MB body. The rate limit is 600 calls per minute per key, so polling every few seconds is plenty.
- Failed items. The usual ones are
DEVICE_NOT_FOUND(not registered),CERTIFICATE_EXISTS(already has a valid certificate) andINVALID_CSR(not P-256 or a bad signature). Fix them and resend just those items. - Manual issuance.
pendingitems becomeapprovedinGET /v1/requests/{requestId}after Solarize approves them.