Skip to content

Instantly share code, notes, and snippets.

@will-yama
Created June 19, 2023 11:30
Show Gist options
  • Save will-yama/e82913ce36f488ddf96dbe6279bc4962 to your computer and use it in GitHub Desktop.
Save will-yama/e82913ce36f488ddf96dbe6279bc4962 to your computer and use it in GitHub Desktop.
Various sample HTTP requests to a Kintone App
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Proyecto26;
using SimpleJSON;
public class add_record_to_kintone : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
//リクエストボディのJSONを作成する
JSONObject RequestBody = new JSONObject();
RequestBody["app"] = "{PLACE_APP_ID_HERE}";
JSONObject RecordObject = new JSONObject();
JSONObject MangaTitleObject = new JSONObject();
MangaTitleObject["value"] = "ドラゴンボール";
RecordObject["manga_title"] = MangaTitleObject;
JSONObject MangaArtistObject = new JSONObject();
MangaArtistObject["value"] = "鳥山明";
RecordObject["manga_artist"] = MangaArtistObject;
RequestBody["record"] = RecordObject;
//上記のボディを含めたPOSTのHTTPリクエストを送信する
RestClient.Post(new RequestHelper {
Uri = "{PLACE_API_REQUEST_ENDPOINT_HERE}",
Headers = new Dictionary<string, string>
{
{ "X-Cybozu-API-Token", "{PLACE_API_TOKEN_HERE}" }
},
BodyString = RequestBody.ToString()
}).Then(response => {
//リクエストが成功した場合
Debug.Log(response.Text);
//レスポンスをJSONNode型に入れることで、特定のデータを抜きやすくする
JSONNode jsondata = JSON.Parse(response.Text);
Debug.Log("追加されたレコードのID: " + jsondata["id"].Value);
}).Catch(err =>{
//リクエストが失敗した場合
var error = err as RequestException;
Debug.Log(error.Response);
});
}
}
const axios = require("axios");
async function addRecord() {
const API_endpoint = "{PLACE_API_REQUEST_ENDPOINT_HERE}";
const appId = "{PLACE_APP_ID_HERE}";
const headers = {
"X-Cybozu-API-Token": "{PLACE_API_TOKEN_HERE}",
"Content-Type": "application/json"
};
const data = {
app: appId,
record: {
title: { value: "ドラゴンボール" },
artist: { value: "鳥山明" }
}
};
try {
const response = await axios.post(API_endpoint, data, { headers });
console.log(response.data);
} catch (error) {
console.error(error.response.data);
}
}
addRecord();
import requests
import json
def add_record():
API_endpoint = "{PLACE_API_REQUEST_ENDPOINT_HERE}"
app_id = "{PLACE_APP_ID_HERE}"
kintone_headers = {
"X-Cybozu-API-Token": "{PLACE_API_TOKEN_HERE}",
"Content-Type": "application/json"
}
bodydata = {
"app": app_id,
"record": {
"title": {
"value": "ドラゴンボール"
},
"artist": {
"value": "鳥山明"
}
}
}
try:
response = requests.post(API_endpoint, headers=kintone_headers, data=json.dumps(bodydata))
jsondata = response.json()
print(jsondata)
except requests.exceptions.RequestException as error:
print(error)
add_record()
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Proyecto26;
using SimpleJSON;
public class get_records_from_kintone : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
RestClient.Get(new RequestHelper {
Uri = "{PLACE_API_REQUEST_ENDPOINT_HERE}",
Headers = new Dictionary<string, string>
{
{ "X-Cybozu-API-Token", "{PLACE_API_TOKEN_HERE}" }
},
Params = new Dictionary<string, string>
{
{ "app", "{PLACE_APP_ID_HERE}" }
},
DefaultContentType = false //デフォルトでapplication/jsonなので無効にする
}).Then(response => {
Debug.Log(response.Text);
//レスポンスをJSONNode型に入れることで、特定のデータを抜きやすくする
JSONNode jsondata = JSON.Parse(response.Text);
Debug.Log(jsondata["records"][0]["manga_title"]["value"].Value);
}).Catch(err =>{
var error = err as RequestException;
Debug.Log(error.Response);
});
}
}
const axios = require("axios");
async function get_all_records() {
const API_endpoint = "{PLACE_API_REQUEST_ENDPOINT_HERE}";
const app_Id = "{PLACE_APP_ID_HERE}";
const parameters = "?app=" + app_Id;
const headers = {
"X-Cybozu-API-Token": "{PLACE_API_TOKEN_HERE}"
};
try {
const response = await axios.get(API_endpoint + parameters, { headers });
const records = response.data.records;
console.log(records);
} catch (error) {
console.error(error);
}
}
get_all_records();
import requests
def get_all_records():
API_endpoint = "{PLACE_API_REQUEST_ENDPOINT_HERE}"
app_id = "{PLACE_APP_ID_HERE}"
API_endpoint = API_endpoint + "?app=" + app_id
kintone_headers = {
"X-Cybozu-API-Token": "{PLACE_API_TOKEN_HERE}",
}
try:
response = requests.get(API_endpoint, headers=kintone_headers)
jsondata = response.json()
print(jsondata)
except requests.exceptions.RequestException as error:
print(error)
get_all_records()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment