京都のkintone用javascript
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

42 行
866B

  1. import { MyPageApiID } from ".";
  2. type MyPageApiResponse = {
  3. result: "SUCCESS" | "FAILED";
  4. };
  5. export const getUrl = (apiId: MyPageApiID) => {
  6. return [process.env.MYPAGE_BASE_URL ?? "", "api-from-kintone", apiId].join(
  7. "/"
  8. );
  9. };
  10. export const send = async (apiId: MyPageApiID, data: object) => {
  11. const url = getUrl(apiId);
  12. const sendData = {
  13. ...data,
  14. token: process.env.MYPAGE_TOKEN ?? "",
  15. };
  16. console.info("MyPageAPICall", url, data);
  17. const res: any = await kintone.proxy(
  18. url,
  19. "POST",
  20. { "Content-Type": "application/json" },
  21. sendData
  22. );
  23. const status = res[1];
  24. if (status !== 200) {
  25. console.error("http status not 200", res);
  26. return false;
  27. }
  28. const obj = JSON.parse(res[0]);
  29. if (obj.result === "SUCCESS") {
  30. return true;
  31. } else {
  32. console.error("処理失敗", res);
  33. return false;
  34. }
  35. };