-
Notifications
You must be signed in to change notification settings - Fork 145
Description
When using the latest master branch (574c907 at the time of writing) and attempting to create a new Event that contains numeric metadata, the SDK throws a JsonException.
Steps to reproduce
Trying to run:
$client = new Intercom\IntercomClient(
token: '<token>',
);
$values = [
'userId' => '12345',
'eventName' => 'foobar',
'createdAt' => time(),
'metadata' => [
'mynumber' => 123, // <-- this is the crucial factor
],
];
$client->events->create(
new Intercom\Types\CreateDataEventRequestWithUserId($values),
);ends with:
JsonException: Cannot serialize value of type Intercom\Types\CreateDataEventRequestWithUserId with any of the union types: Intercom\Types\CreateDataEventRequestWithId | Intercom\Types\CreateDataEventRequestWithUserId | Intercom\Types\CreateDataEventRequestWithEmail
It appears this error comes from the JsonProperty validation attribute on the CreateDataEventRequestWithUserId::$metadata property - here.
If metadata.mynumber (in the example above) is sent as a string, the error disappears.
Expected behavior
According to the API documentation, metadata values may be:
- a String
- a Number
- a Date (Unix timestamp int)
- a Link (string URL or an object with
urlandvaluefields) - a Monetary Amount (an object with
amountandcurrencyfields)
Using curl, I confirmed that the Intercom API (2.14) does accept numeric metadata values, so the issue seems to be specific to the PHP SDK's serialization rules.
We have not tested whether this affects the latest official release version of the SDK.
However, we are currently using the Legacy client to gradually migrate our integration, as recommended in the README, which is not yet released as a stable version.