I am trying to use https://api.hubapi.com/marketing-emails/v1/emails/ to update an existing email, by sending ‘widgets’ => ‘the_array_with the change’ I get an empty response and the email does not change.
Hey, @HvanderMerwe50
Welcome to the community! Thanks for your question.
I have a few questions that will help our community to understand your issue and how to best help you.
- Can you share the full API request you’re sending, including the structure of the
widgetsarray, please? - Are you receiving any status code or error messages from the API response?
- Can you specify the exact changes you’re trying to make to the email?
- Have you been able to update other aspects of an email successfully using this endpoint?
The more details you can provide, the better we’ll be able to assist.
Thanks! — Jaycee
This is my PHP Code:
$url = "https://api.hubapi.com/marketing-emails/v1/emails/${$market_watch_email_id}";
$new_email_content = (object) [
"widgets" => $html
];
mdebug($new_email_content,'$new_email_content',100,800);
// Initialize cURL
$ch = curl_init($url);
// Set cURL options
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . hubspot_api_key,
'Content-Type: application/json'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($new_email_content));
// Execute the request
$response = curl_exec($ch);
// Check for errors
if($response === FALSE){
die(curl_error($ch));
}
// Decode the response
$responseData = json_decode($response, TRUE);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
mdebug($httpcode);
// Close the cURL handler
curl_close($ch);
I am getting a 401 response on this.
I am sending this object:
stdClass Object
(
[widgets] => stdClass Object
(
[module-0-0-0] => stdClass Object
(
[body] => stdClass Object
(
[alignment] => center
[css_class] => dnd-module
[hs_enable_module_padding] => 1
[img] => stdClass Object
(
[alt] => HubSpot logo orange
[height] => 72
[src] => https://static.hsappstatic.net/TemplateAssets/static-1.114/img/hs_default_template_images/email_dnd_template_images/company-logo-orange.png
[width] => 240
)
[module_id] => 1367093
[path] => @hubspot/image_email
[schema_version] => 2
)
[child_css] => stdClass Object
(
)
[css] => stdClass Object
(
)
[id] => module-0-0-0
[module_id] => 1367093
[name] => module-0-0-0
[order] => 1
[styles] => stdClass Object
(
)
[type] => module
)
[module-1-0-0] => stdClass Object
(
[body] => stdClass Object
(
[css_class] => dnd-module
[hs_enable_module_padding] => 1
[html] => Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
[i18nKey] => richText.welcome.primary
[module_id] => 1155639
[path] => @hubspot/rich_text
[schema_version] => 2
)
[child_css] => stdClass Object
(
)
[css] => stdClass Object
(
)
[id] => module-1-0-0
[module_id] => 1155639
[name] => module-1-0-0
[order] => 3
[styles] => stdClass Object
(
)
[type] => module
)
[module-2-0-0] => stdClass Object
(
[body] => stdClass Object
(
[align] => center
[css_class] => dnd-module
[font] => stdClass Object
(
[color] => #23496d
[font] => Arial, sans-serif
[size] => stdClass Object
(
[units] => px
[value] => 12
)
)
[hs_enable_module_padding] =>
[link_font] => stdClass Object
(
[color] => #00a4bd
[font] => Helvetica,Arial,sans-serif
[size] => stdClass Object
(
[units] => px
[value] => 12
)
[styles] => stdClass Object
(
[bold] =>
[italic] =>
[underline] => 1
)
)
[module_id] => 2869621
[path] => @hubspot/email_footer
[schema_version] => 2
[unsubscribe_link_type] => both
)
[child_css] => stdClass Object
(
)
[css] => stdClass Object
(
)
[id] => module-2-0-0
[module_id] => 2869621
[name] => module-2-0-0
[order] => 4
[styles] => stdClass Object
(
)
[type] => module
)
[preview_text] => stdClass Object
(
[body] => stdClass Object
(
[value] =>
)
[child_css] => stdClass Object
(
)
[css] => stdClass Object
(
)
[id] => preview_text
[label] => Preview Text <span class=help-text>This will be used as the preview text that displays in some email clients</span>
[name] => preview_text
[order] => 0
[styles] => stdClass Object
(
)
[type] => text
)
)
)
I was trying to change
widgets → module-1-0-0 → body → html
So here is what we are trying to do. We have data on our WordPress site that we would like to send via Hubspot to a contact list. This is a market info post that we do daily and they would like to automate this process.