0

It looks like the ExactTarget/SFMC API for managing email templates has changed, but the FuelSDK examples have not yet been updated.

Legacy way to create an email template: (assume ET_Client has been initialized and authenticated against SFMC)

NameOfTestEmail = 'My Email'
stubObj = ET_Client.ET_Client(False, debug, params = params)

# Create Email 
print('>>> Create Email')
postHTMLBody = ET_Client.ET_Email()
postHTMLBody.auth_stub = stubObj
postHTMLBody.props = {"CustomerKey" : NameOfTestEmail, "Name":NameOfTestEmail, "Subject" : "Created Using the PythonSDK", "HTMLBody": "<b>Some HTML Goes here</b>"}
postResponse = postHTMLBody.post()
print('Post Status: ' + str(postResponse.status))
print('Code: ' + str(postResponse.code))
print('Message: ' + str(postResponse.message))
print('Result Count: ' + str(len(postResponse.results)))
print('Results: ' + str(postResponse.results

How to do this using the new API?

1

You'll need to utilize the REST API in order to perform CRUD operations on Content Builder assets. Here are some example JSON payloads, from the documentation, on creating content using this approach.

I recommend utilizing a library, such as Requests, to easily structure your API calls to Marketing Cloud and work with the response. Here's an example function for retrieving your access token in order to help get you started:

def getToken():
    payload = {
        "grant_type": "client_credentials",
        "client_secret": "clientSecret",
        "client_id":"clientID",
        "account_id":"12345"
    }
    print("\nAuthenticating...\n")
    res = requests.post("YOUR AUTH URL", data=payload)
    res.raise_for_status()
    return json.loads(res.text)["access_token"]
    print("Done.")

accessToken = getToken()
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.