Search code examples
aws-php-sdkaws-pinpoint

How to send messages using AWS Pinpoint service using PHP SDK


Hi I am trying to send a message using AWS Pinpoint with the PHP SDK, but I am getting an error. Any ideas why? Here is my code:

    $client = new PinpointClient([
        'version' => 'latest',
        'region'  => 'us-east-1',
        'credentials' => [
            'key'    => 'MYIAMAWSKEY',
            'secret' => 'MYAWSSECRET',
        ]
    ]);

    $result = $client->sendMessages([
        'ApplicationId' => 'MyAppId',
        'MessageRequest' => [
            'Addresses' => [
               'AnIOSDeviceToken' => [
                    'BodyOverride' => 'aaa',
                    'ChannelType' => 'APNS',
                    'RawContent' => 'bbb',
                    'Context' => ['ccc' => '222'],
                    'TitleOverride' => 'ddd',
                ],
            ],
        ],
        'MessageConfiguration' => [
            'APNSMessage' => [
                    'Action' => 'OPEN_APP',
                    'Body' => 'Hello',
                    'RawContent' => 'World',
                    'SilentPush' => false,
                    'Title' => 'Hello World!!!',
                ],
        ],
    ]);

I get the following error:

DeliveryStatus: 'PERMANENT_FAILURE'
StatusCode: 400
StatusMessage: Invalid notification: Notification is malformed

Solution

  • According to the API Docs, 'MessageConfiguration' needs to be inside the 'MessageRequest' field. Please make sure your input parameters fully match the documented API Parameter Syntax.