Skip to content

Instantly share code, notes, and snippets.

@potaracom
Last active December 16, 2020 13:57
Show Gist options
  • Save potaracom/f1e487a4a0975efde2dd7342b8a95ca2 to your computer and use it in GitHub Desktop.
Save potaracom/f1e487a4a0975efde2dd7342b8a95ca2 to your computer and use it in GitHub Desktop.
別ドメインのレコードを取得(kintone JavaScript API)
(() => {
"use strict";
kintone.events.on(["app.record.detail.show"], async (event) => {
const domain = "xxx.cybozu.com";
const app = "xxx";
const headers = {
"X-Cybozu-API-Token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
};
const query = encodeURIComponent('会社名 = "金都運総研"');
const url = `https://${domain}/k/v1/records.json`;
const queryString = `?app=${app}&query=${query}&fields[0]=$id&fields[1]=$revision&fields[2]=会社名&totalCount=true`;
const res = await kintone.proxy(`${url}${queryString}`, "GET", headers, {});
const { records, totalCount, message } = JSON.parse(res[0]);
if (res[1] === 200) {
console.log(records);
console.log(totalCount);
} else {
console.log(message);
}
return event;
});
})();
import qs from "qs";
interface DetailEvent {
appId: number;
record: kintone.types.SavedFields;
recordId: number;
type: string;
}
interface Params {
app: string;
query: string;
fields: string[];
totalCount: boolean;
}
kintone.events.on(["app.record.detail.show"], async (event: DetailEvent) => {
const domain = "xxx.cybozu.com";
const app = "xxx";
const headers = {
"X-Cybozu-API-Token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
};
const params: Params = {
app,
query: '会社名 = "金都運総研"',
fields: ["$id", "$revision", "会社名"],
totalCount: true,
};
const url = `https://${domain}/k/v1/records.json`;
const res = await kintone.proxy(
`${url}?${qs.stringify(params)}`,
"GET",
headers,
{}
);
const { records, totalCount, message } = JSON.parse(res[0]);
if (res[1] === 200) {
console.log(records);
console.log(totalCount);
} else {
console.log(message);
}
return event;
});
(() => {
"use strict";
kintone.events.on(["app.record.detail.show"], async (event) => {
const domain = "xxx.cybozu.com";
const app = "xxx";
const headers = {
"X-Cybozu-API-Token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Content-Type": "application/json",
"X-HTTP-Method-Override": "GET",
};
const data = {
app,
query: '会社名 = "金都運総研"',
fields: ["$id", "$revision", "会社名"],
totalCount: true,
};
const url = `https://${domain}/k/v1/records.json`;
const res = await kintone.proxy(url, "POST", headers, data);
const { records, totalCount, message } = JSON.parse(res[0]);
if (res[1] === 200) {
console.log(records);
console.log(totalCount);
} else {
console.log(message);
}
return event;
});
})();
interface DetailEvent {
appId: number;
record: kintone.types.SavedFields;
recordId: number;
type: string;
}
interface Params {
app: string;
query: string;
fields: string[];
totalCount: boolean;
}
kintone.events.on(["app.record.detail.show"], async (event: DetailEvent) => {
const domain = "xxx.cybozu.com";
const app = "xxx";
const headers = {
"X-Cybozu-API-Token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Content-Type": "application/json",
"X-HTTP-Method-Override": "GET",
};
const params: Params = {
app,
query: '会社名 = "金都運総研"',
fields: ["$id", "$revision", "会社名"],
totalCount: true,
};
const url = `https://${domain}/k/v1/records.json`;
const res = await kintone.proxy(url, "POST", headers, params);
const { records, totalCount, message } = JSON.parse(res[0]);
if (res[1] === 200) {
console.log(records);
console.log(totalCount);
} else {
console.log(message);
}
return event;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment