
# 获取桶的事件通知配置(Node.js SDK)
![](https://support.huaweicloud.com/sdk-nodejs-devg-obs/public_sys-resources/notice_3.0-zh-cn.png)
开发过程中，您有任何问题可以在GitHub上[提交issue](https://github.com/huaweicloud/huaweicloud-sdk-nodejs-obs/issues)，或者在[华为云对象存储服务论坛](https://bbs.huaweicloud.com/forum/forum-620-1.html)中发帖求助。
#### 功能说明
获取指定桶的通知配置信息。
#### 方法定义
```
ObsClient.getBucketNotification
```
#### 请求参数
| **参数名称**    | **参数类型**                                                                    | **约束** | **描述**                                                                                                  |
|:---|:---|:---|:---|
| Bucket      | String                                                                      | 必选     | 桶名。                                                                                                     |
| RequestDate | String 或 Date | 可选     | 指定请求时间。 说明： 当为String类型时，必须符合ISO8601或RFC822规范。 |
   
#### 返回结果（InterfaceResult）
| **参数名称**       |||| **参数类型** | **描述**                                                |
|:--|---|---|---|:---|:---|
| RequestId      |||| String   | OBS服务端返回的请求ID。                                        |
| TopicConfigurations |||| Array    | 消息通知服务配置列表。                                           |
| - | ID          ||| String   | 消息通知服务配置ID。                                           |
| - | Topic       ||| String   | 事件通知主题的URN，当OBS检测到桶中发生特定的事件后，将会发布通知消息至该主题。            |
| - | Event       ||| Array    | 需要发布通知消息的事件类型列表。                                      |
| - | Filter      ||| Object   | 过滤规则信息。                                               |
| - | - | FilterRules || Array    | 过滤规则列表。                                               |
| - | - | - | Name  | String   | 指定规则按对象名前缀或者后缀进行过滤。                                   |
| - | - | - | Value | String   | 指定的对象名关键字，用以按照前缀或者后缀过滤对象。                             |
| FunctionGraphConfigurations |||| Array    | 函数工作流服务配置列表。                                          |
| - | ID          ||| String   | 函数工作流服务配置ID。                                          |
| - | FunctionGraph ||| String   | 函数工作流服务的URN，当OBS检测到桶中发生特定的事件后，将会发送消息至函数工作流服务调用执行该工作流。 |
| - | Event       ||| Array    | 需要发送消息至函数工作流服务的事件类型列表。                                |
| - | Filter      ||| Object   | 过滤规则信息。                                               |
| - | - | FilterRules || Array    | 过滤规则列表。                                               |
| - | - | - | Name  | String   | 指定规则按对象名前缀或者后缀进行过滤。                                   |
| - | - | - | Value | String   | 指定的对象名关键字，用以按照前缀或者后缀过滤对象。                             |
   
#### 代码示例
您可以通过ObsClient.getBucketNotification查看桶的事件通知。以下代码展示了如何查看桶的事件通知：
```
// 引入obs库
// 使用npm安装
var ObsClient = require('esdk-obs-nodejs');
// 使用源码安装
// var ObsClient = require('./lib/obs');
// 创建ObsClient实例
const obsClient = new ObsClient({
    //推荐通过环境变量获取AKSK，这里也可以使用其他外部引入方式传入，如果使用硬编码可能会存在泄露风险。
    //您可以登录访问管理控制台获取访问密钥AK/SK，获取方式请参见https://support.huaweicloud.com/usermanual-ca/ca_01_0003.html
    access_key_id: process.env.ACCESS_KEY_ID,
    secret_access_key: process.env.SECRET_ACCESS_KEY,
    //这里以华北-北京四为例，其他地区请按实际情况填写
    server: 'https://obs.cn-north-4.myhuaweicloud.com'
    
});
obsClient.getBucketNotification({
       Bucket : 'bucketname'
},(err, result) => {
       if(err){
              console.error('Error-->' + err);
       }else{
              console.log('Status-->' + result.CommonMsg.Status);
              if(result.CommonMsg.Status < 300 && result.InterfaceResult){
                 if(result.InterfaceResult.TopicConfigurations){
                     for(let j=0;j<result.InterfaceResult.TopicConfigurations.length;j++){
                         console.log('ID-->' + result.InterfaceResult.TopicConfigurations[j].ID);
                         console.log('Topic-->' + result.InterfaceResult.TopicConfigurations[j].Topic);
                         console.log('Event-->' + result.InterfaceResult.TopicConfigurations[j].Event);
                         if(result.InterfaceResult.TopicConfigurations[j].Filter){
                               for(let i=0;i<result.InterfaceResult.TopicConfigurations[j].Filter.FilterRules.length;i++){
                                      console.log('FilterRule[' + i + '][Name]-->' + result.InterfaceResult.TopicConfigurations[j].Filter.FilterRules[i].Name);
                                      console.log('FilterRule[' + i + '][Value]-->' + result.InterfaceResult.TopicConfigurations[j].Filter.FilterRules[i].Value);
                               }
                         }
                     }
                 }
                 if(result.InterfaceResult.FunctionGraphConfigurations){
                     for(let j=0;j<result.InterfaceResult.FunctionGraphConfigurations.length;j++){
                         console.log('ID-->' + result.InterfaceResult.FunctionGraphConfigurations[j].ID);
                         console.log('Topic-->' + result.InterfaceResult.FunctionGraphConfigurations[j].FunctionGraph);
                         console.log('Event-->' + result.InterfaceResult.FunctionGraphConfigurations[j].Event);
                         if(result.InterfaceResult.FunctionGraphConfigurations[j].Filter){
                               for(let i=0;i<result.InterfaceResult.FunctionGraphConfigurations[j].Filter.FilterRules.length;i++){
                                      console.log('FilterRule[' + i + '][Name]-->' + result.InterfaceResult.FunctionGraphConfigurations[j].Filter.FilterRules[i].Name);
                                      console.log('FilterRule[' + i + '][Value]-->' + result.InterfaceResult.FunctionGraphConfigurations[j].Filter.FilterRules[i].Value);
                               }
                         }
                     }
                 }
              }
       }
});
```
