자율차마스터정보 (수집)
자율주행 서비스의 자율 주행 차량 마스터 정보를 수집하여 플랫폼 내에 적재하는 기능을 제공합니다.
Last updated
자율주행 서비스의 자율 주행 차량 마스터 정보를 수집하여 플랫폼 내에 적재하는 기능을 제공합니다.
Last updated
https://service.mqnicrnd5.com/api/v1/acm/collect/pacm
일정 주기 마다 (추후 안내 예정), 변경 시
HTTPS
POST
API를 요청할 때 다음 예와 같이 HTTP 요청 헤더에 접근 토큰(Access Token) 을 추가해야 합니다. 접근 토큰 앞에 "Bearer " 문자열을 추가해야 한다는 점에 주의하세요.
> POST /api/v1/acm/collect/pacm
> Host: service.mqnicrnd5.com
> User-Agent: curl/7.64.1
> Accept: */*
> Authorization: Bearer <접근 토큰>
curl --location 'http://localhost:8001/api/v1/acm/collect/pacm' \
--header 'Authorization: Bearer <접근 토큰>' \
--header 'Content-Type: application/json' \
--data '{
"deltaUpdateFlag": "n",
"autonomousCarMaster": [
{
"vehicleId": "99371",
"serviceNo": "10",
"vehicleType": "",
"maker": "",
"updateType": "I",
"updateDttm": "20240617142040"
}
]
}'
수집 API의 경우 별도 응답 파라미터가 아닌 HTTP Status Code로 성공 여부를 구분합니다.
200
성공
400
요청 파라미터 검증 실패
401
인증 실패
500
서버 오류
다음은 각 언어별 자율차마스터정보 수집 API 구현 예제입니다.
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.json.JSONObject; // JSON 라이브러리 추가 필요
public class CallAPI {
public static void main(String[] args) {
String accessToken = "Bearer <접근 토큰>"; // 실제 접근 토큰으로 교체 필요
// JSON 객체 생성
JSONObject jsonObject = new JSONObject();
jsonObject.put("deltaUpdateFlag", "y");
// 'autonomousCarMaster' JSON 배열, 객체 생성 및 삽입
JSONArray jsonArray = new JSONArray();
JSONObject acm = new JSONObject();
acm.put("vehicleId", "99371");
acm.put("serviceNo", "10");
acm.put("vehicleType", "");
acm.put("maker", "");
acm.put("updateType", "I");
acm.put("updateDttm", "20240617142040");
jsonArray.put(acm);
// 위와 같이 jsonArray에 다른 자율차량 데이터들 추가
jsonObject.put("autonomousCarMaster", jsonArray);
String apiURL = "https://service.mqnicrnd5.com/api/v1/acm/collect/pacm"; // POST 요청 URL
String responseBody = post(apiURL, jsonObject.toString(), accessToken);
System.out.println(responseBody);
}
private static String post(String apiUrl, String jsonInputString, String accessToken) {
HttpURLConnection con = connect(apiUrl);
try {
con.setRequestMethod("POST");
con.setRequestProperty("Authorization", accessToken);
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
try(OutputStream os = con.getOutputStream()) {
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) { // 정상 호출
return readBody(con.getInputStream());
} else { // 오류 발생
return readBody(con.getErrorStream());
}
} catch (IOException e) {
throw new RuntimeException("API 호출 중 오류 발생: ", e);
} finally {
con.disconnect();
}
}
private static HttpURLConnection connect(String apiUrl) {
try {
URL url = new URL(apiUrl);
return (HttpURLConnection) url.openConnection();
} catch (MalformedURLException e) {
throw new RuntimeException("API URL이 잘못되었습니다. : " + apiUrl, e);
} catch (IOException e) {
throw new RuntimeException("연결이 실패했습니다. : " + apiUrl, e);
}
}
private static String readBody(InputStream body) {
InputStreamReader streamReader = new InputStreamReader(body);
try (BufferedReader lineReader = new BufferedReader(streamReader)) {
StringBuilder responseBody = new StringBuilder();
String line;
while ((line = lineReader.readLine()) != null) {
responseBody.append(line);
}
return responseBody.toString();
} catch (IOException e) {
throw new RuntimeException("API 응답을 읽는 데 실패했습니다.", e);
}
}
}
import requests
import json
def call_api():
access_token = "Bearer <접근 토큰>" # 실제 접근 토큰으로 교체 필요
# 데이터 구조 생성
data = {
"deltaUpdateFlag": "y",
"autonomousCarMaster": [
{
"vehicleId": "99373",
"serviceNo": "10",
"vehicleType": "",
"maker": "",
"updateType": "U",
"updateDttm": "20240617144900"
}
]
}
api_url = "https://service.mqnicrnd5.com/api/v1/acm/collect/pacm"
headers = {
"Authorization": access_token,
"Content-Type": "application/json",
"Accept": "application/json"
}
response = requests.post(api_url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
return response.text
else:
return f"Error: {response.status_code}, Message: {response.text}"
if __name__ == "__main__":
print(call_api())
const axios = require('axios');
async function callAPI() {
const accessToken = 'Bearer <접근 토큰>'; // 실제 접근 토큰으로 교체 필요
const data = {
deltaUpdateFlag: 'y',
autonomousCarMaster: [
{
vehicleId: '99370',
serviceNo: '10',
vehicleType: '',
maker: '',
updateType: 'U',
updateDttm: '20230401201530'
}
]
};
const config = {
method: 'post',
url: 'https://service.mqnicrnd5.com/api/v1/acm/collect/pacm',
headers: {
'Authorization': accessToken,
'Content-Type': 'application/json'
},
data: data
};
try {
const response = await axios(config);
console.log(response.data);
} catch (error) {
console.error(`Error: ${error.response.status}, Message: ${error.response.data}`);
}
}
callAPI();
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace APICallExample
{
class Program
{
static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
await CallAPI();
}
static async Task CallAPI()
{
var apiUrl = "https://service.mqnicrnd5.com/api/v1/acm/collect/pacm";
var accessToken = "Bearer <접근 토큰>"; // 실제 접근 토큰으로 교체 필요
var requestData = new
{
deltaUpdateFlag = "n",
autonomousCarMaster = new[]
{
new
{
vehicleId = "99371",
serviceNo = "10",
vehicleType = "",
maker = "",
updateType = "I",
updateDttm = "20240617142040"
}
}
};
var jsonRequest = JsonSerializer.Serialize(requestData);
var content = new StringContent(jsonRequest, Encoding.UTF8, "application/json");
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "<접근 토큰>"); // 헤더에 인증 정보 추가
try
{
var response = await client.PostAsync(apiUrl, content);
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
Console.WriteLine($"\nException Caught!");
Console.WriteLine($"Message :{e.Message} ");
}
}
}
}