HTTParty accepts the forward proxy as request options. Keep the service URL as the first argument:

response = HTTParty.get(
  'https://api.example/items',
  http_proxyaddr: 'proxy.example',
  http_proxyport: 8080,
  http_proxyuser: ENV.fetch('PROXY_USER'),
  http_proxypass: ENV.fetch('PROXY_PASSWORD'),
  headers: { 'Authorization' => "Bearer #{ENV.fetch('API_TOKEN')}" },
  open_timeout: 5,
  read_timeout: 15
)
puts response.code

The proxy host and port identify the intermediary. The proxy user and password authenticate there. The Authorization header belongs to the API, whose account can be completely different.

For a proxy without authentication, omit http_proxyuser and http_proxypass. For a public API request on an allowed public route, take an HTTP address from the HTTP proxy list only with no proxy credentials retained in either the request or its class defaults. The host field is passed as a proxy address to Net::HTTP; supply the hostname separately from its port rather than a destination URL or PAC URL.

A wrapper class that includes HTTParty can instead use its http_proxy class method to set defaults. Request options override those defaults for the call that supplies them.

This describes HTTParty's default connection adapter. A custom connection_adapter is responsible for interpreting its options, so inspect that adapter when a valid setting appears to be ignored. Read the HTTP status separately from the parsed API data; successful JSON parsing is not an authentication result.

Аффингæй хæстæг статьялтæ