# レコードを全件取得したい

**URL:** <https://community.cybozu.dev/t/topic/7186>\
**Category:** kintone 開発相談\
**Created:** [2021 年 6 月 18 日午前 5:36 UTC](https://community.cybozu.dev/t/topic/7186 "2021-06-18T05:36:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Legacy\_Account2769](https://avatars.discourse-cdn.com/v4/letter/l/9fc29f/32.png) [@Legacy\_Account2769](https://community.cybozu.dev/u/Legacy_Account2769)\
**Post date:** [2021 年 6 月 18 日午前 5:36 UTC](https://community.cybozu.dev/t/topic/7186/1 "2021-06-18T05:36:19Z")

</div>

下記のコードで全件取得（501件以上）するにはどのようなコーディングがあるかご教授いただけますと幸いです、、、（過去のレコード取得の記事を拝見したのですがいまいち理解できず、、、）

```
function getRecords() {
varurlGetRecords ="https://xxxxxxxxxxx.cybozu.com/k/v1/records.json";
varappId = xx;
varapiToken = 'xxxxxxxxxxxxx';
// kintoneからデータを取得
varparamFields ="&fields=$id,"+ encodeURIComponent("アポインター名,社員番号,雇用形態,入社日,在籍期間");
varurl = urlGetRecords +"?app="+ appId + paramFields;
varres = JSON.parse(UrlFetchApp.fetch(url, {"method":"get","headers": {"X-Cybozu-API-Token": apiToken}}));
// 取得したデータを整形
varoutput = [];
res["records"].forEach(function(record){
varrow = [];
row.push(record["アポインター名"].value);
row.push(record["社員番号"].value);
row.push(record["雇用形態"].value);
row.push(Utilities.formatDate(newDate(record["入社日"].value), 'JST', 'yyyy/M/d HH:mm'));
row.push(record["在籍期間"].value);
output.push(row);
});
// スプレッドシートに出力
varsheetOutput = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('シート1');
sheetOutput.getRange(2, 1, output.length, output[0].length).setValues(output);
}

```

---

<div class="post-metadata">

**Author:** ![Legacy\_Account1740](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@Legacy\_Account1740](https://community.cybozu.dev/u/Legacy_Account1740)\
**Post date:** [2021 年 6 月 18 日午前 7:57 UTC](https://community.cybozu.dev/t/topic/7186/2 "2021-06-18T07:57:08Z")

</div>

kenichi nagahamaさん

SDKを用いれば自分で実装せずに全件取得できるので、一番簡単かと思います。  
[https://developer.cybozu.io/hc/ja/articles/900000767263](https://developer.cybozu.io/hc/ja/articles/900000767263)  
[https://github.com/kintone/js-sdk/blob/master/packages/rest-api-client/docs/record.md#getAllRecords](https://github.com/kintone/js-sdk/blob/master/packages/rest-api-client/docs/record.md#getAllRecords)

以下は、もしご自身で実装するのであれば御覧ください。

1万件以下であれば、offsetを利用して全件取得できます。  
[https://developer.cybozu.io/hc/ja/articles/203702800](https://community.cybozu.dev/hc/ja/articles/203702800)  
[https://developer.cybozu.io/hc/ja/community/posts/360017977863/comments/360000774026](https://community.cybozu.dev/hc/ja/community/posts/360017977863/comments/360000774026)

offset 0に設定して500件取得 -\> offset 500に設定して500件取得 -\> offset 1000に設定して500件取得 -\> …  
というようにoffsetを変えながら取得することで全件取得できます。

offsetの上限は1万なので、超える場合はcursorで実装する必要があります。  
[https://developer.cybozu.io/hc/ja/articles/360028843531](https://community.cybozu.dev/hc/ja/articles/360028843531)

---

<div class="post-metadata">

**Author:** ![Legacy\_Account2769](https://avatars.discourse-cdn.com/v4/letter/l/9fc29f/32.png) [@Legacy\_Account2769](https://community.cybozu.dev/u/Legacy_Account2769)\
**Post date:** [2021 年 6 月 18 日午前 8:00 UTC](https://community.cybozu.dev/t/topic/7186/3 "2021-06-18T08:00:00Z")

</div>

@[江田篤史](https://community.cybozu.dev/hc/ja/profiles/5826575706-%E6%B1%9F%E7%94%B0%E7%AF%A4%E5%8F%B2)さん

早速のご返信ありがとうございます！いただきました方法を試してみます！ありがとうございますm(\_ \_)m！！！
