I am trying to retrieve a portion of the response related to a template-based email via a Cloudpage. I am attempting to get the "items" portion of the response. I get the following error:
Value was either too large or too small for an Int32.
This the section of the overall code that handles the request:
function retrieveEmailTemplate(accessToken, emailTemplateName, tenantURL)
{
var url = 'https://'+ tenantURL +'.rest.marketingcloudapis.com/asset/v1/content/assets/query';
var contentType = 'application/json';
var headername = ["Authorization"];
var headervalue = ["Bearer " + accessToken];
var payload ='{"query":{"leftOperand":{"property":"name","simpleOperator":"equal","value":"'+ emailTemplateName +'"},"logicalOperator":"AND","rightOperand":{"property":"assetType.name","simpleOperator":"equal","value":"templatebasedemail"}},"fields":["views","data","content"]}';
try {
var emailRequest = HTTP.Post(url, contentType, payload, headername, headervalue);
var emailResult = Platform.Response.Write(emailRequest.Response[0]["items"]);
return emailResult;
}
catch(err) {
Platform.Response.Write("This is an error: " + err);
}
}
This is part of the response I will normally get if I remove the ["items"]
part of the emailResult
variable:
{
"count": 1,
"page": 1,
"pageSize": 50,
"links": {},
"items": [
{
"id": {{REMOVED}},
"customerKey": "{{REMOVED}}",
"objectID": "{{REMOVED}}",
"contentType": "application/vnd.etmc.email.Message; kind=template",
"assetType": {
"id": 207,
"name": "templatebasedemail",
"displayName": "Template-Based Email"
},
"name": "{{REMOVED}}",
"description": "",
"owner": {
"id": {{REMOVED}},
"email": "{{REMOVED}}",
"name": "{{REMOVED}}",
"userId": "{{REMOVED}}"
}, ....
Are there any adjustments that need to be made to prevent the error and retrieve the "items" section of the response? Thanks.