0

I'm trying to create an email in Content Builder via the REST API. I've validated and and using my token, but when I try and POST to create a simple HTML or even text email, I recieve {"message":"Request contained some validation errors.","errorcode":10006,"documentation":"","validationErrors":[{"message":"You must provide a valid AssetType for the Asset.","errorcode":118075,"documentation":""}]}

I'm copying the exact json from the example in the salesforce docs. I've even tried different variations of upper/lower/camel case for the keys like assetType and AssetType, to no avail. I'm using Python requests to POST to /asset/v1/content/assets as directed in the docs.

headers = {'Authorization': 'Bearer <token>'}
data = {
    "Name": "first rest api test message",
    "Channels": {
        "email": True,
        "web": False
    },
    "Views": {
        "html": {
            "content": "<!DOCTYPE html><body>This is a simple html paste email.</body></html>"
        },
        "text": {},
        "subjectline": {"barf"},
        "preheader": {}
    },
    "AssetType": {
        "name": "htmlemail",
        "id": 208
    }
}
r = requests.post(url, json=data, headers=headers)
  • When using the assets route. I typically create an example in the ui then do a get call and then make any changes I want and do a post to create new items. It ensures you have all the needed properties – EazyE May 12 at 21:35
0

I would suggest you to try it in tools like Postman, so that you can resolve the error quickly and post that you use the skeleton to add it in Python.

From your above code, I can see the error in the subject line. It's not properly formed.

I have tried your code in postman and corrected the errors:

{
    "Name": "first rest api test message",
    "Channels": {
        "email": true,
        "web": false
    },
    "Views": {
        "html": {
            "content": "<!DOCTYPE html><body>This is a simple html paste email.</body></html>"
        },
        "text": {},
        "subjectline": {
            "content": "This is the subject"
        },
        "preheader": {}
    },
    "AssetType": {
        "name": "htmlemail",
        "id": 208
    }
}

Let me know if this helps.

| improve this answer | |
  • That seemed to clear it up, thanks! Seems like the doc example is outdated, and the error message wasn't helpful as it was complaining about something other than the subject line. – mcbrandt13 May 13 at 18:53
  • Ya sometimes, the error message won't help. We have to go with our instincts. – Naveen VM May 14 at 5:07

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.