Create a Performance Max campaign with mutate

This guide assumes that you create the entire campaign in a single atomic request, rather than creating each individual entity in separate requests. This means that you'll need to set up and use temporary IDs to link resources to each other.

With this in place, create an array to hold all the operations:

const operations = [];

You will frequently need the customer ID for the customer you're making the campaign in, since it's required in every resource name.

const customerId = AdsApp.currentAccount().getCustomerId();

Each time you want to create a new operation, you will use the next temp ID in the resource name, so that you can reference this object later, and insert the object created into the array:

const newOperation = {
    [OPERATION_TYPE_VARIES]: {
        create: {
            resourceName: `customers/${customerId}/[EXACT_PATH_VARIES]/${getNextTempId()}`
            // Other fields, relevant to the resource being created.
        }
    }
}
operations.push(newOperation);

You can read more and see an example operation on the Google Ads API REST mutate documentation.

Once you have constructed all of our operations, execute them in a single batch:

AdsApp.mutateAll(operations);