api_request()

Make an authenticated HTTP request through a saved API integration connection. The integration supplies the auth (OAuth2, HTTP Basic, or token) so you don't hardcode credentials in your script.

Syntax

api_request(connection, url, method, spec?)

Parameters

Name Type Required Description
connection string yes Name of the API integration connection to use.
url string yes The request URL.
method string yes GET, POST, PUT, PATCH, or DELETE.
spec array no headers, query, data.

Returns

A response object from the integration (status, headers, body).

Example

$resp = api_request("Stripe", "https://api.stripe.com/v1/customers", "POST", [
    "data" => ["email" => $record["email"], "name" => $record["name"]]
]);
sys_log("Stripe responded: " . $resp["status"]);

Example output

["status" => 200, "body" => "{ ... }", "headers" => [ ... ]]

Notes

  • Set up the connection first under your account's integrations (OAuth2 / HTTP Basic / Token).
  • Use this instead of curl_request() whenever the endpoint is behind one of your configured integrations — it handles auth and token refresh for you.

See also: curl_request(), Integrations