import requests import json # Define your SFMC API credentials and endpoint client_id = 'mdjjjo4s6tiqe1hxtsg6ws6p' client_secret = 'EJ51rtDf7RPCNqyVYXrxTbSw' sfmc_subdomain = 'mcpbq4z2b121rg0v4mmy7tjls8h4' # Your SFMC subdomain access_token_url = f'https://{sfmc_subdomain}.auth.marketingcloudapis.com/v2/token' journey_endpoint = f'https://{sfmc_subdomain}.rest.marketingcloudapis.com/automation/v1/interactions/Welcome_to_OI_Verification_Email/execute' # Authenticate and get an access token payload = { "grant_type": "client_credentials", "client_id": client_id, "client_secret": client_secret } response = requests.post(access_token_url, data=payload) response_json = response.json() access_token = response_json['access_token'] # Define the contact data to inject contact_data = { "ContactKey": "C1001", # Contact Key "EventDefinitionKey": "Welcome_to_OI_Verification_Email", # Event Definition Key "Data": { "EMAIL_ADDRESS": "pstest.rg@gmail.com", "FIRST_NAME": "Aaron", "LAST_NAME": "OrderNumber", "ZIP": "Test" } } # Inject the contact into the journey headers = { "Authorization": f"Bearer {access_token}", "Content-Type": "application/json" } response = requests.post(journey_endpoint, headers=headers, data=json.dumps(contact_data)) # Check the response if response.status_code == 202: print("Contact injected into the journey successfully.") else: print("Failed to inject contact into the journey. Status code:", response.status_code) print("Response content:", response.text) |