Last active
September 4, 2021 03:08
-
-
Save ojmccall/321c3833fc9f1b4adff12a58084eec10 to your computer and use it in GitHub Desktop.
GCP - SFMC Data Extension Rows 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
#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') | |
body = json.loads(r.content) | |
token = body['access_token'] | |
except Exception as e: print('Error from Token request: '+e) | |
postRequests = 0 | |
# Create arrays of rows for API payload of 1000 rows per request | |
if len(datarows) >0: | |
def arraybuilder(seq, size): | |
return (seq[pos:pos + size] for pos in range(0, len(seq), size)) | |
for group in arraybuilder(datarows, 1000): | |
payload = {"items":group} | |
strpayload = json.dumps(payload) | |
head = {"Authorization": "Bearer " + token} | |
url = 'https://'+baseURL+'.rest.marketingcloudapis.com/data/v1/async/dataextensions/key:'+DEName+'/rows' | |
response = requests.post(url, data=strpayload, headers=head) | |
#print(response) | |
#print(response.json()) | |
#incremement number of posts made during function | |
postRequests += 1 | |
print('total API posts: '+str(postRequests)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment