Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Webflow

WebflowClient::rest_requestpublicWC 1.0

Makes a GET request to the Webflow REST API.

Method of the class: WebflowClient{}

No Hooks.

Returns

Object|Array|\WP_Error. Decoded JSON response (object or array) or WP_Error on failure.

Usage

$WebflowClient = new WebflowClient();
$WebflowClient->rest_request( $path, $query_params );
$path(string) (required)
The API path relative to API base (e.g., '/sites/{id}/products').
$query_params(array)
Optional query parameters.
Default: array()

WebflowClient::rest_request() code WC 11.0.1

public function rest_request( string $path, array $query_params = array() ) {
	$credentials = $this->get_credentials();
	if ( is_wp_error( $credentials ) ) {
		return $credentials;
	}

	$endpoint = self::API_BASE . $path;
	if ( ! empty( $query_params ) ) {
		$endpoint = add_query_arg( $query_params, $endpoint );
	}

	$request_args = array(
		'method'  => 'GET',
		'headers' => array(
			'Authorization' => 'Bearer ' . $credentials['access_token'],
			'Accept'        => 'application/json',
		),
		'timeout' => 60,
	);

	for ( $attempt = 0; $attempt <= self::MAX_RETRIES; $attempt++ ) {
		$response      = wp_remote_request( $endpoint, $request_args );
		$response_code = is_wp_error( $response ) ? 0 : (int) wp_remote_retrieve_response_code( $response );

		if ( 429 !== $response_code ) {
			return $this->process_response( $response, $path );
		}

		// Rate limited: back off and retry until the budget is exhausted. The final
		// attempt falls through to the retry-budget error below rather than retrying.
		if ( $attempt < self::MAX_RETRIES ) {
			$retry_after = (int) wp_remote_retrieve_header( $response, 'retry-after' );
			$delay       = $retry_after > 0 ? $retry_after : ( 2 ** $attempt );
			$delay       = min( 30, max( 1, $delay ) );
			if ( function_exists( 'sleep' ) ) {
				sleep( $delay );
			}
		}
	}

	return new \WP_Error( 'api_error', "REST request to {$path} exceeded retry budget after repeated 429 responses." );
}