Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GroupsToDisplay::setGroupsToDisplay's handling of array arguments #624

Closed
moismailzai opened this issue Jun 4, 2018 · 1 comment
Closed
Labels
difficulty: medium fix is medium in difficulty status: work in progress Twilio or the community is in the process of implementing type: bug bug in the library

Comments

@moismailzai
Copy link

Issue Summary

According to the API docs, asm.groups_to_display should be an array of integers.

Several of the examples in this repository show that sendgrid-php is meant to support passing an array to asm.groups_to_display:

However, both of these examples return 400 with:
{"errors":[{"message":"Invalid type. Expected: integer, given: array.","field":"asm.groups_to_display.0","help":null}]}

This because the setGroupsToDisplay method of the GroupsToDisplay class is wrapping its argument ($groups_to_display) in an array: $this->groups_to_display[] = $groups_to_display;. This is necessary when $groups_to_display is a single integer, but it breaks when $groups_to_display is already an array. The fix is a conditional that checks if $groups_to_display is an array.

Steps to Reproduce

  1. Create a new mail object $email = new \SendGrid\Mail\Mail() and setAsm with two arguments, an integer and an array of integers: $email->setAsm(1, array( 2, 3, 4)).
  2. Send the mail and you will get a 400 response citing asm.groups_to_display.

Alternatively,

  1. Create a new mail object and configure your ASM like below:
$asm = new \SendGrid\Mail\Asm();
$asm->setGroupId(1);
$asm->setGroupsToDisplay(array(2, 3, 4));
...
$email->setAsm($asm);
  1. Send the mail and you will get a 400 response citing asm.groups_to_display.

Technical details:

@thinkingserious thinkingserious added type: bug bug in the library status: work in progress Twilio or the community is in the process of implementing difficulty: medium fix is medium in difficulty labels Jun 5, 2018
@thinkingserious
Copy link
Contributor

Thank you @moismailzai!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: work in progress Twilio or the community is in the process of implementing type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

2 participants