NovuN
Novu4d ago
Robbe

novuhq/php-novu serializes nested payload incorrectly

When trying out the example, I can see that the payload is wrongly serialized. (I am using the latest v3.11).
declare(strict_types=1);

require 'vendor/autoload.php';

use novu;
use novu\Models\Components;

$sdk = novu\Novu::builder()
    ->setSecurity(
        'YOUR_SECRET_KEY_HERE'
    )
    ->build();

$triggerEventRequestDto = new Components\TriggerEventRequestDto(
    workflowId: 'workflow_identifier',
    payload: [
        'comment_id' => 'string',
        'post' => [
            'text' => 'string',
        ],
    ],
    overrides: new Components\Overrides(),
    to: 'SUBSCRIBER_ID',
    actor: '<value>',
    context: [
        'key' => 'org-acme',
    ],
);

$response = $sdk->trigger(
    triggerEventRequestDto: $triggerEventRequestDto
);

if ($response->triggerEventResponseDto !== null) {
    // handle response
}

This code looks like this in the activity feed:
{
  "comment_id": "string",
  "post": "{\"text\":\"string\"}"
}


When I used the older unicodeveloper/novu, it would look like this:
{
  "comment_id": "string",
  "post": {
    "text": "string"
  }
}


So with the new library, I can't access data like post.text anymore, because it is not correctly serialized/deserialized.
Was this page helpful?