octokit / octokit.js

The all-batteries-included GitHub SDK for Browsers, Node.js, and Deno.
MIT License
6.84k stars 1k forks source link

[BUG]: teams.getByName does not work #2585

Closed johnament closed 7 months ago

johnament commented 7 months ago

What happened?

There exists an API call Get A Team by Name: https://docs.github.com/en/rest/teams/teams?apiVersion=2022-11-28#get-a-team-by-name Following code examples (https://octokit.github.io/rest.js/v20#teams scroll to getByName), I should be able to call it like:

octokit.rest.teams.getByName({
  org: <org name>,
  team_slug: <team name>});

However that does not return any teams.

When I call it the way described in the API, or via curl it works fine with the same params

client.request('GET /orgs/{org}/teams/{team_slug}', {
    org: 'Contrast-Security-Inc',
    team_slug: 'team-cratus',
    headers: {
      'X-GitHub-Api-Version': '2022-11-28'
    }
  }).then((response) => {
    console.log(response);
  }).catch((error) => {
    console.log(error);
  });

Versions

Node v20.9.0 Octokit: latest available

Relevant log output

No response

Code of Conduct

github-actions[bot] commented 7 months ago

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

wolfy1339 commented 7 months ago

I can't reproduce the issue

const { Octokit } = require("octokit")
const octokit = new Octokit({
    auth: "<token>"
});
async function main() {
    const data = await octokit.rest.teams.getByName({
        org: "octokit",
        team_slug: "maintainers",
    });
    console.log(data);
}
main();
johnament commented 7 months ago

Should octokit/maintainers work for me (as someone not a member of your org)?

wolfy1339 commented 7 months ago

No, it only works for members of the org. You can change the values of org and team_slug as needed.

johnament commented 7 months ago

So I retested with yours and confirmed that i pulled in 3.1.2 of octokit, and that worked. I noticed that where I was running the original test was on 2.1.0 of octokit (not latest as I had assumed). I can upgrade that and see if that resolves this issue.

wolfy1339 commented 7 months ago

Glad to hear that it is now working 👍