Skip to content

fix: updating Mailjet client auth#19725

Merged
michelle0927 merged 4 commits intomasterfrom
fix/mailjet-connection
Jan 28, 2026
Merged

fix: updating Mailjet client auth#19725
michelle0927 merged 4 commits intomasterfrom
fix/mailjet-connection

Conversation

@maycon-pipedream
Copy link
Copy Markdown
Contributor

@maycon-pipedream maycon-pipedream commented Jan 16, 2026

Fix Mailjet Authentication Issue

Problem

The Mailjet integration was failing to authenticate with a 401 Unauthorized error.

Root Cause

Two issues were identified:

  1. Incorrect auth field reference in code: The app was referencing this.$auth.api_key, but the Pipedream authentication configuration for Mailjet uses this.$auth.public_key and this.$auth.secret_key.

  2. Incorrect authentication strategy configuration: In the Admin Apps configuration, the authentication field was set to API_KEY instead of Public_Key, causing the credentials to not be properly resolved.

Changes Made

  • Updated the import statement to use the correct library name:

    • Changed from import Mailjet from "node-mailjet" to import MailjetClient from "node-mailjet"
  • Updated the client() method in mailjet.app.mjs to use the correct authentication field names:

    • Changed from this.$auth.api_key to this.$auth.public_key
  • Updated the client instantiation to use the proper node-mailjet v6.x syntax:

    return new MailjetClient({
    apiKey: this.$auth.public_key,
    apiSecret: this.$auth.secret_key,
    });

Summary by CodeRabbit

  • Chores
    • Mailjet integration package bumped to 0.4.5.
    • Mailjet action modules updated to v0.0.4 (create/list/send/update contacts).
    • Mailjet event/source version advanced.
    • Improved Mailjet client and authentication handling behind the scenes.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
pipedream-docs-redirect-do-not-edit Ignored Ignored Jan 28, 2026 7:37pm

Request Review

@pipedream-component-development
Copy link
Copy Markdown
Collaborator

Thank you so much for submitting this! We've added it to our backlog to review, and our team has been notified.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 16, 2026

Walkthrough

Version bumps across Mailjet actions (0.0.3 → 0.0.4), a source (contact-created 0.0.4 → 0.0.5), and package.json (0.4.4 → 0.4.5). mailjet.app.mjs updates import alias to MailjetClient, instantiates that client, and switches credential usage from this.$auth.api_key to this.$auth.public_key.

Changes

Cohort / File(s) Summary
Action Version Updates
components/mailjet/actions/create-contact/create-contact.mjs, components/mailjet/actions/list-contacts/list-contacts.mjs, components/mailjet/actions/send-message/send-message.mjs, components/mailjet/actions/update-contact/update-contact.mjs
Exported action version fields bumped from 0.0.3 to 0.0.4.
Source Version Update
components/mailjet/sources/contact-created/contact-created.mjs
Exported source version bumped from 0.0.4 to 0.0.5.
Main App Configuration
components/mailjet/mailjet.app.mjs
Import alias changed to MailjetClient; client instantiation updated; credential source switched from this.$auth.api_key to this.$auth.public_key.
Package Version
components/mailjet/package.json
Package version bumped from 0.4.4 to 0.4.5.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main change: fixing Mailjet client authentication by updating the import and auth field references.
Description check ✅ Passed The PR description is comprehensive and well-structured, covering the problem, root cause, and all changes made. It clearly explains the authentication fix and implementation details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pipedream-component-development
Copy link
Copy Markdown
Collaborator

Thanks for submitting this PR! When we review PRs, we follow the Pipedream component guidelines. If you're not familiar, here's a quick checklist:

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
components/mailjet/actions/send-message/send-message.mjs (4)

57-68: Add validation to enforce at least one content field is required.

Both textPart and htmlPart are marked optional, but the Mailjet API requires at least one to be specified. The action should validate this constraint before making the API call to provide a clearer error message.

✅ Proposed validation fix

Add this validation in the run method after destructuring (around line 82):

   } = this;
 
+  if (!textPart && !htmlPart) {
+    throw new Error("At least one of 'Text Part' or 'HTML Part' must be provided.");
+  }
+
   try {
     const { body: { Sent: response } } =

99-101: Add defensive check before accessing array element.

The code assumes response[0] exists without verification. While the API should return at least one result on success, adding a bounds check would prevent potential runtime errors.

🛡️ Defensive coding suggestion
-  $.export("$summary", `Successfully sent email message with ID ${response[0].MessageID}`);
+  if (!response || response.length === 0) {
+    throw new Error("No response received from Mailjet API");
+  }
+  $.export("$summary", `Successfully sent email message with ID ${response[0].MessageID}`);

103-105: Consider preserving more error context for better debugging.

The current error handling extracts only statusMessage, which may lose important details like error codes or response body that could help troubleshoot API failures.

🔍 Enhanced error handling
   } catch (error) {
-    throw error.response?.res?.statusMessage ?? error;
+    const errorMessage = error.response?.res?.statusMessage;
+    const errorBody = error.response?.body;
+    throw new Error(
+      errorMessage 
+        ? `Mailjet API error: ${errorMessage}${errorBody ? ` - ${JSON.stringify(errorBody)}` : ''}`
+        : error.message || error
+    );
   }

87-89: Fix the Sender field type — it must be an object, not a boolean.

The Mailjet Send API v3 expects the "Sender" field to be an object with "Email" and optional "Name" properties (e.g., { "Email":"sender@example.com", "Name":"Sender Name" }), but the code passes a boolean value directly. This will cause the API call to fail. If the intent is to conditionally use a default sender address, transform the boolean flag into the proper object structure or omit the field when not needed.

GTFalcao
GTFalcao previously approved these changes Jan 27, 2026
Copy link
Copy Markdown
Collaborator

@GTFalcao GTFalcao left a comment

Choose a reason for hiding this comment

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

LGTM!

@GTFalcao GTFalcao moved this from Ready for PR Review to Ready for QA in Component (Source and Action) Backlog Jan 27, 2026
@vunguyenhung vunguyenhung moved this from Ready for QA to Ready for Release in Component (Source and Action) Backlog Jan 28, 2026
@vunguyenhung
Copy link
Copy Markdown
Contributor

Hi everyone, all test cases are passed! Ready for release!

Test reports

@michelle0927
Copy link
Copy Markdown
Collaborator

michelle0927 commented Jan 28, 2026

Hi @maycon-pipedream, make sure you update the version of the source contact-created before merging. If the authentication was broken, it will affect all components, not just actions.

@michelle0927
Copy link
Copy Markdown
Collaborator

/approve

@michelle0927 michelle0927 merged commit 17fea08 into master Jan 28, 2026
9 checks passed
@michelle0927 michelle0927 deleted the fix/mailjet-connection branch January 28, 2026 20:57
@github-project-automation github-project-automation Bot moved this from Ready for Release to Done in Component (Source and Action) Backlog Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants