본문으로 건너뛰기

소개 및 사용법

1. 라이브러리 설치​

Swit Node Sdk는 NPM을 통해서 설치할수 있습니다.

프로젝트 Root에서 아래와 같은 명령어를 실행하세요.

npm install @swit-api/api-client @swit-api/oauth

2. ApiClient 생성하기​

oauth api로 가져온 토큰을 ApiClinet 생성자에 token값을 넣고 생성해주세요. 생성된 ApiClient의 v1 속성을 통해서 open api v1 관련 api를 호출할수 있는 메서드들을 제공합니다.

import { ApiClient, ApiClientConfig } from '@swit-api/api-client';

const token = process.env.SWIT_OPEN_API_TOKEN; // 액세스 토큰;
const config: ApiClientConfig= {
token: SWIT_OPEN_API_TOKEN,
};

const client = new ApiClient(config);
const clientV1 = client.v1;

3. Api 호출하기​

clientV1에는 비지니스 기준의 프로퍼티로 할당된 각 도메인 별 서비스를 사용할 수 있습니다.

아래 예시와 같이 유저 정보를 가져올수 있습니다.


const clientV1 = client.v1;

const res = await client.user.userInfo();

추가적인 ClientV1 정보는 아래 링크를 참고하시길 바랍니다.

4. Properties 별 서비스 clientV1 매핑​

Property명Service명
approvalApprovalService
channelChannelService
chatChatService
chatMessageChatMessageService
customFieldCustomFieldService
ideaIdeaService
ideaCommentIdeaCommentService
membershipMembershipService
messageMessageService
messageCommentMessageCommentService
projectProjectService
projectBucketProjectBucketService
taskTaskService
taskChecklistTaskChecklistService
taskCommentTaskCommentService
teamTeamService
userUserService
workspaceWorkspaceService

5.내부에서 사용하는 Axios instance 직접 접근 가능​

별도의 설정 커스텀이 필요한 경우에 내부에서 사용하는 Axios instance에 접근하여 사용할수도 있습니다.

const client = new ApiClient(config);
client.clientV1AxiosRef.interceptors.response.use(
(response) => {
// response handle
return response;
},
(error) => {
// error handle
return Promise.reject(error);
}
);