Skip to content

Conversation

Claymost
Copy link

@Claymost Claymost commented Jun 26, 2025

Description

Fixes issue where templateId was required when sending emails with htmlContent as described in #10

Changes

  • Made templateId nullable with default null
  • Only include templateId in API request when set

Notes

As detailed in the brevo api docs, templateId is not always a required field. It's optional if htmlContent is included.

No tests added as none existed for this class previously. Let me know if you'd like test coverage.

@Claymost Claymost changed the title Fix: Make templateId optional to support content-based emails Fix: Make templateId optional to support html content emails Jun 26, 2025
Copy link

@N1k0h N1k0h left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template ID is not mandatory in Brevo documentation

Template is only mandatory in email campaign creation, only if htmlContent and htmlUrl are empty.

Sources :

Template ID is not mandatory in Brevo Package

See listInvalidProperties functions of each models to create email campaigns, or send transactional emails.

CreateEmailCampaign.php

/**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties()
    {
        $invalidProperties = [];

        if ($this->container['sender'] === null) {
            $invalidProperties[] = "'sender' can't be null";
        }
        if ($this->container['name'] === null) {
            $invalidProperties[] = "'name' can't be null";
        }
        if (!is_null($this->container['splitRule']) && ($this->container['splitRule'] > 50)) {
            $invalidProperties[] = "invalid value for 'splitRule', must be smaller than or equal to 50.";
        }

        if (!is_null($this->container['splitRule']) && ($this->container['splitRule'] < 1)) {
            $invalidProperties[] = "invalid value for 'splitRule', must be bigger than or equal to 1.";
        }

        $allowedValues = $this->getWinnerCriteriaAllowableValues();
        if (!is_null($this->container['winnerCriteria']) && !in_array($this->container['winnerCriteria'], $allowedValues, true)) {
            $invalidProperties[] = sprintf(
                "invalid value for 'winnerCriteria', must be one of '%s'",
                implode("', '", $allowedValues)
            );
        }

        if (!is_null($this->container['winnerDelay']) && ($this->container['winnerDelay'] > 168)) {
            $invalidProperties[] = "invalid value for 'winnerDelay', must be smaller than or equal to 168.";
        }

        if (!is_null($this->container['winnerDelay']) && ($this->container['winnerDelay'] < 1)) {
            $invalidProperties[] = "invalid value for 'winnerDelay', must be bigger than or equal to 1.";
        }

        if (!is_null($this->container['increaseRate']) && ($this->container['increaseRate'] > 100)) {
            $invalidProperties[] = "invalid value for 'increaseRate', must be smaller than or equal to 100.";
        }

        if (!is_null($this->container['increaseRate']) && ($this->container['increaseRate'] < 0)) {
            $invalidProperties[] = "invalid value for 'increaseRate', must be bigger than or equal to 0.";
        }

        return $invalidProperties;
    }

SendSmtpEmail.php

/**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties()
    {
        $invalidProperties = [];

        return $invalidProperties;
    }

Sources :

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants