Skip to content

.id() URL-encodes email addresses, breaking /contact/{email} and /contactdata/{email} endpoints #300

@mlevison

Description

@mlevison

When using .id() with an email address to access the /contact/{email} or /contactdata/{email} endpoints, the SDK URL-encodes the @ symbol (→ %40), causing a 400 error: "Invalid action for resource "ContactData" : "user@example.com"".

The Mailjet REST API accepts email addresses in the URL path for these endpoints — this works correctly via curl but fails through the SDK.

Steps to reproduce

const Mailjet = require('node-mailjet');
const client = Mailjet.apiConnect(apiKey, secretKey, {
  config: { version: 'v3' },
});

// This fails with 400
const response = await client
  .get('contactdata/{email}')
  .id('user@example.com')
  .request();

// Same failure with contact endpoint
const response2 = await client
  .get('contact/{email}')
  .id('user@example.com')
  .request();

Error

Unsuccessful: Status Code: "400" Message: "Invalid action for resource "ContactData" : "user@example.com"."

Expected behavior

The SDK should pass the email as-is in the URL path: https://api.mailjet.com/v3/REST/contactdata/user@example.com

Actual behavior

The SDK encodes the @%40: https://api.mailjet.com/v3/REST/contactdata/user%40example.com

Proof that the REST API accepts emails in the path (curl works)

# GET contact by email — works
curl -s -u "$API_KEY:$SECRET_KEY" \
  "https://api.mailjet.com/v3/REST/contact/user@example.com"

# PUT contactdata by email — works
curl -s -X PUT -u "$API_KEY:$SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"Data": [{"Name": "my_property", "Value": "hello"}]}' \
  "https://api.mailjet.com/v3/REST/contactdata/user@example.com"

Workaround

Use fetch directly instead of the SDK for these endpoints.

Environment

  • node-mailjet version: 6.0.11
  • Node.js version: v22.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions