카카오 알림톡 API Unauthorized 권한 관련 문의 #60
-
사용 중인 프로그래밍 언어 및 버전Node.js v20.11.1(Next.js 기반) SDK 버전REST API 사용 운영 환경개발 환경 (로컬) 질문/문제 설명고객 예약확정 시 자동으로 카카오 알림톡 발송을 구현하려고 합니다. 코드 예시// API 호출부
import type { NextApiRequest, NextApiResponse } from 'next';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method !== 'POST') {
return res.status(405).json({ success: false, message: 'Method Not Allowed' });
}
const apiKey = process.env.API_KEY!;
const apiSecret = process.env.API_SECRET!;
const {
name,
phone,
carModel,
carNumber,
destination
} = req.body;
const data = {
message: {
to: phone,
from: '[발신번호]', // 실제 발신번호 (010-xxxx-xxxx)
kakaoOptions: {
pfId: '[pfId]', // 등록된 pfId
templateId: '[templateId]', // 등록된 템플릿 ID
variables: {
name,
phone,
reserveDateTime,
carModel,
carNumber,
destination
}
}
}
};
try {
const response = await fetch(`https://api.solapi.com/messages/v4/send?api_key=${apiKey}&api_secret=${apiSecret}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
const responseData = await response.json();
return res.status(200).json({ success: true, data: responseData });
} catch (error: any) {
return res.status(500).json({ success: false, message: error.message });
}
}
// API 호출 부분(알림톡 전송)
await fetch('/api/send-sms', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
name: target.name,
phone: target.phone,
carModel: target.carType,
carNumber: target.car,
destination: target.city
}),
});시도한 해결 방법
기대하는 결과정상적으로 설정한 비즈니스채널에서 해당 번호로 알림톡 발송이 이뤄집니다. 확인사항
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
안녕하세요 회원님, 솔라피 기술지원팀입니다. 제공하신 코드를 확인했을 때 헤더에 관련한 인증코드가 없는 것으로 보입니다. 당사의 Node.js SDK 인증 코드를 보내드리며, Node.js SDK를 이용하시면 손쉽게 개발 연동을 진행하실 수 있습니다. 아래에 Next.js Node.js SDK 연동 예제도 첨부드리오니 참고 부탁드리겠습니다. Node.js SDK 상 인증 코드: Next.js + SOLAPI Node.js SDK 예제 코드: 감사합니다. |
Beta Was this translation helpful? Give feedback.
안녕하세요 회원님, 솔라피 기술지원팀입니다. 제공하신 코드를 확인했을 때 헤더에 관련한 인증코드가 없는 것으로 보입니다. 당사의 Node.js SDK 인증 코드를 보내드리며, Node.js SDK를 이용하시면 손쉽게 개발 연동을 진행하실 수 있습니다. 아래에 Next.js Node.js SDK 연동 예제도 첨부드리오니 참고 부탁드리겠습니다.
Node.js SDK 상 인증 코드:
https://github.com/solapi/solapi-nodejs/blob/master/src/lib/defaultFetcher.ts
Next.js + SOLAPI Node.js SDK 예제 코드:
https://github.com/solapi/solapi-nodejs/tree/master/examples/nextjs
감사합니다.