create operation PERFORMANCE MAX campaign

190 views
Skip to first unread message

Jip Veerbeek

unread,
Oct 26, 2022, 10:41:43 AM10/26/22
to Google Ads API and AdWords API Forum
Hello, I am trying to create an Performance Max Campaign with the google ads API. I am building the request in php and I have managed to create an Search campaign. I have tried multiple things to transform my code to make an  Performance Max Campaign without succes. I will send the code along and I hope someone can help me.


snel.php

Jip Veerbeek

unread,
Oct 26, 2022, 10:42:43 AM10/26/22
to Google Ads API and AdWords API Forum
<?php

//1 acces token aanmaken

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://www.googleapis.com/oauth2/v3/token?grant_type=refresh_token&client_id=12345678910&client_secret=asecret',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json',
    'Content-length: 0'
  ),
));

//1 code
$response = curl_exec($curl);
$httpcode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($httpcode == 200) {
    $response = json_decode($response, true);
    $accesToken = $response['access_token'];
    $fullAccesToken = 'Authorization: Bearer ' . $accesToken;
    //print_r($accesToken);

    //2 budget id aanmaken

    $curl2 = curl_init();

    curl_setopt_array($curl2, array(
    CURLOPT_URL => 'https://googleads.googleapis.com/v11/customers/123456789/campaignBudgets:mutate',
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => '',
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 0,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS =>'{
    "operations": [
    {
        "create": {
        "name": "My Campaign Budget ysdwpnzgs",
        "amountMicros": 500000
        }
    }
    ]
    }',
    CURLOPT_HTTPHEADER => array(
        'Content-Type: application/json',
        'developer-token: ',
        'login-customer-id: 123456789',
        $fullAccesToken
    ),
    ));

    //2 code
    $response2 = curl_exec($curl2);
    $httpcode2 = curl_getinfo($curl2, CURLINFO_HTTP_CODE);

    if ($httpcode2 == 200) {
        $response2 = json_decode($response2, true);
        $budgetId = $response2['results'][0]['resourceName'];
        print_r($budgetId);

        //3 Create campaign

        $curl3 = curl_init();

        curl_setopt_array($curl3, array(
        CURLOPT_URL => 'https://googleads.googleapis.com/v11/customers/123456789/campaigns:mutate',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 0,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_POSTFIELDS =>'{
        "operations": [
            {
            "create": {
                "name": "An campaign testt28",
                "status": "PAUSED",
                "campaignBudget": "' . $budgetId . '",
                "advertisingChannelType": "SEARCH",
                "networkSettings": {
                "targetGoogleSearch": true,
                "targetSearchNetwork": true,
                "targetContentNetwork": true,
                "targetPartnerSearchNetwork": false
                },
                "target_spend": {}
            }
            }
        ]
        }',
        CURLOPT_HTTPHEADER => array(
            'Content-Type: application/json',
            'developer-token: ',
            'login-customer-id: 123456789',
            $fullAccesToken
        ),
        ));

        //3 code
        $response3 = curl_exec($curl3);
        $httpcode3 = curl_getinfo($curl3, CURLINFO_HTTP_CODE);
        print_r($response3);
        // if ($httpcode3 == 200) {
        //     $response3 = json_decode($response3, true);
        //     $campaignId = $response3['results'][0]['resourceName'];
        //     print_r($campaignId);
        // }


        // //foutcode
        // else {
        //     echo 'fout bij 3';
        // }

    }

    else {
        echo 'fout bij 2';
    }
}
else {
    echo 'fout bij 1';

Google Ads API Forum Advisor

unread,
Oct 26, 2022, 11:29:51 AM10/26/22
to jip.ve...@gmail.com, adwor...@googlegroups.com
Hello,

Thanks for reaching out. I can see in your request that the advertisingChannelType is set to 'SEARCH'. You should set this type to 'PERFORMANCE_MAX'. 

I would recommend using the PHP client library, which includes a PHP example for creating Performance Max campaigns

Regards,

Google Logo
Matt
Google Ads API Team
 


ref:_00D1U1174p._5004Q2foOVp:ref

Jip Veerbeek

unread,
Oct 27, 2022, 3:22:09 AM10/27/22
to Google Ads API and AdWords API Forum
Hello, 

thanks for the fast response. 
Is there also an Curl request example on how to add a Performance Max Campaign? This would help me a lot becouse I would like to test it in postman.

Regards,

Jip Veerbeek

Google Ads API Forum Advisor

unread,
Oct 27, 2022, 5:59:16 AM10/27/22
to jip.ve...@gmail.com, adwor...@googlegroups.com

Hi Jip,

Thanks for getting back to us.

You may use the CURL below to create a PMAX campaign:

curl -f --request POST "https://googleads.googleapis.com/v${API_VERSION}/customers/${CUSTOMER_ID}/campaigns:mutate" \

--header "Content-Type: application/json" \

--header "developer-token: ${DEVELOPER_TOKEN}" \

--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \

--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \

--data "{

'operations': [

  {

    'create': {

     'resourceName': "customers/<your customer id>/campaigns/-1",

      'status': 'PAUSED',

      'advertisingChannelType': 'PERFORMANCE_MAX',

     'biddingStrategyType': 'MAXIMIZE_CONVERSION_VALUE',

      'maximizeConversionValue': {

        'targetRoas': '0.5'

      },

     'name': 'My first PMAX campaign',

      'campaignBudget': "customers/<your customer id>/campaignBudgets/<your campbudget id>",

      'urlExpansionOptOut': false

    }

  }

]

}

"

 

Let me know if this helps.

Regards,

Google Logo
Yasar
Google Ads API Team
 


ref:_00D1U1174p._5004Q2foOVp:ref

Jip Veerbeek

unread,
Oct 27, 2022, 6:37:51 AM10/27/22
to Google Ads API and AdWords API Forum
Hello,

Thanks for the response. This helps me a lot but I am running into an issue. If I try to send the request I get the error: CAMPAIGN_CANNOT_USE_SHARED_BUDGET. I dont understand why I get this error becouse the budget isn't shared. Do you know how I can fix this?

Schermafbeelding 2022-10-27 123611.jpg

Regards,

Jip Veerbeek

Google Ads API Forum Advisor

unread,
Oct 27, 2022, 10:13:22 AM10/27/22
to jip.ve...@gmail.com, adwor...@googlegroups.com
Hi Jip,

Thank you for your reply. I'm also a member of the Google Ads API support team and allow me to assist you here. 

Upon checking your error message "CAMPAIGN_CANNOT_USE_SHARED_BUDGET", it appears that you are using a campaign budget that is configured as "shared". However, I am afraid that the campaign budget that you should use is configured as "not shared" as according to this document. With this, to help you identify the campaign budget that you can use for the performance max campaign, you can use campaign_budget and include the campaign_budget.explicitly_shared. The value that will be returned by the campaign_budget.explicitly_shared is "false" for the campaign budget that is not shared.

Best regards,
Google Logo
Jinky
Google Ads API Team
 


ref:_00D1U1174p._5004Q2foOVp:ref

Jip Veerbeek

unread,
Oct 28, 2022, 3:12:23 AM10/28/22
to Google Ads API and AdWords API Forum
Thnx
Reply all
Reply to author
Forward
0 new messages