---
title: "쇼핑 인사이트 예제"
slug: "naver-api-hub-shopping-insight-examples"
updated: 2026-06-25T09:06:51Z
published: 2026-06-25T09:06:51Z
canonical: "api.ncloud-docs.com/naver-api-hub-shopping-insight-examples"
---

> ## Documentation Index
> Fetch the complete documentation index at: https://api.ncloud-docs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 쇼핑 인사이트 예제

Classic/VPC 환경에서 이용 가능합니다.

쇼핑 인사이트 API로 쇼핑 분야별 검색 클릭 트렌드를 조회하는 구현 예제입니다. 쇼핑 인사이트 API의 다른 작업을 구현하는 방법도 이와 유사하기 때문에 이 구현 예제를 참고하면 쇼핑 인사이트 API를 구현할 수 있습니다.

참고

- 샘플 코드의 `YOUR_CLIENT_ID`에는 네이버 클라우드 플랫폼 콘솔에서 발급받은 Client ID를, `YOUR_CLIENT_SECRET`에는 Client ID에 매핑되는 Client Secret을 입력해 주십시오.
- Client ID와 Client Secret 발급 방법은 [NAVER API HUB 개요](/docs/naver-api-hub-overview#API%ED%82%A4)를 참조해 주십시오.

## 분야별 트렌드 조회

네이버 통합검색의 쇼핑 영역과 네이버쇼핑에서의 검색 클릭 추이를 쇼핑 분야별로 조회하는 쇼핑 인사이트 API 예제를 설명합니다. 요청 바디의 `category`와 검색 조건(`device`, `ages`, `gender` 등)을 다른 값으로 교체하면 동일한 방식으로 다른 분야의 클릭 추이를 조회할 수 있습니다.

### Java

Java 기반의 Shopping Insight API 예제 코드는 다음과 같습니다.

```
package com.naver.apihub.example;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

public class ApiExampleShoppingCategories {

    public static void main(String[] args) {
        String clientId = "YOUR_CLIENT_ID"; // 애플리케이션 Client ID
        String clientSecret = "YOUR_CLIENT_SECRET"; // 애플리케이션 Client Secret

        String apiUrl = "https://naverapihub.apigw.ntruss.com/shopping/v1/categories";

        Map<String, String> requestHeaders = new HashMap<>();
        requestHeaders.put("X-NCP-APIGW-API-KEY-ID", clientId);
        requestHeaders.put("X-NCP-APIGW-API-KEY", clientSecret);
        requestHeaders.put("Content-Type", "application/json");

        String requestBody = "{\"startDate\":\"2026-01-01\"," +
                "\"endDate\":\"2026-05-31\"," +
                "\"timeUnit\":\"month\"," +
                "\"category\":[{\"name\":\"패션의류\",\"param\":[\"50000000\"]}," +
                             "{\"name\":\"화장품/미용\",\"param\":[\"50000002\"]}]," +
                "\"device\":\"pc\"," +
                "\"gender\":\"f\"," +
                "\"ages\":[\"20\",\"30\"]}";

        String responseBody = post(apiUrl, requestHeaders, requestBody);
        System.out.println(responseBody);
    }

    private static String post(String apiUrl, Map<String, String> requestHeaders, String requestBody) {
        HttpURLConnection con = connect(apiUrl);
        try {
            con.setRequestMethod("POST");
            for (Map.Entry<String, String> header : requestHeaders.entrySet()) {
                con.setRequestProperty(header.getKey(), header.getValue());
            }

            con.setDoOutput(true);
            try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) {
                wr.write(requestBody.getBytes(StandardCharsets.UTF_8));
                wr.flush();
            }

            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, StandardCharsets.UTF_8);
        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);
        }
    }
}
```

### PHP

PHP 기반의 Shopping Insight API 예제 코드는 다음과 같습니다.

```
<?php

$client_id = "YOUR_CLIENT_ID";
$client_secret = "YOUR_CLIENT_SECRET";

$url = "https://naverapihub.apigw.ntruss.com/shopping/v1/categories";
$body = "{\"startDate\":\"2026-01-01\",\"endDate\":\"2026-05-31\",\"timeUnit\":\"month\",\"category\":[{\"name\":\"패션의류\",\"param\":[\"50000000\"]},{\"name\":\"화장품/미용\",\"param\":[\"50000002\"]}],\"device\":\"pc\",\"gender\":\"f\",\"ages\":[\"20\",\"30\"]}";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = array();
$headers[] = "X-NCP-APIGW-API-KEY-ID: " . $client_id;
$headers[] = "X-NCP-APIGW-API-KEY: " . $client_secret;
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$response = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status_code == 200) {
    echo $response;
} else {
    echo "Error 내용:" . $response;
}
?>
```

### Node.js

Node.js 기반의 Shopping Insight API 예제 코드는 다음과 같습니다.

```
const client_id = 'YOUR_CLIENT_ID';
const client_secret = 'YOUR_CLIENT_SECRET';

const api_url = 'https://naverapihub.apigw.ntruss.com/shopping/v1/categories';
const request_body = {
  startDate: '2026-01-01',
  endDate: '2026-05-31',
  timeUnit: 'month',
  category: [
    { name: '패션의류', param: ['50000000'] },
    { name: '화장품/미용', param: ['50000002'] },
  ],
  device: 'pc',
  gender: 'f',
  ages: ['20', '30'],
};

(async () => {
  const response = await fetch(api_url, {
    method: 'POST',
    headers: {
      'X-NCP-APIGW-API-KEY-ID': client_id,
      'X-NCP-APIGW-API-KEY': client_secret,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(request_body),
  });
  console.log(response.status);
  console.log(await response.text());
})();
```

### Python

Python 기반의 Shopping Insight API 예제 코드는 다음과 같습니다.

```
import urllib.request

client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"

url = "https://naverapihub.apigw.ntruss.com/shopping/v1/categories"
body = "{\"startDate\":\"2026-01-01\",\"endDate\":\"2026-05-31\",\"timeUnit\":\"month\",\"category\":[{\"name\":\"패션의류\",\"param\":[\"50000000\"]},{\"name\":\"화장품/미용\",\"param\":[\"50000002\"]}],\"device\":\"pc\",\"gender\":\"f\",\"ages\":[\"20\",\"30\"]}"

request = urllib.request.Request(url)
request.add_header("X-NCP-APIGW-API-KEY-ID", client_id)
request.add_header("X-NCP-APIGW-API-KEY", client_secret)
request.add_header("Content-Type", "application/json")

response = urllib.request.urlopen(request, data=body.encode("utf-8"))
rescode = response.getcode()
if rescode == 200:
    response_body = response.read()
    print(response_body.decode("utf-8"))
else:
    print("Error Code:" + str(rescode))
```

### C#

C# 기반의 Shopping Insight API 예제 코드는 다음과 같습니다.

```
using System;
using System.IO;
using System.Net;
using System.Text;

namespace NaverApiHubExample
{
    public class ApiExampleShoppingCategories
    {
        static void Main(string[] args)
        {
            string clientId = "YOUR_CLIENT_ID";
            string clientSecret = "YOUR_CLIENT_SECRET";

            string url = "https://naverapihub.apigw.ntruss.com/shopping/v1/categories";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            request.Headers.Add("X-NCP-APIGW-API-KEY-ID", clientId);
            request.Headers.Add("X-NCP-APIGW-API-KEY", clientSecret);
            request.ContentType = "application/json";
            request.Method = "POST";

            string body = "{\"startDate\":\"2026-01-01\",\"endDate\":\"2026-05-31\",\"timeUnit\":\"month\",\"category\":[{\"name\":\"패션의류\",\"param\":[\"50000000\"]},{\"name\":\"화장품/미용\",\"param\":[\"50000002\"]}],\"device\":\"pc\",\"gender\":\"f\",\"ages\":[\"20\",\"30\"]}";
            byte[] byteData = Encoding.UTF8.GetBytes(body);
            request.ContentLength = byteData.Length;
            using (Stream st = request.GetRequestStream())
            {
                st.Write(byteData, 0, byteData.Length);
            }

            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
                {
                    Console.WriteLine(reader.ReadToEnd());
                }
            }
            catch (WebException e) // 에러 응답
            {
                using (StreamReader reader = new StreamReader(e.Response.GetResponseStream(), Encoding.UTF8))
                {
                    Console.WriteLine(reader.ReadToEnd());
                }
            }
        }
    }
}
```
