using rest api to create a Demand Gen Gampain. error: The operation is not allowed for the given context.

161 views
Skip to first unread message

Jingqiang Liu

unread,
Mar 19, 2024, 6:50:24 AM3/19/24
to Google Ads API and AdWords API Forum
campaign type: DISCOVERY

biddingStrategy:  MAXIMIZE_CONVERSIONS

maximizeConversions: 
cpcBidCeilingMicros=10000.
 cpcBidFloorMicros=10000
 targetCpaMicros=10000


the error is:

 {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.ads.googleads.v15.errors.GoogleAdsFailure",
        "errors": [
          {
            "errorCode": {
              "contextError": "OPERATION_NOT_PERMITTED_FOR_CONTEXT"
            },
            "message": "The operation is not allowed for the given context.",
            "trigger": {
              "int64Value": "10990265602"
            },
            "location": {
              "fieldPathElements": [
                {
                  "fieldName": "operations",
                  "index": 0
                },
                {
                  "fieldName": "create"
                },
                {
                  "fieldName": "bidding_strategy"
                }
              ]
            }
          },
          {
            "errorCode": {
              "campaignError": "CANNOT_ATTACH_TO_BIDDING_STRATEGY"
            },
            "message": "Cannot attach the campaign to this bidding strategy.",
            "trigger": {
              "int64Value": "10990265602"
            },
            "location": {
              "fieldPathElements": [
                {
                  "fieldName": "operations",
                  "index": 0
                },
                {
                  "fieldName": "create"
                },
                {
                  "fieldName": "bidding_strategy"
                }
              ]
            }
          }
        ],
        "requestId": "tBZu_Kz24vxT2UfKWkElvQ"
      }
    ]
  }
}

Google Ads API Forum Advisor

unread,
Mar 19, 2024, 12:42:47 PM3/19/24
to liu...@ctw.inc, adwor...@googlegroups.com

Hi,

Thank you for reaching out to the Google Ads API support team.

Upon checking the provided partial logs, I found that you are trying to create a Demand Gen Campaign via the Google Ads API, but you are getting a CANNOT_ATTACH_BIDDING_STRATEGY_TO_CAMPAIGN error. This error is a type of OPERATION_NOT_PERMITTED_FOR_CONTEXT error. This error indicates that you cannot attach a bidding strategy to a campaign. Please note that there are a few minimum requirements that should be met before creating a demand-gen campaign. I also suggest you please check the Create campaign and bidding strategy documentation to know how to create a campaign and the bidding strategy. You can also check the Bidding Strategy Types documentation to know the supported bidding strategies via the Google Ads API.

However, the provided logs are not complete as there is no request body presented in the logs. So if the issue still persists even after following the above documentation and minimum requirements, please provide us with complete API logs (request and response with request-id and request header) generated at your end.

You can send the details via the Reply privately to the author option or a direct private reply to this email. 

This message is in relation to case "ref:!00D1U01174p.!5004Q02s03Jb:ref" (ADR-00227828)

Thanks,
 
Google Logo Google Ads API Team


Jingqiang Liu

unread,
Mar 21, 2024, 5:00:18 AM3/21/24
to Google Ads API and AdWords API Forum
Thanks for your feedback. this is error message:

api: {
  "error": {

    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.ads.googleads.v15.errors.GoogleAdsFailure",
        "errors": [
          {
            "errorCode": {
              "contextError": "OPERATION_NOT_PERMITTED_FOR_CONTEXT"
            },
            "message": "The operation is not allowed for the given context.",
            "location": {
              "fieldPathElements": [
                {
                  "fieldName": "operations",
                  "index": 0
                },
                {
                  "fieldName": "update"
                },
                {
                  "fieldName": "maximize_conversions"
                },
                {
                  "fieldName": "target_cpa_micros"
                }
              ]
            }
          }
        ],
        "requestId": "Bm2xH7-FdyitEFfHMPfBAg"
      }
    ]
  }
}

requestId: Bm2xH7-FdyitEFfHMPfBAg


When create Campaign that type is discovery and uses  maximizeConversions successfully. and then  I want to update this campaign's maximizeConversions,so  I get this error.

create request: {
"partialFailure": false,
"operations": [
{
"create": {
"name": "Campaign_name",
"campaign_budget": "customers/id/campaignBudgets/id",
"advertising_channel_type": "DISCOVERY",
"status": "PAUSED",
"selective_optimization": null,
"maximize_conversions": {}
}
}
],
"responseContentType": "MUTABLE_RESOURCE",
"validateOnly": false
}
========================
upadte request: {
"partialFailure": false,
"operations": [
{
"update": {
"maximizeConversions": {
"targetCpaMicros": "100000"
},
"resourceName": "customers/my_id/campaigns/my_id"
},
"updateMask": "maximizeConversions.targetCpaMicros"
}
],
"responseContentType": "MUTABLE_RESOURCE",
"validateOnly": true
}

Jingqiang Liu

unread,
Mar 21, 2024, 5:00:23 AM3/21/24
to Google Ads API and AdWords API Forum
I using rest api create customConversionGoals depend on  https://developers.google.com/google-ads/api/rest/reference/rest/v16/customers.customConversionGoals/mutate。I want to set up that for my campaign, could u tell me how set

在2024年3月20日星期三 UTC+9 01:42:47<Google Ads API Forum Advisor> 写道:

Google Ads API Forum Advisor

unread,
Mar 21, 2024, 10:44:23 AM3/21/24
to liu...@ctw.inc, adwor...@googlegroups.com
Hi,

Upon checking the provided logs, I would like to inform you that the logs that you have provided are incomplete and do not contain the request header and customer ID in them. So, In order to debug your issue further, kindly provide us with the complete API logs (request and response with request-id and request header) generated at your end.

Also, I would recommend you refer to the documents Campaign-level Conversion Goals and custom_conversion_goal to get more information on how to create customConversionGoals for your campaign.

Jingqiang Liu

unread,
Mar 22, 2024, 4:56:30 AM3/22/24
to Google Ads API and AdWords API Forum
Thanks for your reply

Request-id: LWPZzJZS1MzPNqPOxyPtgA


Request :Sending post content to https://googleads.googleapis.com/v15/customers/8401942066/campaigns:mutate : {"partialFailure":false,"operations":[{"update":{"maximizeConversions":{"targetCpaMicros":"100000"},"resourceName":"customers/8401942066/campaigns/21122737618"},"updateMask":"maximizeConversions.targetCpaMicros"}],"responseContentType":"MUTABLE_RESOURCE","validateOnly":true}

Response: {
"body": {
"l": "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Request contains an invalid argument.\",\n \"status\": \"INVALID_ARGUMENT\",\n \"details\": [\n {\n \"@type\": \"type.googleapis.com/google.ads.googleads.v15.errors.GoogleAdsFailure\",\n \"errors\": [\n {\n \"errorCode\": {\n \"contextError\": \"OPERATION_NOT_PERMITTED_FOR_CONTEXT\"\n },\n \"message\": \"The operation is not allowed for the given context.\",\n \"location\": {\n \"fieldPathElements\": [\n {\n \"fieldName\": \"operations\",\n \"index\": 0\n },\n {\n \"fieldName\": \"update\"\n },\n {\n \"fieldName\": \"maximize_conversions\"\n },\n {\n \"fieldName\": \"target_cpa_micros\"\n }\n ]\n }\n }\n ],\n \"requestId\": \"LWPZzJZS1MzPNqPOxyPtgA\"\n }\n ]\n }\n}\n"
},
"code": 400,
"status_text": "Bad Request",
"headers": [
{
"name": "Transfer-Encoding",
"value": "chunked"
},
{
"name": "Alt-Svc",
"value": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"
},
{
"name": "Server",
"value": "ESF"
},
{
"name": "X-Content-Type-Options",
"value": "nosniff"
},
{
"name": "Date",
"value": "Fri, 22 Mar 2024 01:20:16 GMT"
},
{
"name": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"name": "Cache-Control",
"value": "private"
},
{
"name": "Content-Encoding",
"value": "gzip"
},
{
"name": "Vary",
"value": "Referer"
},
{
"name": "Vary",
"value": "X-Origin"
},
{
"name": "Vary",
"value": "Origin"
},
{
"name": "X-XSS-Protection",
"value": "0"
},
{
"name": "Request-Id",
"value": "LWPZzJZS1MzPNqPOxyPtgA"
},
{
"name": "Content-Type",
"value": "application/json; charset=UTF-8"
}
],
"history": [],
"request": {
"method": "POST",
"uri": {
"scheme": "https",
"authority": {
"host_segment": {
"encoding": {}
}
},
"path_segments": {
"segments": [
{
"v": "v15",
"encoding": {}
},
{
"v": "customers",
"encoding": {}
},
{
"v": "8401942066",
"encoding": {}
},
{
"v": "campaigns:mutate",
"encoding": {}
}
]
},
"query_segments": [],
"absolute": true,
"relative": false
},
"headers": [
{
"name": "Accept-Encoding",
"value": "gzip, deflate"
},
{
"name": "Content-Type",
"value": "application/json"
},
{
"name": "Content-Length",
"value": "275"
},
{
"name": "developer-token",
"value": "mpoXG2hU6yBfE5cly5FQuw"
},
{
"name": "login-customer-id",
"value": "8421237550"
},
{
"name": "Authorization",
"value": "Bearer ya29.a0Ad52N3_NFoO8W-xcxlfqVppXftuO3QEN_aP_TUy8_AOT3qdQZt-i5j6oK9W8g5c9AQkNfha1Au9AQsrgB4Yim7VBrkrTnt68ol0fv04ACIiufzGO5d_3vM8zrDeY_IT5nfypCm7GQnAyHf5_8zcdtGlp_bDrAQkngqbKrwaCgYKAVISARASFQHGX2MiOkvFgGT9BTxYSJ9eoEwFjQ0173"
},
{
"name": "Cookie",
"value": ""
}
]
},
"success": false,
"client_error": true,
"server_error": false,
"redirect": false,
"200": false
}

Google Ads API Forum Advisor

unread,
Mar 22, 2024, 11:29:16 AM3/22/24
to liu...@ctw.inc, adwor...@googlegroups.com

Hi, 

Could you please provide the following information to us? So that we can check from our end and assist you accordingly.

  • Please provide the request body that you passed as a parameter while creating the campaign, as in the provided logs you have removed the campaign budget resource name.
  • In the update operation, you are also removed from the campaign resource name. So please provide the request as it is without removing anything from the request body.
Reply all
Reply to author
Forward
0 new messages