Created
September 25, 2021 05:55
-
-
Save ojmccall/f0b66dbc3e1f4508c936f9bee3983756 to your computer and use it in GitHub Desktop.
GCP - SFMC Find & Replace Section 3
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
##Change Content Here | |
Types = [195,196,197,205,207,208,220] | |
for idx, val in enumerate(Types): | |
PageNumber = 1 | |
Actarray = [] | |
count = 1 | |
ContentId = val | |
while len(Actarray) < count: | |
head = {"Authorization": "Bearer " + token} | |
url = "https://"+baseURL+".rest.marketingcloudapis.com//asset/v1/content/assets?$page="+str(PageNumber)+"&$pagesize=50&$orderBy=name asc&$filter=assetType.id="+str(ContentId)+"&$fields=name,id,customerKey,content" | |
response = requests.get(url, headers=head) | |
d = response.json() | |
count = d["count"] | |
pageSize = d["pageSize"] | |
items = d["items"] | |
strItems = str(items) | |
for Act in items: | |
if ContentId in [220,197,196,195]: #Contentblocks | |
content = Act["content"] | |
name = Act["name"] | |
id = Act["id"] | |
customerKey = Act["customerKey"] | |
data = { "id": id, | |
"customerKey": customerKey, | |
"content": content | |
} | |
else: #emails and web pages | |
stringAct = str(Act) | |
if stringAct.find("'views': {'html': {'content'") >-1: #Emails & Web pages | |
content = Act["views"]["html"]["content"] | |
elif stringAct.find("'content':") >-1: | |
content = Act["content"] | |
else: | |
content = "" | |
name = Act["name"] | |
id = Act["id"] | |
customerKey = Act["customerKey"] | |
data = { "id": id, | |
"customerKey": customerKey, | |
"content": content | |
} | |
Actarray.append(data) | |
PageNumber+=1 | |
print("ContentId: "+str(ContentId)+" Length: "+str(len(Actarray))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment