# Salesforce + Dizo

> Enrich Salesforce leads with an Apex callout from a record-triggered Flow, using a Named Credential for the Dizo key.

Type: REST recipe — base URL `https://api.dizo.ai/v1`. No native app needed.

## Steps
1. Create an External Credential + Named Credential `Dizo` for `https://api.dizo.ai` with a custom `Authorization` header.
2. Add the invocable Apex class below.
3. Call it from a record-triggered Flow on Lead create (run asynchronously).

## DizoEnrich.cls
```
public with sharing class DizoEnrich {
  @InvocableMethod(label='Dizo: enrich lead' callout=true)
  public static void run(List<Id> leadIds) {
    for (Lead l : [SELECT Id, Email FROM Lead WHERE Id IN :leadIds]) {
      HttpRequest req = new HttpRequest();
      req.setEndpoint('callout:Dizo/v1/people/enrich');
      req.setMethod('POST');
      req.setHeader('Content-Type', 'application/json');
      req.setHeader('Idempotency-Key', l.Id);
      req.setBody(JSON.serialize(new Map<String,Object>{ 'email' => l.Email, 'max_credits' => 2 }));
      HttpResponse res = new Http().send(req);
      if (res.getStatusCode() != 200) continue; // 404 = not found, not charged
      Map<String,Object> p = (Map<String,Object>)((Map<String,Object>)JSON.deserializeUntyped(res.getBody())).get('person');
      l.Title = (String)p.get('title');
    }
    // update leads outside the loop in production code
  }
}
```

## Notes
- Run callouts asynchronously (Flow async path or Queueable) and respect Salesforce callout limits; for large backfills use Dizo batch and import the results file.

## Related API docs
- [/docs/people-enrich](https://dizo.ai/docs/people-enrich.md)
- [/docs/batch](https://dizo.ai/docs/batch.md)
