Step 6: Assign Datasets to Questions

Now that we've created our question, we need to assign the right datasets to the specified dataset macros in order to run it.

All of the tutorial datasets are provisioned from our organization, so you do not need to rely on partners to assign datasets. We will work with the following macro-to-dataset mapping:

  • adlog = Synthetic Publisher AdLogs Data
  • pubmap = Synthetic Publisher RampID Mapping Data
  • transaction = Synthetic Advertiser Transactions Data
  • rmnmap = Synthetic Advertiser RampID Mapping Data

(Optional) Get Information on Available Organizations and Macros to Assign

When programmatically creating questions and assigning datasets, you may not have the necessary IDs.

The following example uses the cleanrooms and cleanroom-questions endpoints to get required IDs.

For more information, see the following calls:

Get Organizations

# Get possible organizations to assign datasets in the clean room. Note: This will be empty for your API tutorial clean room because there are no partners.

## cleanroom_id = "<YOUR cleanroom id>"

## response = cleanroom_api.get_cleanroom_partners(cleanroom_id)
## print(json.dumps(response, indent=4))

# Get dataset macros which need to be assigned for a question for the questions in a given clean room

## response = cleanroom_api.get_clean_room_questions(cleanroom_id)
## print(json.dumps(response, indent=4))

Assign Dataset Ownership to the Question

# Assign datasets ownership to the question we created in step 5.

# Be sure to replace the cleanroom_question_id with the CRQ ID. This is NOT the question ID from step 5. It can be found in the URL when editing the question or by getting clean room questions.

# cleanroom_question_id = "<YOUR cleanroom_question_id>"

# Define assignment details
# assign_cleanroom_questions_dataset_requests = [
#    {
#        "organizationId" : "<YOUR organization id>",
#        "macro" : "adlog"
#    },
#    {
#        "organizationId" : "<YOUR organization id>",
#        "macro" : "transaction"
#    },
#    {
#        "organizationId" : "<YOUR organization id>",
#        "macro" : "pubmap"
#    },
#    {
#        "organizationId" : "<YOUR organization id>",
#        "macro" : "rmnmap"
#    }
# ]

# response = cleanroom_api.create_cleanroom_question_datasets_owners(cleanroom_question_id,assign_cleanroom_questions_dataset_requests)

    # Print formatted response
# print(json.dumps(response, indent=4))

Configure Clean Room Question Datasets

We authored our question based on known datasets, so ownership assignment is already taken care of for this question. We are now ready to "manage datasets" and confirm the assignments for the question.

This uses the POST /cleanroom-questions/{cleanroomQuestionId}/datasets call, which is the equivalent of "opting-in" to allow a question to run.

Define Clean Room Question and Clean Room ID

# Define clean room question and clean room ID. Replace this with the clean room question ID in your API tutorial clean room.

cleanroom_question_id = "<YOUR cleanroom_question_id>"

# Define cleanroomQuestionDatasetDetails

cleanroom_question_dataset_details = [
    {
        "id" : cleanroom_question_id,
        "datasetId" : "<YOUR dataset id>",
        "macro" : "transaction",
        # Note fields are empty here because we did not use field macros in our question. If using field macros, the format would be macro name and actual value for the field name from the dataset.
        "fields" : []
    },
    {
        "id" : cleanroom_question_id,
        "datasetId" : "<YOUR dataset id>",
        "macro" : "pubmap",
        # Note fields are empty here because we did not use field macros in our question. If using field macros, the format would be macro name and actual value for the field name from the dataset.
        "fields" : []
    },
    {
        "id" : cleanroom_question_id,
        "datasetId" : "<YOUR dataset id>",
        "macro" : "rmnmap",
        # Note fields are empty here because we did not use field macros in our question. If using field macros, the format would be macro name and actual value for the field name from the dataset.
        "fields" : []
    }
]

# Perform configuration

response = cleanroom_api.create_cleanroom_question_datasets(cleanroom_question_id,cleanroom_question_dataset_details)

print(json.dumps(response, indent=4))