import java.io.*;
import java.net.*;
public class Cafe24ApiCallListAllCategories {
public static void main(String[] args) {
String accessToken = "{access_token}";//<---------------------- {access_token} modify
String mallId = "{mall_id}";//<-------------------------------- {mall_id} modify
String authorization = "Bearer " + accessToken; // {Bearer} Next required space!
String endpointUrl = "https://" + mallId + ".cafe24api.com/api/v2/admin/categories";
BufferedReader br = null;
HttpURLConnection con = null;
StringBuilder response = new StringBuilder();
try {
URL url = new URL(endpointUrl);
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", authorization);
con.setRequestProperty("Content-Type", "application/json");
int responseCode = con.getResponseCode();
System.err.println(responseCode);
if (responseCode == 200) { // Correct call
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else { // Error
br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
}
String line;
while ((line = br.readLine()) != null) {
response.append(line);
}
System.out.println(response.toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {br.close();} catch (IOException e) {e.printStackTrace();}
con.disconnect();
}
}
}
$sAccessToken = "{access_token}";
$sEndpointUrl = "https://{mall_id}.cafe24api.com/api/v2/admin/categories";
// Common code ▼
$oCurl = curl_init();
curl_setopt_array($oCurl, array(
CURLOPT_URL => $sEndpointUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Authorization: Bearer ' . $sAccessToken)
));
$sResponse = curl_exec($oCurl);
print_r($sResponse);
import urllib.request
access_token = "{access_token}" # <---------------------- {access_token} modify
mall_id = "{mall_id}" # <-------------------------------- {mall_id} modify
authorization = "Bearer " + access_token # {Bearer} Next required space!
api_url = "https://" + mall_id + ".cafe24api.com/api/v2/admin/categories"
request = urllib.request.Request(api_url)
request.add_header("Authorization", authorization)
request.add_header("Content-Type", "application/json")
response = urllib.request.urlopen(request)
rescode = response.getcode()
print(rescode)
if rescode == 200:
response_body = response.read()
print(response_body.decode('utf-8'))
else:
print("Error Code:" + rescode)
// ref: https://developers.cafe24.com/docs/api/front/#get-a-product
var getProduct = function () {
// required
var productNo = '{product_no}';
// optional params
var params = {
'variants': '{item_entity}',
'memos': '{memo_entity}',
'hits': '{hit_entity}',
'seo': '{seo_entity}',
'tags': '{tag_entity}',
'options': '{option_entity}'
};
var getProductURI = '/api/v2/products/' + productNo + '?'
+ encodeURIComponent(Object.keys(params).map(key => key + '=' + params[key]).join('&'));
CAFE24API.init('{client_id}')
.get(getProductURI, function(err, res){
console.log(err, res);
});
};
if (document.readyState === 'complete') {
getProduct();
} else {
window.addEventListener('load', getProduct);
}
import java.io.*;
import java.net.*;
public class Cafe24ApiCallCreateScripttag {
public static void main(String[] args) {
String accessToken = "{access_token}";//<---------------------- {access_token} modify
String mallId = "{mall_id}";//<-------------------------------- {mall_id} modify
String authorization = "Bearer " + accessToken; // {Bearer} Next required space!
String endpointUrl = "https://" + mallId + ".cafe24api.com/api/v2/admin/scripttags";
BufferedReader br = null;
HttpURLConnection con = null;
StringBuilder response = new StringBuilder();
try {
URL url = new URL(endpointUrl);
String postParams = "{\"shop_no\":1,\"request\":{\"src\":\"https://js-aplenty.com/bar.js\",\"display_location\":[\"PRODUCT_LIST\",\"PRODUCT_DETAIL\"],\"skin_no\":[3,4]}}";
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Authorization", authorization);
con.setRequestProperty("Content-Type", "application/json");
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(postParams);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.err.println(responseCode);
if (responseCode == 201) { // Correct call
br = new BufferedReader(new InputStreamReader(con.getInputStream()));
} else { // Error
br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
}
String line;
while ((line = br.readLine()) != null) {
response.append(line);
}
System.out.println(response.toString());
} catch (Exception e) {
e.printStackTrace();
} finally {
try {br.close();} catch (IOException e) {e.printStackTrace();}
con.disconnect();
}
}
}
$sAccessToken = "{access_token}";
$sEndpointUrl = "https://{mall_id}.cafe24api.com/api/v2/admin/scripttags";
$aPostData = array(
"shop_no" => "{shop_no}",
"request" => array(
"client_id" => "{client_id}",
"src" => "{javascript_src}",
"display_location" => array(
"{display_location_code}"
// ref: https://developer.cafe24.com/docs/api/admin/#display_location-code
)
)
);
$oCurl = curl_init();
curl_setopt_array($oCurl, array(
CURLOPT_URL => $sEndpointUrl,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => json_encode($aPostData),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer ' . $sAccessToken,
"Content-Type: application/json"
)
));
$sResponse = curl_exec($oCurl);
print_r($sResponse);
import urllib.request
import requests
access_token = "{access_token}" # <---------------------- {access_token} modify
mall_id = "{mall_id}" # <-------------------------------- {mall_id} modify
authorization = "Bearer " + access_token # Bearer Next required space!
endpoint_url = "https://" + mall_id + ".cafe24api.com/api/v2/admin/scripttags"
headers = {'Authorization': authorization, "Content-Type": "application/json"}
params = "{\"shop_no\":1,\"request\":{\"src\":\"https://js-aplenty.com/bar.js\",\"display_location\":[\"PRODUCT_LIST\",\"PRODUCT_DETAIL\"],\"skin_no\":[3,4]}}"
request = urllib.request.Request(endpoint_url)
request.add_header("Authorization", authorization)
request.add_header("Content-Type", "application/json")
response = requests.post(endpoint_url, headers=headers, data=params)
rescode = response.status_code
print(rescode)
if (rescode == 201):
print(response.text)
else:
print("Error Code : " + str(rescode))