This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sfmc_api(event,context): | |
import requests | |
import json | |
from google.cloud import storage | |
import csv | |
import pandas as pd | |
#get the file info from the trigger event | |
filename = format(event['name']) | |
bucketname = format(event['bucket']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find config data values | |
client_id = config_data['client_id'] | |
client_secret = config_data['client_secret'] | |
baseURL = config_data['base_url'] | |
#Find DE data in filename | |
var = filename[5:] | |
var = var.replace(".csv","") | |
split =var.split("_") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get OAuth token | |
try: | |
url = 'https://'+baseURL+'.auth.marketingcloudapis.com/v2/Token' | |
data = {"grant_type":"client_credentials", | |
"client_id":client_id, | |
"client_secret":client_secret | |
} | |
r = requests.post(url, data=data) | |
print('posted') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
google-cloud-storage==1.7.0 | |
requests==2.22.0 | |
requests-html==0.6.6 | |
pandas>=1 | |
gcsfs>=0.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Additional imports for building a DE in addition to just rows | |
import base64 | |
import pandas as pd | |
import xml.etree.ElementTree as ET | |
#Set Values for DE structure | |
SOAPEndpoint = "https://"+baseURL+".soap.marketingcloudapis.com/Service.asmx" | |
#get DE Name & DE Folder ID | |
DEName = split[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get csv values to create DE | |
try: | |
df = pd.read_csv(fullpath) | |
df = df.fillna("") | |
df_dict = df.to_dict(orient='records') | |
print("df_array: "+str(df_dict)) | |
print("length: "+str(len(df_dict))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Post XML string to the SOAP Endpoint | |
try: | |
header = {"Content-Type": "text/xml" } | |
post = requests.post(SOAPEndpoint, data = XML ,headers=header) | |
print("posted") | |
body = post.content | |
except Exception as e: print("error from DE Build: "+e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
import requests | |
client_id = | |
client_secret = | |
baseURL = | |
SOAPEndpoint = "https://"+baseURL+".soap.marketingcloudapis.com/Service.asmx" | |
#compile XML |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sfmc_replace(event,context): | |
import requests | |
import json | |
import uuid | |
from google.cloud import storage | |
filename = format(event['name']) | |
bucketname = format(event['bucket']) | |
if filename.find("find_replace") >-1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contentChanged = 0 | |
SQLChanged = 0 | |
SSJSChanged = 0 | |
#get Token Here | |
try: | |
url = "https://"+baseURL+".auth.marketingcloudapis.com/v2/Token" | |
data = {"grant_type":"client_credentials", | |
"client_id":client_id, |
OlderNewer