웹훅¶
경고
It is highly recommended to consult with a developer, solution architect, or another technical role when deciding to use webhooks and throughout the implementation process. If not properly configured, webhooks may disrupt the Odoo database and can take time to revert.
웹훅은 스튜디오* 에서 생성할 수 있는 자동화 규칙으로, 사용자 지정 HTTP 콜백을 통해 외부 이벤트에 의해 작동되는 규칙입니다. 외부 시스템이 데이터 파일(“페이로드”)과 함께 Odoo 웹훅의 URL(“트리거”)로 데이터를 전송하면 Odoo에서 데이터베이스에 미리 정의된 작업으로 응답합니다.
Unlike scheduled actions or manual API calls, webhooks enable real-time communication and automation. For example, if a sales order is confirmed in an external POS system, a webhook can instantly update Odoo’s inventory, ensuring system synchronization.
참고
This article covers creating a webhook that takes in data from an external source. However, an automated action that sends an API call to an external webhook can also be created.
스튜디오에서 웹훅 만들기¶
Webhooks are configured in Studio, and their setup is split between their trigger and their actions.
팁
Setting up a webhook in Odoo requires no coding when connecting Odoo databases, but testing requires an external tool like Postman. Custom target records or actions may require programming skills.
Activate developer mode to modify the model targeted by the webhook (e.g., sales orders or contact information) and to find the model’s technical name (which may be required for proper payload configuration).
웹훅 트리거 설정¶
스튜디오 에 웹훅을 생성하려면 스튜디오를 열고 웹훅 을 클릭한 후 이어서 신규 를 클릭합니다. 여기에서 웹훅 이름을 지정한 후, 필요한 경우 웹훅 모델(대상 데이터베이스 항목의 종류)을 수정하고, 웹훅 URL 호출을 기록할지 여부를 토글로 지정합니다(문제 해결을 위해 웹훅 호출 기록에 대한 추적 여부 설정).
The webhook’s URL is automatically generated. This is the URL that should be used for testing the webhook and connecting it to the external system that will send updates to the database.
위험
The webhook’s URL is confidential and should be treated with care. Sharing it online or without caution can provide unintended access to the Odoo database. Click Rotate Secret to change the URL if needed.
마지막으로, 웹훅 전송 시스템이 Odoo가 아닌 경우에는 대상 레코드 작업을 조정하여 웹훅의 URL 호출 시 API 호출 페이로드에 포함된 JSON 레코드를 찾게 합니다. 웹훅 전송 시스템이 Odoo 데이터베이스인 경우에는 id
및 모델
이 페이로드에 표시되는지 확인하세요.
팁
Odoo에서는 모델 이 이미 설정되어 있으나, 반드시 모델의 기술명이 페이로드에 지정되어야 합니다. 모델명 위에 마우스를 가져간 다음, (내부 링크) 아이콘을 클릭하면 모델 필드에서 기술명을 찾을 수 있습니다. 예를 들어, 판매주문서 웹훅에서는 판매주문서 모델을 사용하지만, 페이로드에는 기술명인 sale.order
가 사용됩니다.
참고
When creating a record in the Odoo database, the target record’s default format should not be
used. Instead, use model.browse(i)
or model.search(i)
.
웹훅 동작 설정¶
To set a webhook’s action while configuring a webhook, click Add an action under the Actions To Do tab. Click the action’s Type and set the fields as needed.
웹훅 테스트¶
참고
웹훅을 테스트하려면 웹훅을 설정한 후 웹훅으로 전송할 테스트 페이로드와 POST
API 요청을 통해 페이로드를 전송할 외부 도구 또는 시스템이 필요합니다. Postman 과 같은 도구를 사용하면 기술적인 지원이 적은 상황에서도 가능합니다.
If a message saying 200 OK
or status: ok
gets returned during testing, then the webhook is
functioning properly on Odoo’s side. From here, implementation can begin with the other tool to
automatically send those webhook calls into Odoo using the webhook’s URL.
다른 응답이 반환되는 경우, 응답에서 전송된 번호를 통해 문제를 식별할 수 있습니다. 예를 들어, 500 내부 서버 오류
는 Odoo에서 호출을 제대로 해석하지 못한다는 의미입니다. 이 응답이 반환되는 경우 JSON 파일에서 찾은 필드가 웹훅 설정과 테스트 호출을 보내는 시스템에서 제대로 매핑되었는지 확인하세요. 웹훅 환경설정에서 호출 로깅을 켜면 웹훅이 의도한 대로 작동하지 않을 경우 오류 로그가 표시됩니다.
웹훅 구현¶
Once the webhook is fully configured, begin connecting it to the system that sends data to the Odoo database through this webhook. Make sure that the API calls are sent to the webhook’s URL when setting that system up.
웹훅 사용 사례¶
Below are two examples of how to use webhooks in Odoo. These webhooks require external tools (which are listed with the example).
경고
Consult with a developer, solution architect, or another technical role when deciding to implement webhooks. If not properly configured, webhooks may disrupt the Odoo database and can take time to revert.
판매주문서 통화 업데이트하기¶
This webhook updates a sales order in the Sales app to USD. It useful for subsidiaries outside the United States with a mother company located inside the United States or during mergers when consolidating data into one Odoo database.
웹훅 트리거 설정¶
To set up this webhook, open the Sales app. Then, set the trigger so the Model is set to Sales Order
. Also, set
the Target Record to model.env[payload.get('model')].browse(int(payload.get('id')))
.
This is broken down below.
model: what gets updated in Odoo (in this case, sales orders). This matches the Model set earlier.
env: where the action takes place. In this case, it is Odoo.
payload: what is sent to the webhook’s URL. This contains the information that updates the sales order.
get(‘model’): tells the webhook what database record to look at. In this case, the webhook retrieves (
get
) the data tied to a specificmodel
. In this example, this is the Sales Order model.browse: tells the webhook to look in the
model
(Sales Order) set by the payload for what to update.int: turns the target into an
integer
(a whole number). This is important in case some words (astring
) or a decimal number is included in the payload’s target record.get(‘id’): identifies the sales order number that is being updated in Odoo.
웹훅 동작 설정¶
After setting the trigger, set the webhook’s action by clicking Add an action. For the
Type, click Update Record. Then, select Update
, choose the field
Currency
, and select USD
to have the currency field updated to USD. Finally, click
Save & Close.
웹훅 설정 요약¶
설정된 내용을 요약하면, 웹훅은 판매 주문 번호를 통해 인식되는 판매주문서를 대상으로 하며 해당 판매 주문 번호(페이로드의 id
레코드로 식별)가 포함된 웹훅 URL로 POST 요청이 전송되면 통화를 USD
로 업데이트합니다.
웹훅 테스트¶
Test the webhook’s setup to make sure everything is correct. This process uses a tool called Postman to send the simulated trigger.
This section walks through the steps to test this webhook in Postman, but does not offer help if there’s an issue within that tool. To get specific help with Postman, contact their support team.
Postman이 열리면 새 HTTP 요청을 생성한 후 해당 메서드를 POST 로 설정합니다. 그 다음, 테스트 중인 웹훅 URL을 복사하여 Postman의 URL 필드에 붙여넣습니다. 그런 다음 본문 탭을 클릭하고 원시 옵션을 선택합니다. 파일 유형을 JSON 으로 설정한 다음 이 코드를 복사하여 파일에 붙여넣습니다.
{
"model": "sale.order",
"id": "SALES ORDER NUMBER"
}
여기에서 웹훅을 테스트할 판매 주문을 선택하세요. Odoo 라이브 데이터베이스에서 테스트할 수 없는 경우 판매주문서 샘플과 웹훅 환경설정을 사용하여 데모 데이터베이스를 생성하도록 합니다. 판매주문서 번호
에서 S
또는 숫자 앞에 있는 0을 제외한 판매 주문 번호로 변경합니다. 예를 들어, 판매주문서 번호가 S00007`인 경우 Postman에서는 `7
로 입력해야 합니다. 마지막으로 Postman에서 보내기 를 클릭합니다.
200 OK
또는 status: ok
라는 메시지가 반환되면 Odoo 측에서 웹훅이 제대로 작동하고 있다는 의미입니다. 테스트 판매주문서의 통화 항목이 업데이트됩니다. 여기에서 다른 도구를 통해 구현하여 웹훅의 URL을 통해 해당 웹훅 호출을 Odoo로 자동으로 전송할 수 있습니다.
다른 응답이 반환되는 경우 응답과 관련된 번호로 문제를 식별할 수 있습니다. 예를 들어 500 내부 서버 오류
는 Odoo에서 호출을 제대로 해석할 수 없다는 의미입니다. 이 응답이 반환되면 웹훅 환경설정 및 Postman에서 모델
및 id
필드가 제대로 매핑되었는지 확인하세요.
새 계약서 만들기¶
This webhook uses custom code to create a new contact in an Odoo database. This could be helpful for automatically creating new vendors or customers.
웹훅 트리거 설정¶
To set up this webhook, open the Contacts app. Then, set the trigger so the Model is set to Contact
. Also, set the
Target Record to model.browse([2])
. This is broken down below.
model: what gets updated in Odoo (in this case, a contact). This matches the Model set earlier.
browse: tells the webhook to look in the
model
(the contacts) set by the payload for what to create.
웹훅 동작 설정¶
After setting the trigger, set the webhook’s action by clicking Add an action. For the Type, click Execute Code, then set the code to the sample code below. Finally, click Save & Close.
# variables to retrieve and hold data from the payload
contact_name = payload.get('name')
contact_email = payload.get('email')
contact_phone = payload.get('phone')
# a Python function to turn the variables into a contact in Odoo
if contact_name and contact_email:
new_partner = env['res.partner'].create({
'name': contact_name,
'email': contact_email,
'phone': contact_phone,
'company_type':'person',
'customer_rank': 1,
})
# an error message for missing required data in the payload
else:
raise ValueError("Missing required fields: 'name' and 'email'")
웹훅 설정 요약¶
To summarize what is set up, the webhook creates a contact when an API call is sent to the webhook’s URL that includes the contact’s information.
웹훅 테스트¶
Test the webhook’s setup to make sure everything is correct. This process uses a tool called Postman to send the simulated trigger.
This section walks through the steps to test this webhook in Postman, but does not offer help if there’s an issue within that tool. To get specific help with Postman, contact their support team.
Postman이 열리면 새로 요청을 생성한 후 해당 메서드를 POST 로 설정합니다. 그런 다음 테스트 중인 웹훅 URL을 복사하여 Postman의 URL 필드에 붙여넣습니다. 그런 다음 본문 탭을 클릭하고 원시 를 클릭합니다. 파일 형식을 JSON 으로 설정한 다음 이 코드를 복사하여 파일에 붙여넣습니다.
{
"name": "CONTACT NAME",
"email": "CONTACTEMAIL@EMAIL.COM",
"phone": "CONTACT PHONE NUMBER"
}
Replace the fields above with a new contact’s information in Postman, and then click Send.
200 OK
또는 `상태: ok`라는 메시지가 반환되면 Odoo에서 웹훅이 제대로 작동하는 것입니다. 새 테스트 연락처가 연락처 앱에 나타납니다. 여기에서 다른 도구로 구현을 시작한 후 웹훅 호출을 웹훅 URL을 사용하여 Odoo로 자동 전송할 수 있습니다.
다른 응답이 반환되는 경우, 해당 응답과 관련된 번호를 통해 문제를 식별할 수 있습니다. 예를 들어, 500 내부 서버 오류
는 Odoo에서 호출을 제대로 해석하지 못한다는 의미입니다. 이 응답이 반환되면 JSON 파일에서 찾은 필드가 웹훅 설정과 Postman에서 제대로 매핑되었는지 확인하세요.