Sendgrid-nodejs: Disposition argument no longer optional

Created on 13 Aug 2020  路  8Comments  路  Source: sendgrid/sendgrid-nodejs

# Issue Summary
In version 7.2.1 or later (I haven't pinpointed the commit that caused the change) the disposition field in attachments are no longer optional and are not defaulting to 'attachment'. Either the docs or the code should change to reflect the docs

I'm getting this error: Expected the attachment's 'disposition' field to be a string

Steps to Reproduce

  1. leave out disposition when sending an email

Exception/Log

Error: Expected the attachment's `disposition` field to be a string
    at Mail.setAttachments (/usr/src/app/node_modules/@sendgrid/helpers/classes/mail.js:448:13)
    at Mail.fromData (/usr/src/app/node_modules/@sendgrid/helpers/classes/mail.js:82:10)
    at new Mail (/usr/src/app/node_modules/@sendgrid/helpers/classes/mail.js:46:12)
    at Function.create (/usr/src/app/node_modules/@sendgrid/helpers/classes/mail.js:670:12)
    at MailService.send (/usr/src/app/node_modules/@sendgrid/mail/src/classes/mail-service.js:188:25)
    at MergeMapSubscriber.project (/usr/src/app/src/services/send-mail.service.ts:73:46)
    at MergeMapSubscriber._tryNext (/usr/src/app/node_modules/rxjs/src/internal/operators/mergeMap.ts:135:21)
    at MergeMapSubscriber._next (/usr/src/app/node_modules/rxjs/src/internal/operators/mergeMap.ts:125:12)
    at MergeMapSubscriber.Subscriber.next (/usr/src/app/node_modules/rxjs/src/internal/Subscriber.ts:99:12)
    at MapSubscriber._next (/usr/src/app/node_modules/rxjs/src/internal/operators/map.ts:89:22)
    at MapSubscriber.Subscriber.next (/usr/src/app/node_modules/rxjs/src/internal/Subscriber.ts:99:12)
    at Object.complete (/usr/src/app/node_modules/rxjs/src/internal/observable/forkJoin.ts:194:26)
    at Object.wrappedComplete (/usr/src/app/node_modules/rxjs/src/internal/Subscriber.ts:248:54)
    at SafeSubscriber.__tryOrUnsub (/usr/src/app/node_modules/rxjs/src/internal/Subscriber.ts:265:10)
    at SafeSubscriber.complete (/usr/src/app/node_modules/rxjs/src/internal/Subscriber.ts:251:16)
    at Subscriber._complete (/usr/src/app/node_modules/rxjs/src/internal/Subscriber.ts:148:22)

Technical details:

  • sendgrid-nodejs version: >7.2.1
  • node version: v13.14.0
bug

Most helpful comment

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

All 8 comments

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

Same thing happening with email attachments optional type property https://github.com/sendgrid/sendgrid-nodejs/issues/1175
image


const attachments = [{
  content: rawQrCodeBase64,
  content_id: 'qrcode',
  filename: 'qrcode.png',
  type: 'image/png',  // Sending any email without this property now fails
}];

Got the same issue

version: "^7.2.5",

Expected the attachment'sdispositionfield to be a string,

even after passing type: 'application/pdf' in attachment

at Mail.setAttachments (billing-service/node_modules/@sendgrid/helpers/classes/mail.js:448:13) at Mail.fromData (billing-service/node_modules/@sendgrid/helpers/classes/mail.js:82:10) at new Mail (billing-service/node_modules/@sendgrid/helpers/classes/mail.js:46:12) at Function.create (billing-service/node_modules/@sendgrid/helpers/classes/mail.js:670:12) at MailService.send (billing-service/node_modules/@sendgrid/mail/src/classes/mail-service.js:188:25)

@joel-cavli I ended forcing the default values for both optional disposition: 'attachment' and type fields since this bug is still happening after a month

Source: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html#-Request-Body-Parameters
image

@TheOptimisticFactory Thank you

yes, I did try the same after looking into SendGrid doc and the issue got fixed by mandatorily passing the parameters disposition and content_id. But I guess, we need a fix to include the default values so that more people don't have to go through this pain while upgrading the packages

SendGrid doc: https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html#-Request-Body-Parameters

            let attachments = [{
                filename: `${fileName}pdf`,
                content:  content, // converted pdf buffer to base64 as per sendgrid api doc
                type: 'application/pdf',
                disposition: "inline",  // make sure you pass this parameter 
                content_id: `${timestamp}` // make sure you pass this parameter
            }];

It is either

  • 1) A bug in their API endpoint under the assumption the documentation is correct. These parameters used to be omittable for at least a year and a half
  • 2) A case of deprecated documentation under the assumption the API response is correct. It would be a somewhat breaking change that none of the changelogs highlight.

Either way, it would be nice to have a definitive answer on whether it is a bug or the now-desired behavior

It's a bug in the type-checking. PR submitted to fix this.

Probably good practice to just specify the disposition explicitly anyway, just in case.
(Still not fixed by the way, I just got this error in Sentry)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thinkingserious picture thinkingserious  路  4Comments

polkhovsky picture polkhovsky  路  3Comments

wooyah picture wooyah  路  4Comments

agostonbonomi picture agostonbonomi  路  3Comments

Loriot-n picture Loriot-n  路  4Comments