Why can't i get app, record with kintone.proxy?

I can use kintone.proxy with POST method (ex: add preview app, add form fields, …), but when i use them with get method, i received error (status: 502). 

I use postmen to request Get method, it run correct.

Post:

let url = 'https:// *******.cybozu.com/k/v1/preview/app.json'
let method = 'POST'
let header = {
  'X-Cybozu-Authorization': ' ******',
  'Content-Type': 'application/json',
}

let data = {
  name: 'APP_NAME'
}

kintone.proxy(url, method, header, data, function(body, status, headers) {
  console.log(status, JSON.parse(body), headers);
}, function(error) {
  console.log(error); // Display the response body (string) from the proxy API
});

GET: 

let url = 'https:// ***********.cybozu.com/k/v1/app.json'
let method = 'GET'
let header = {
  'X-Cybozu-Authorization': ' *********',
  'Content-Type': 'application/json'  
}

let data = {
  id: 113
}

kintone.proxy(url, method, header, data, function(body, status, headers) {
  console.log(body);
}, function(error) {
  console.log(error); // Display the response body (string) from the proxy API
});

Can you help me?

Hi Tân Lương Nhật,

 

I tested the process based on your provided information and found that the 502 error did not occur.

(Error 520 occurred on my end.)

 

Also, when I checked the processing that specified the GET method you provided, I found an error in the way the kintone.proxy function is being used.

 

For data, it is only used for the POST and PUT methods and ignored for the GET and DELETE methods.

For the GET and DELETE methods, you need to add a parameter to the QueryString of the URL.

 

In the case of the GET method, it is not necessary to specify ‘Content-Type’: 'application/JSON within the header.

Could you check if it runs correctly by altering it to the following process?

 

<Ex>

 

(the app ID is specified in the URL.)

 

let url = 'https:// ***********.cybozu.com/k/v1/app.json?id=113'
let method = 'GET'
let header = {
'X-Cybozu-Authorization': '' *********'
}

let data = {}

kintone.proxy(url, method, header, data, function(body, status, headers) {
console.log(body);
}, function(error) {
console.log(error); // Display the response body (string) from the proxy API
});

Thank Sean Tachibana,

My problem was resolved. 

I inserted query to url as you said (‘https://***********.cybozu.com/k/v1/app.json?id=113’) 

and I add to header authentication:

let header = {
'X-Cybozu-Authorization': ' *********',
'Authorization': ' *********'
}

Thank your support so much