Fix GroupsToDisplay::setGroupsToDisplay's handling of array arguments #624
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
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
:$email->setAsm(1, [1, 2, 3, 4])
. The expectation is that thesetAsm
method would pass its second argument to the groups_to_display setter.$asm->setGroupsToDisplay([4,5,6,7,8])
. The expectation is that this array would be set as theasm.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 theGroupsToDisplay
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
$email = new \SendGrid\Mail\Mail()
and setAsm with two arguments, an integer and an array of integers:$email->setAsm(1, array( 2, 3, 4))
.400
response citingasm.groups_to_display
.Alternatively,
400
response citingasm.groups_to_display
.Technical details:
The text was updated successfully, but these errors were encountered: