# 사용자의 기본 그룹을 설정하는 API가 있나요?

**URL:** https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611
**Category:** Development
**Tags:** rest-api
**Created:** [5월 28, 2024, 12:29오전 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611 "2024-05-28T00:29:24Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Onlyanegg](https://avatars.discourse-cdn.com/v4/letter/o/e8c25b/32.png) [@Onlyanegg](https://meta.discourse.org/u/Onlyanegg)
#### Post date: [5월 28, 2024, 12:29오전 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/1 "2024-05-28T00:29:24Z")

</div>

원래라면 사용자를 초대할 때 초대에 포함된 그룹을 기본 그룹으로 설정하고 싶은데, 그렇게 할 방법을 찾지 못하겠습니다. API를 통해 사용자의 기본 그룹을 설정할 수 있는 방법이 있을까요?

감사합니다.

---

<div class="post-metadata">

### Author: ![Lilly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lilly/32/575047_2.png) [@Lilly](https://meta.discourse.org/u/Lilly)
#### Post date: [5월 28, 2024, 2:12오전 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/2 "2024-05-28T02:12:34Z")

</div>

updateUser 작업을 통해 사용자 설정을 업데이트할 수 있을 것 같습니다:

> **[Discourse API Docs](https://docs.discourse.org/#tag/Users/operation/updateUser)**

> [@Discourse REST API Documentation](https://meta.discourse.org/t/discourse-rest-api-documentation/22706/1):
>
> Discourse API Please view the Discourse API Documentation site for detailed info: [https://docs.discourse.org](https://docs.discourse.org)information_source Authentication API requests must use HTTP header based authentication. Pass your Api-Key and Api-Username as HTTP headers. Authentication via query parameters or request body is not supported (this was removed in April 2020). Please see the example cURL request below. The only API endpoints that continue to support credentials in query parameters are requests to…

---

<div class="post-metadata">

### Author: ![Onlyanegg](https://avatars.discourse-cdn.com/v4/letter/o/e8c25b/32.png) [@Onlyanegg](https://meta.discourse.org/u/Onlyanegg)
#### Post date: [5월 28, 2024, 4:34오전 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/3 "2024-05-28T04:34:39Z")

</div>

알려주셔서 감사합니다. 해당 방법을 시도해 보았습니다. primary\_group\_name, primary\_group\_id, 그리고 해당 항목의 groups 배열 엔트리인 [‘primary\_group’] = true까지 모두 업데이트했습니다. 제미나를 사용하여 update\_user를 호출하면 200 응답을 받지만, 아직 원하는 결과는 나오지 않습니다. 내일 더 자세히 살펴보고 무엇이 잘못되었는지 확인해 보겠습니다. 다만, 눈에 띄는 문제는 발견하지 못했습니다.

다음은 실행하여 서버로부터 200 코드를 받은 코드입니다:

```plaintext
client = DiscourseApi::Client.new("https://myforumurl.example.com")
client.api_key = 'an api key with global permissions for testing this'
client.api_username = 'my admin username -- I think this doesnt matter though'
user = client.user('joepowell')
user['primary_group_name'] = 'dojo'
user['primary_group_id'] = 42
# this is group 42 in the groups array
user['groups'][2]['primary_group'] = true
client.update_user('joepowell', user)

```

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [5월 28, 2024, 10:07오전 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/4 "2024-05-28T10:07:37Z")

</div>

[Discourse API 역공학](https://meta.discourse.org/t/reverse-engineer-the-discourse-api/20576)을 참고하세요. API를 파악하는 가장 확실한 방법이며, 항상 최신 상태를 유지합니다.

---

<div class="post-metadata">

### Author: ![Onlyanegg](https://avatars.discourse-cdn.com/v4/letter/o/e8c25b/32.png) [@Onlyanegg](https://meta.discourse.org/u/Onlyanegg)
#### Post date: [5월 28, 2024, 11:43오전 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/5 "2024-05-28T11:43:28Z")

</div>

정말 감사합니다 🙂 내일 아침에 해보고 여기 다시 올릴게요 🙂

---

<div class="post-metadata">

### Author: ![Onlyanegg](https://avatars.discourse-cdn.com/v4/letter/o/e8c25b/32.png) [@Onlyanegg](https://meta.discourse.org/u/Onlyanegg)
#### Post date: [5월 29, 2024, 11:55오후 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/6 "2024-05-29T23:55:52Z")

</div>

다음 Ruby 코드를 사용하여 기본 그룹 ID를 업데이트할 수 있었습니다. 아직 해당 기능이 gem을 통해 지원되지 않는 것으로 보입니다(코드를 검색하여 primary\_group\_id에 대한 참조를 찾아보았지만, 이 방식으로 작동할 것 같은 내용은 보이지 않았습니다).

```plaintext
require 'curb'
http = Curl.put('https://yourforum.com/admin/users/###user_id###/primary_group?primary_group_id=###group_id###') do | http |
  http.headers['Api-Key'] = 'your-api-key';
  http.headers['Api-Username'] = 'your-api-username';
  http.headers['Content-Type'] = 'application/x-www-form-urlencoded'
end

```

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [5월 30, 2024, 4:55오전 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/7 "2024-05-30T04:55:02Z")

</div>

> [@Onlyanegg](#):
>
> 아직 gem을 통해 지원되지 않는 것으로 보입니다.

gem이 지원하지 않는 경로에 요청을 보내기 위해 이 메서드들을 사용하는 것이 괜찮다고 생각합니다:

> <https://github.com/discourse/discourse_api/blob/main/lib/discourse_api/client.rb#L93-L117>

따라서 다음과 같은 작업을 수행할 수 있습니다:

```ruby
 response = client.put("admin/users/4/primary_group", primary_group_id: 43)

```

---

<div class="post-metadata">

### Author: ![Onlyanegg](https://avatars.discourse-cdn.com/v4/letter/o/e8c25b/32.png) [@Onlyanegg](https://meta.discourse.org/u/Onlyanegg)
#### Post date: [5월 30, 2024, 5:10오전 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/8 "2024-05-30T05:10:42Z")

</div>

아, 좋네요. 감사합니다. 여기서 코드를 업데이트한 후에 풀 리퀘스트를 만들 수 있을 것 같아서요:

> <https://github.com/discourse/discourse/blob/main/app/models/api_key_scope.rb#L23>

하지만 지금은 디스코urs 코드를 직접 수정하기보다는 시스템을 실행시키는 데 집중하고 있어서, 디스코urs 코드 자체를 변경하기까지는 좀 더 시간이 걸릴 것 같습니다. 그래도 디스코urs는 정말 마음에 듭니다. 이름은 밝히지 않겠지만, 누군가의 추천으로 Flarum을 잠시 사용해 봤는데, 솔직히 비교가 안 됩니다. 틀을 깨고 무언가를 하고 싶은 사람들에게 디스코urs는 다른 차원의 서비스입니다.

감사합니다

---

<div class="post-metadata">

### Author: ![barto\_95](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barto_95/32/199996_2.png) [@barto\_95](https://meta.discourse.org/u/barto_95)
#### Post date: [6월 10, 2024, 4:23오후 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/9 "2024-06-10T16:23:52Z")

</div>

API를 통해 기본 그룹을 변경할 수 없나요? ☹

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [6월 10, 2024, 4:28오후 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/10 "2024-06-10T16:28:45Z")

</div>

UX에서 변경할 수 있다면, API에서도 변경할 수 있습니다. [Discourse API 역공학](https://meta.discourse.org/t/reverse-engineer-the-discourse-api/20576)을 참고하세요.

아, Gem으로 변경하는 것을 말씀하시는 거라면, 저는 잘 모르겠습니다. 죄송합니다.

---

<div class="post-metadata">

### Author: ![barto\_95](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barto_95/32/199996_2.png) [@barto\_95](https://meta.discourse.org/u/barto_95)
#### Post date: [6월 10, 2024, 4:58오후 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/11 "2024-06-10T16:58:34Z")

</div>

@pfaffman 답변해 주셔서 감사합니다.

역순으로 테스트해 봤지만 작동하지 않으며 404 not found가 반환되었습니다 ☹

/admin/users/barto\_95/primary\_group.json:

```plaintext
{
	"errors": [
		"L'URL ou la ressource demandée n'a pas été retrouvée."
	],
	"error_type": "not_found"
}

```

그리고  
/admin/users/2/primary\_group.json: (2 = 사용자 barto\_95의 ID)

```plaintext
{
	"errors": [
		"L'accès à la ressource demandée n'est pas autorisé."
	],
	"error_type": "invalid_access"
}

```

브라우저에서 URL /admin/users/2/primary\_group.json으로 접속하면 JSON이 표시됩니다.

 ![CleanShot 2024-06-10 at 18.55.23](https://global.discourse-cdn.com/meta/original/4X/e/c/0/ec04bc617a78e35fc2575963ecb44e34765215d7.jpeg)

API를 테스트하기 위한 요청:

```plaintext

curl --request PUT \
  --url 'https://xxxxxr/admin/users/2/primary_group.json?=' \
  --header 'Api-Key: a7bb1199xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdecbc7b41658' \
  --header 'Apu-Username: Equipe_HACF' \
  --header 'Content-Type: application/json' \
  --data '{   
	"primary_group_id": "67" 
}'

```

☹ 도움 주셔서 감사합니다

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [6월 10, 2024, 5:02오후 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/12 "2024-06-10T17:02:45Z")

</div>

해당 사용자가 관리자인가요? 제 추측으로는 권한 문제일 것 같습니다. 다음 중 하나 이상에 해당합니다: 사용자가 잘못되었거나, 키가 잘못되었거나, 키에 대한 권한 설정이 잘못되었습니다.

---

<div class="post-metadata">

### Author: ![barto\_95](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/barto_95/32/199996_2.png) [@barto\_95](https://meta.discourse.org/u/barto_95)
#### Post date: [6월 11, 2024, 8:40오전 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/13 "2024-06-11T08:40:17Z")

</div>

> [@barto\_95](#):
>
> /admin/users/2/primary\_group.json

네, 문제는 제가 사용한 사용자의 권한입니다.

감사합니다 🙂

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [7월 11, 2024, 8:41오전 UTC](https://meta.discourse.org/t/is-there-an-api-to-set-the-primary-group-for-a-user/309611/14 "2024-07-11T08:41:04Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
