phpfacebook-php-sdkfacebook-pixel

Facebook Conversions API - AuthorizationException (Invalid parameter)


While triggering the Purchase event after a successful transaction on the payment gateway and a redirection to the website, I'm getting the following error:

Fatal error: Uncaught FacebookAds\Http\Exception\AuthorizationException: Invalid parameter in /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Http/Exception/RequestException.php:174 Stack trace: #0 /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Http/Client.php(215): FacebookAds\Http\Exception\RequestException::create(Object(FacebookAds\Http\Response)) #1 /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Http/Request.php(286): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Api.php(165): FacebookAds\Http\Request->execute() #3 /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Api.php(214): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\ in /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Http/Exception/RequestException.php on line 174

Other events being triggered without any issues with a valid Pixel ID and a token.

$this->api = Api::init($pixel_id, null, $access_token);
$event = (new Event())
                ->setActionSource(ActionSource::WEBSITE)
                ->setEventName('Purchase')
                ->setEventTime(time())
                ->setEventSourceUrl($current_url)
                ->setUserData($user_data);
            
$events = array();
array_push($events, $event);
$request = $this->create_request($events);
// Execute the request
$response = $request->execute();

Solution

  • I had the same problem but found out that the reason to the exception is that a purchase event must have currency and value set.

    $customData = (new CustomData())
            ->setCurrency('USD')
            ->setValue(10);
    

    Then add the custom data to the event:

    ->setCustomData($customData)