Mastodon API: relationships endpoint should never return object instead of array
VyrCossont opened this issue · comments
When relationships with multiple accounts are requested, but not all accounts have a relationship with the requesting account, the resulting array may contain gaps, and is incorrectly serialized: for example, when requesting 3 accounts like /api/v1/accounts/relationships?id%5B%5D=644249863538274110&id%5B%5D=676701638882780286&id%5B%5D=560748040462586535
, and there's no relationship with the middle one, this JSON results:
{
"0": {
"id": "644249863538274110",
"following": true,
"followed_by": false,
"blocking": false,
"muting": false,
"muting_notifications": null,
"requested": false,
"domain_blocking": null,
"showing_reblogs": null,
"endorsed": false
},
"2": {
"id": "560748040462586535",
"following": true,
"followed_by": false,
"blocking": false,
"muting": false,
"muting_notifications": null,
"requested": false,
"domain_blocking": null,
"showing_reblogs": null,
"endorsed": false
}
}
The correct response in this case would be:
[
{
"id": "644249863538274110",
"following": true,
"followed_by": false,
"blocking": false,
"muting": false,
"muting_notifications": null,
"requested": false,
"domain_blocking": null,
"showing_reblogs": null,
"endorsed": false
},
{
"id": "560748040462586535",
"following": true,
"followed_by": false,
"blocking": false,
"muting": false,
"muting_notifications": null,
"requested": false,
"domain_blocking": null,
"showing_reblogs": null,
"endorsed": false
}
]
This is a classic PHP issue and can probably be fixed by calling array_values
on the response to renumber it, which should cause it to be serialized as an actual array instead of an object.