fix(leadmail): drop leading slash on post path so Faraday respects /api/v1 prefix
Some checks failed
Lock Threads / action (push) Has been cancelled

Faraday treats a leading slash on the request path as absolute from the
host root, replacing the path component of the connection URL. With
LEADMAIL_API_URL=https://mail.leadmagnet.dev/api/v1 and post('/emails/send'),
the resulting URL was https://mail.leadmagnet.dev/emails/send — missing
/api/v1, getting an HTML 404 from the LeadMail dispatcher.

Drop the leading slash so the path is appended relative to the prefix:
  https://mail.leadmagnet.dev/api/v1/emails/send

Also add Accept: application/json to mirror the documented curl example
and avoid any content-negotiation surprises (HTML error pages vs JSON
error responses).
This commit is contained in:
netlas
2026-04-28 10:22:38 +03:00
parent 8df7a1192c
commit 35c6ffc15e

View File

@@ -7,7 +7,7 @@ class LeadmailDelivery
def deliver!(message)
payload = build_payload(message)
response = http_client.post('/emails/send', payload.to_json)
response = http_client.post('emails/send', payload.to_json)
unless response.success?
raise LeadmailDeliveryError, "LeadMail API error: #{response.status} - #{response.body}"
@@ -104,7 +104,8 @@ class LeadmailDelivery
url: settings[:api_url],
headers: {
'Authorization' => "Bearer #{settings[:token]}",
'Content-Type' => 'application/json'
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
)
end