Bluemo's Brain

Search

Search IconIcon to open search

GASでScrapboxのexport APIを呼ぶ

Last updated Unknown Edit Source

    参考

    script.js

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    
    function myFunction() {
      const sid = "YOUR_SID";
      const cookie = "connect.sid=" + sid;
      const userInfoJSON = UrlFetchApp.fetch("https://scrapbox.io/api/users/me", {
        method: "get",
        headers: {
           "Cookie" : cookie
        }
      });
      const userInfoData = JSON.parse(userInfoJSON);
      const csrfToken = userInfoData.csrfToken
      const response = UrlFetchApp.fetch("https://scrapbox.io/api/page-data/export/blu3mo.json", {
        method: 'post',
        headers: {
           "Cookie" : cookie,
           "X-CSRF-TOKEN": csrfToken,
        },
        muteHttpExceptions : true,
      });
      Logger.log(JSON.parse(response))
    }