8. Stibee에 유저 메일 추가하기

Eden·2023년 8월 4일
0

Stibee에 유저 메일 추가하기

구독자 관리 플랫폼인 Stibee에 가입한 유저의 메일을 추가하는 api를 구현하고자 한다

필요한 패키지 설치
-Axios는 브라우저, Node.js를 위한 Promise API를 활용하는 HTTP 비동기 통신 라이브러리

npm install axios @nestjs/axios  

환경변수(.env)/유효성검사 추가
STIBEE_LIST_ID
STIBEE_ACCESS_TOKEN

auth.module에 해당 패키지를 import 시켜준다.

import { HttpModule } from '@nestjs/axios';

@Module({
  +
  HttpModule,
})

Stibee에 메일 추가하는 mathod 구현

public async subscribersToStibee(
  email: string,
  name: string,
  adAgree: boolean,
) {
  const listId = this.configService.get('STIBEE_LIST_ID');
  const stibeeAddress =  `https://api.stibee.com/v1//lists/${listId}/subscribers`;
  const options = {
  	headers: {
    	AccessToken: this.configService.get('STIBEE_ACCESS_TOKEN')
    }
  };
  const userInput = {
  	eventOccuredBy: 'MANUAL',
    confirmEmailYN: 'N',
    groupIds:[],
    subscribers:[{
      email,
      name,
      ad_agreed: adAgree ? 'Y' : 'N',
      tag1: 'email',
    }]
  };
  
  const { data } = await this.httpService.post(stibeeAddress, userInput, options).toPromise();
  return data.Ok;
}
  



profile
주섬주섬..

0개의 댓글