Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mastodon API: relationships endpoint should never return object instead of array #5015

Open
VyrCossont opened this issue Mar 22, 2024 · 0 comments

Comments

@VyrCossont
Copy link

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.

@VyrCossont VyrCossont changed the title Mastodon API: relationships endpoint can return object instead of array Mastodon API: relationships endpoint should never return object instead of array Mar 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant