가비아의 개발 노하우로
API를 제공합니다
API를 제공합니다
API 개발 가이드
- 알림톡 API 사용 첫 단계
- 알림톡을 이용하기 전, 발송 IP와 알림톡 전용 발신 번호, 사전 템플릿 등록 및 API Key를 확인하세요.
API 연동 방법
연동 방법
알림톡 Open API
- - 제공 언어: PHP, JAVA, PYTHON, NODE, RUBY, cURL, GO
- - 하단의 이용 매뉴얼 참고
- 사용자 인증
- SMS ID와 API Key로 토큰을 발행해 사용자를 인증합니다.
- - 사용자 인증 단계에서만, Authroization에 'API_ KEY' 값을 넣어주세요.
- POST https://sms.gabia.com/oauth/token
- HEADERS
Content-Type application/x-www-form-urlencoded Authorization Basic base64encode(SMS_ID:API_KEY)
(예) Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ=- BODY
grant_type client_credentials - RESPONSE
성공케이스 {
"access_token": "your_access_token",
"refresh_token": "your_refresh_token",
"expires_in": 3600,
"scope": "basic",
"create_on": "2022-01-01 00:00:01",
"is_expires": "N",
"token_type": "basic",
"code": "basic"
}실패케이스 {"message": "SMS ID나 API KEY가 잘못되었습니다."}
{"message": "unsupported_grant_type (grant_type 값을 확인해주세요.)"}* Authorization 값 확인이 안 되는 경우, {"message": "client_id empty"} 또는 {"message": "client_secret empty"}가 출력됩니다.
sms_id:api_key 형태로 base64인코딩 규격을 맞춰주세요.<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://sms.gabia.com/oauth/token", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => false, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "grant_type=client_credentials", CURLOPT_HTTPHEADER => array( "Content-Type: application/x-www-form-urlencoded", "Authorization: Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ=" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } ?>
import com.google.gson.Gson; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.HashMap; import java.util.Objects; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; // 외부 라이브러리 다운로드가 필요합니다. (gradle 기준) // implementation 'com.squareup.okhttp3:okhttp:4.9.3' https://mvnrepository.com/artifact/com.squareup.okhttp/okhttp // implementation 'com.google.code.gson:gson:2.9.0' https://github.com/google/gson public class userAuth { public static final String SMS_OAUTH_TOKEN_URL = "https://sms.gabia.com/oauth/token"; // ACCESS TOKEN 발급 API URL 입니다. public static void main(String[] args) throws IOException { String smsId = "YOUR_SMS_ID"; // SMS ID 를 입력해 주세요. String apiKey = "YOUR_API_KEY"; // SMS 관리툴에서 발급받은 API KEY 를 입력해 주세요. String authValue = Base64.getEncoder().encodeToString(String.format("%s:%s", smsId, apiKey).getBytes(StandardCharsets.UTF_8)); // Authorization Header 에 입력할 값입니다. // 사용자 인증 API 를 호출합니다. OkHttpClient client = new OkHttpClient(); RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM) .addFormDataPart("grant_type", "client_credentials") .build(); Request request = new Request.Builder() .url(SMS_OAUTH_TOKEN_URL) .post(requestBody) .addHeader("Content-Type", "application/x-www-form-urlencoded") .addHeader("Authorization", "Basic " + authValue) .addHeader("cache-control", "no-cache") .build(); // Response 를 key, value 로 확인하실 수 있습니다. Response response = client.newCall(request).execute(); HashMap<String, String> result = new Gson().fromJson(Objects.requireNonNull(response.body()).string(), HashMap.class); for(String key : result.keySet()) { System.out.printf("%s: %s%n", key, result.get(key)); } } }
import requests url = 'https://sms.gabia.com/oauth/token' payload = 'grant_type=client_credentials' headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': 'Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ=' } response = requests.request('POST', url, headers = headers, data = payload, allow_redirects=False, timeout=undefined) print(response.text)
var https = require('https'); var qs = require('querystring'); var postData = qs.stringify({ 'grant_type': 'client_credentials' }); var options = { method: 'POST', hostname: 'sms.gabia.com', path: '/oauth/token', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Content-Length': Buffer.byteLength(postData), 'Authorization': 'Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ=' } }; var req = https.request(options, function (res) { var chunks = []; res.on("data", function (chunk) { chunks.push(chunk); }); res.on("end", function (chunk) { var body = Buffer.concat(chunks); console.log(body.toString()); }); res.on("error", function (error) { console.error(error); }); }); req.write(postData); req.end();
require "uri" require "net/http" url = URI("https://sms.gabia.com/oauth/token") https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Post.new(url) request["Content-Type"] = "application/x-www-form-urlencoded" request["Authorization"] = "Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ=" request.body = "grant_type=client_credentials" response = https.request(request) puts response.read_body
curl --location --request POST "https://sms.gabia.com/oauth/token" \ --header "Content-Type: application/x-www-form-urlencoded" \ --header "Authorization: Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ=" \ --data "grant_type=client_credentials"
package main import ( "fmt" "strings" "os" "path/filepath" "net/http" "io/ioutil" ) func main() { url := "https://sms.gabia.com/oauth/token" method := "POST" payload := strings.NewReader("grant_type=client_credentials") client := &http.Client { CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, } req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) } req.Header.Add("Content-Type", "application/x-www-form-urlencoded") req.Header.Add("Authorization", "Basic c1hY3JvY2sZDAwNzA2YzJlMTdjZjlkMz1234hlM2U5YjQ=") res, err := client.Do(req) defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) fmt.Println(string(body)) }
- 카카오 알림톡 발송하기
- 카카오 알림톡을 발송할 수 있습니다. 사전에 등록한 템플릿과 템플릿에 입력할 변수로 메시지를 정의할 수 있습니다. 발송 시간을 정의할 경우 예약 발송을 진행할 수도 있습니다.
-
- 알림톡 발송 시 Authorization에 'ACCESS TOKEN' 값을 넣어주세요.
- 발송 시간을 정의하지 않을 경우 요청 즉시 알림톡이 발송됩니다.
- 'template_id' 값은 [SMS관리툴 > 환경 설정 > 알림톡 템플릿]에서 확인할 수 있습니다. - POST https://sms.gabia.com/api/send/alimtalk
- HEADERS
Authorization Basic base64encode(SMS_ID:**ACCESS_TOKEN**)
(예) Basic DckviEksLs6ZXlKMGVYQWlPaUpLVhiR2NpT2lKU1V6STFOaUo5LmV5SnBjM01pT2lKb2RIUndjenBjTDF3dmMyMXpMbWRoWW1saExtTnZiVnd2SWl3aVlYVmtJam9pWEM5dllYVjBhRnd2ZEc5clpXNGlMQ0pshWFhnT2pBNG5uVkVuLWtnVEJoRGpPeWc=- BODY
phone 01000000000 template_id 1 template_variable 변수1|변수2|변수3 request_time 211207030001
(YYYYMMhhmmss,선택)- RESPONSE
성공케이스 {
"code": "200",
"message": "Success",
"data": {
"LEFT_TALK_COUNT": 잔여 토큰 수(number),
"TALK_MESSAGE_ID": 메시지 아이디(UUID)
}
}실패케이스 {
"code": "talk_message_save_error",
"message": "메시지를 저장할 수 없습니다."
}
{
"code": "talk_message_send_error",
"message": "메시지를 발송할 수 없습니다."
}
...<?php $smsId = "YOUR_SMS_ID"; // SMS ID 를 입력해 주세요. $accessToken = "YOUR_ACCESS_TOKEN"; // ACCESS TOKEN(API_KEY) 을 입력해 주세요. $authValue = base64_encode($smsId . ':' . $accessToken); // Authorization Header 에 입력할 값입니다. $curl = curl_init(); // SMS 발송 API 를 호출합니다. curl_setopt_array($curl, array( CURLOPT_URL => 'https://sms.gabia.com/api/send/alimtalk', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', // 수신번호를 입력해 주세요. // 발송에 사용할 알림톡 템플릿 아이디를 입력해 주세요. // 알림톡 템플릿에 사용할 변수를 입력해 주세요. CURLOPT_POSTFIELDS => '{ "phone" : "01000000000", "template_id": 1, "template_variable" : "변수1|변수2|변수3", "request_time": "211207030001" } ', CURLOPT_HTTPHEADER => array( 'Authorization: Basic ' . $authValue ), )); // Response 를 key, value 로 확인하실 수 있습니다. $response = json_decode(curl_exec($curl)); curl_close($curl); foreach ($response as $key => $value) { echo $key . " : " . $value . "<br/>"; }
package hello.alimtalkTest; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import java.io.IOException; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; import java.util.Base64; import java.util.HashMap; import java.util.Objects; import okhttp3.MultipartBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; /** * 외부 라이브러리 다운로드가 필요합니다. 라이브러리 추가 방법은 링크를 참고해주세요. * 1. com.squareup.okhttp3:okhttp:4.9.3, <a href="https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp/4.9.3">링크</a> * 2. com.google.code.gson:gson:2.9.0, <a href="https://mvnrepository.com/artifact/com.google.code.gson/gson/2.9.0">링크</a> */ public class SendAlimTalk { private static final String ALIMTALK_SEND_URL = "https://sms.gabia.com/api/send/sms"; private static final ObjectMapper objectMapper = new ObjectMapper(); public static void main(String[] args) throws IOException { String smsId = "YOUR_SMS_ID"; // SMS ID 를 입력해 주세요. String accessToken = "YOUR_ACCESS_TOKEN"; // ACCESS TOKEN(API_KEY) 을 입력해 주세요. String authValue = Base64.getEncoder().encodeToString(String.format("%s:%s", smsId, accessToken).getBytes( StandardCharsets.UTF_8)); // Authorization Header 에 입력할 값입니다. // SMS 발송 API 를 호출합니다. OkHttpClient client = new OkHttpClient(); RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM) .addFormDataPart("phone", "RECEIPT_PHONE_NUMBER") // 수신번호를 입력해 주세요. .addFormDataPart("template_id", "TEMPLATE_ID") // 발송에 사용할 알림톡 템플릿 아이디를 입력해 주세요. .addFormDataPart("template_variable", "YOUR_REF_KEY") // 알림톡 템플릿에 사용할 변수를 입력해 주세요. .addFormDataPart("request_time", "YOUR_REQUEST_TIME") .build(); Request request = new Request.Builder() .url(ALIMTALK_SEND_URL) .post(requestBody) .addHeader("Content-Type", "application/json") .addHeader("Authorization", "Basic " + authValue) .addHeader("cache-control", "no-cache") .build(); Response response = client.newCall(request).execute(); // Response 를 key, value 로 확인하실 수 있습니다. Type collectionType = new TypeToken<HashMap<String, String>>() { }.getType(); HashMap<String, String> result = new Gson().fromJson(Objects.requireNonNull(response.body()).string(), collectionType); for (String key : result.keySet()) { System.out.printf("%s: %s%n", key, result.get(key)); } } }
import requests import json import base64 def base64_encode(str): bytes = str.encode('UTF-8') result = base64.b64encode(bytes) return result.decode('ascii') url = "https://sms.gabia.com/api/send/alimtalk" smsId="YOUR_SMS_ID" # SMS ID 를 입력해 주세요. accessToken="YOUR_ACCESS_TOKEN" # ACCESS TOKEN(API_KEY) 을 입력해 주세요. authValue=base64_encode(f"{smsId}:{accessToken}") payload = json.dumps({ "phone": "01000000000", # 수신번호를 입력해 주세요. "template_id": 1, # 발송에 사용할 알림톡 템플릿 아이디를 입력해 주세요. "template_variable": "테스트이름|테스트 회사|테스트 서비스" # 알림톡 템플릿에 사용할 변수를 입력해 주세요. }) headers = { 'Content-Type': 'application/json', 'Authorization': authValue } response = requests.request("POST", url, headers=headers, data=payload) print(response.text)
var request = require('request'); function base64_encode(str){ return Buffer.from(str,"utf8").toString('base64') } const smsId="YOUR_SMS_ID" // SMS ID 를 입력해 주세요. const accessToken="YOUR_ACCESS_TOKEN" // ACCESS TOKEN(API_KEY) 을 입력해 주세요. const authValue=base64_encode(`${smsId}:${accessToken}`) var options = { 'method': 'POST', 'url': 'https://sms.gabia.com/api/send/alimtalk', 'headers': { 'Content-Type': 'application/json', 'Authorization': 'Basic '+authValue }, body: JSON.stringify({ "phone": "01000000000", //수신번호를 입력해 주세요. "template_id": 1, // 발송에 사용할 알림톡 템플릿 아이디를 입력해 주세요. "template_variable": "테스트이름|테스트 회사|테스트 서비스" //알림톡 템플릿에 사용할 변수를 입력해 주세요. }) }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });
require "uri" require "json" require "net/http" require "base64" url = URI("https://sms.gabia.com/api/send/alimtalk") smsId="YOUR_SMS_ID" # SMS ID 를 입력해 주세요. accessToken="YOUR_ACCESS_TOKEN" # ACCESS TOKEN(API_KEY) 을 입력해 주세요. authValue=Base64.strict_encode64(smsId+":"+accessToken) https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Post.new(url) request["Content-Type"] = "application/json" request["Authorization"] = authValue request.body = JSON.dump({ "phone": "01000000000", # 수신번호를 입력해 주세요. "template_id": 1, # 발송에 사용할 알림톡 템플릿 아이디를 입력해 주세요. "template_variable": "테스트이름|테스트 회사|테스트 서비스" # 알림톡 템플릿에 사용할 변수를 입력해 주세요. }) response = https.request(request) puts response.read_body
curl --location 'https://sms.gabia.com/api/send/alimtalk' \ --header 'Content-Type: application/json' \ --header 'Authorization: Basic DckviEksLs6ZXlKMGVYQWlPaUpLVhiR2NpT2lKU1V6STFOaUo5LmV5SnBjM01pT2lKb2RIUndjenBjTDF3dmMyMXpMbWRoWW1saExtTnZiVnd2SWl3aVlYVmtJam9pWEM5dllYVjBhRnd2ZEc5clpXNGlMQ0pshWFhnT2pBNG5uVkVuLWtnVEJoRGpPeWc=' \ --data '{ "phone" : "01000000000", "template_id": 1, "template_variable" : "테스트이름|테스트 회사|테스트 서비스" } '
package main import b64 "encoding/base64" import ( "fmt" "io/ioutil" "net/http" "strings" ) func main() { smsId:="YOUR_SMS_ID" //SMS ID 를 입력해 주세요. accessToken:="YOUR_ACCESS_TOKEN" //ACCESS TOKEN(API_KEY) 을 입력해 주세요. authValue:= b64.StdEncoding.EncodeToString([]byte(smsId+":"+accessToken)) url := "https://stage-sms.gabia.com/api/send/alimtalk" method := "POST" payload := strings.NewReader(`{ "phone": "01000000000", //수신번호를 입력해 주세요. "template_id": 6, //발송에 사용할 알림톡 템플릿 아이디를 입력해 주세요. "template_variable": "테스트이름|테스트 회사|테스트 서비스" //알림톡 템플릿에 사용할 변수를 입력해 주세요. }`) client := &http.Client{} req, err := http.NewRequest(method, url, payload) if err != nil { fmt.Println(err) return } req.Header.Add("Content-Type", "application/json") req.Header.Add("Authorization", "Basic "+authValue) res, err := client.Do(req) if err != nil { fmt.Println(err) return } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) return } fmt.Println(string(body)) }
전문가와 상담하세요
- 비지니스솔루션 고객센터
- 1661-4370
- 대량발송문의(영업)
- 02-6948-3769