Skip to content

Instantly share code, notes, and snippets.

@ojmccall
Last active September 4, 2021 03:08
Show Gist options
  • Save ojmccall/321c3833fc9f1b4adff12a58084eec10 to your computer and use it in GitHub Desktop.
Save ojmccall/321c3833fc9f1b4adff12a58084eec10 to your computer and use it in GitHub Desktop.
GCP - SFMC Data Extension Rows 3
#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