Why unable to output the content retrieved via kintone.proxy's GET request using console.log()

Question / Problem

I was trying to retrieve myKintone data from a different kintone environment.

const mykintone = 'https://sample.cybozu.com'; 
const mykintone_API_TOKEN = 'sample';
const mykintone_APP_ID = 1; 
const headers = { 'X-Cybozu-API-Token': mykintone_API_TOKEN };
const url = `${mykintone}/k/v1/records.json`;
const response = await kintone.proxy(url, 'GET', headers, params);
console.log(repsonse);

I tried output the 'respone' with console.log().But It didn't work well.
Please give me some suggestions.:smiling_face_with_tear:

Hello @kokonuts

I was able to reproduce this with a similar setup.
There appear to be two separate issues in the sample code.

First, when using kintone.proxy() with a GET request, the fourth data parameter is ignored. Because of this, the app value in params is not being sent to the Get Records API.

In my test, using:

const response = await kintone.proxy(
  url,
  'GET',
  headers,
  params
);

resulted in an HTTP 400 response indicating that the required app parameter was missing.

Instead, include the App ID in the query string:

const url =
  `${mykintone}/k/v1/records.json?app=${mykintone_APP_ID}`;

Then call:

const response = await kintone.proxy(
  url,
  'GET',
  headers,
  {}
);

Also, there is a typo here:

console.log(repsonse);

It should be:

console.log(response);

In my test, the typo resulted in:

ReferenceError: repsonse is not defined

One other thing to note is that the Promise version of kintone.proxy() returns an array containing the response body, HTTP status code, and response headers:

console.log(response[0]); // response body
console.log(response[1]); // HTTP status
console.log(response[2]); // response headers

If you want to access the returned records, you can parse the response body:

const data = JSON.parse(response[0]);
console.log(data.records);

I hope this helps.

References: