Skip to content

Pausing Campaigns, returns invalid AccountId error #191

Open
@BryanYeh

Description

@BryanYeh

I am doing this in Laravel.

I wanted to test pause a campaign on one of the active campaign I have in Bing Ads. The error I am getting is invalid AccountId, but I know for sure the AccountId is valid I downloaded a campaigns report.

I tested with different AccountIds and Campaigns, none of them works, just the same error.
I even double checked the code that its only related to campaigns.

Below are is my code and the SOAP error:

TestPauseCampaign.php

<?php

namespace App\Console\Commands\Bing;

use Illuminate\Console\Command;

use App\Services\BingAds;
use Illuminate\Support\Facades\Log;
use Microsoft\BingAds\Auth\ServiceClientType;
use Microsoft\BingAds\Auth\ServiceClient;
use Microsoft\BingAds\Auth\ApiEnvironment;
use Microsoft\BingAds\v13\CampaignManagement\UpdateCampaignsRequest;
use Microsoft\BingAds\V13\CampaignManagement\Campaign;
use Microsoft\BingAds\V13\CampaignManagement\CampaignStatus;
use SoapFault;

class TestPauseCampaign extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:test-pause-campaign';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Execute the console command.
     */
    public function handle()
    {
        $bing = new BingAds();
        $authorizationData = $bing->getAuthorizationData();
        $serviceClient = (new ServiceClient(ServiceClientType::CampaignManagementVersion13, $authorizationData, ApiEnvironment::Production));

        try {
            $request = new UpdateCampaignsRequest();
            $request->AccountId = 14191111;

            Log::info($request->AccountId);

            $campaign = new Campaign();
            $campaign->Id = '34234234';
            $campaign->Status = CampaignStatus::Paused;

            $request->Campaigns = [$campaign];

            $response = $serviceClient->GetService()->UpdateCampaigns($request);

            Log::info($response);;
        } catch (SoapFault $e) {
            // Handle SOAP fault

            // Access the fault code
            $faultCode = $e->faultcode;

            // Access the fault string (error message)
            $faultString = $e->getMessage();

            // Access the fault details, if available
            $faultDetails = $e->detail; // This may contain more specific error information

            // Log or display the fault details for debugging
            // You can use var_dump or print_r to view the details
            Log::error(print_r($faultCode, true));
            Log::error(print_r($faultString, true));
            Log::error(print_r($faultDetails, true));

            // Handle the error as needed
            // You can log the details, display an error message, or take other actions
        } catch (\Throwable $th) {
            //throw $th;
            Log::error($th);
        }

    }
}

Error Log

[2023-09-25 22:21:10] local.INFO: 14191111  
[2023-09-25 22:21:10] local.ERROR: s:Server  
[2023-09-25 22:21:10] local.ERROR: Invalid client data. Check the SOAP fault details for more information. TrackingId: 604ded6c-ffff-ffff-xxxx-dca58bc456f2.  
[2023-09-25 22:21:10] local.ERROR: stdClass Object
(
    [AdApiFaultDetail] => stdClass Object
        (
            [TrackingId] => 604ded6c-18fa-46df-bf9f-dca58bc456f2
            [Errors] => stdClass Object
                (
                    [AdApiError] => stdClass Object
                        (
                            [Code] => 119
                            [Detail] => 
                            [ErrorCode] => InvalidAccountId
                            [Message] => The account ID is invalid.
                        )
                )
        )
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions