# Getting Kintone App's Record data from another domain via REST API

**URL:** <https://forum.kintone.dev/t/getting-kintone-apps-record-data-from-another-domain-via-rest-api/169>\
**Category:** General\
**Tags:** error-kintone-is-not-defined\
**Created:** [October 3, 2018, 4:35am UTC](https://forum.kintone.dev/t/getting-kintone-apps-record-data-from-another-domain-via-rest-api/169 "2018-10-03T04:35:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [October 3, 2018, 4:35am UTC](https://forum.kintone.dev/t/getting-kintone-apps-record-data-from-another-domain-via-rest-api/169/1 "2018-10-03T04:35:52Z")

</div>

### How to get record data using REST API from another domain?

I am trying to extract Records data from another Kintone Subdomain using AJAX request.  
However, I get the following error:

```shell
return error----
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://SUBDOMAIN.kintone.com/k/v1/record.json?app=1&id=1.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

```

My Script:

```javascript
var params = "?app=1&id=1";
var url = "https://SUBDOMAIN.kintone.com/k/v1/record.json" + params;

var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.setRequestHeader("X-Cybozu-API-Token", "api-token-string");

xhr.onload = function () {
  if (xhr.status === 200) {
    // success
    console.log(JSON.parse(xhr.responseText));
  } else {
    // error
    console.log(JSON.parse(xhr.responseText));
  }
};
xhr.send();

```

⚡ When I execute the above code in [Postman](https://www.postman.com/), then it works properly.

### Using kintone.proxy()

When I used [`kintone.proxy()`](https://kintone.dev/en/docs/kintone/js-api/other/kintone-proxy/), it still did not work and returns the following Reference error:

```shell
return error---- ReferenceError: kintone is not defined

```

My script with `kintone.proxy()`:

```javascript
var url = "https://SUBDOMAIN.kintone.com/k/v1/records.json";
var method = "POST";
var headers = {
  "Content-Type": "application/json",
  "X-Cybozu-API-Token": "api-token-string",
  "X-HTTP-Method-Override": "GET",
};
var params = {
  app: 1,
  id: 1,
};

kintone
  .proxy(url, method, headers, params)
  .then(function (r) {
    console.log(r);
  })
  .catch(function (e) {
    console.log(e);
  });

```

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [October 5, 2018, 4:05pm UTC](https://forum.kintone.dev/t/getting-kintone-apps-record-data-from-another-domain-via-rest-api/169/2 "2018-10-05T16:05:28Z")

</div>

Hi Salman,

XML requests cannot be executed because of cross-domain restrictions.

> Due to cross-domain restrictions, communication between [kintone.com](http://kintone.com) and external sites using XHR(XMLHttpRequest) cannot be run. The Access-Control-Allow-Origin header cannot be added.

For more information, refer to the [Secure Coding Guidelines](https://kintone.dev/en/legal/secure-coding-guidelines/) article.

### kintone.proxy() Option

As an alternative option, `kintone.proxy()` can be used.

Here is an example code based on yours:

```javascript
var url = "https://<subdomain>.kintone.com/k/v1/record.json";
var method = "POST";
var headers = {
  "Content-Type": "application/json",
  "X-Cybozu-API-Token": "APP_TOKEN",
};

var params = {
  app: APP_ID,
};

kintone
  .proxy(url, method, headers, params)
  .then(function (r) {
    console.log(JSON.parse(r));
  })
  .catch(function (e) {
    console.log(e);
  });

```

⚡ "'X-HTTP-Method-Override':'GET'" is removed in this above example.

In your code, "records.json" has been registered multiple times, but in this case, the required parameters need to be specified, so only one time is registered in the above example.

▼ kintone Proxy  
[Kintone Proxy - Kintone Developer Program](https://kintone.dev/en/docs/kintone/js-api/other/kintone-proxy/)

Thanks,  
Junko

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [October 9, 2018, 10:59pm UTC](https://forum.kintone.dev/t/getting-kintone-apps-record-data-from-another-domain-via-rest-api/169/3 "2018-10-09T22:59:51Z")

</div>

Hello, Salman.

In order to access Kintone API from an external site, you may want to use API Gateway service such as [Amazon API Gateway](https://aws.amazon.com/api-gateway/).

I personally have an experience in this situation and wrote a blog.

[Get kintone data into external microsite via AWS - Fuji Business Software Inc.](https://fujibiz.com/blog/was/get-kintone-data-into-external-microsite-via-aws/)

Best regards,  
Mo

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [October 31, 2018, 4:50am UTC](https://forum.kintone.dev/t/getting-kintone-apps-record-data-from-another-domain-via-rest-api/169/4 "2018-10-31T04:50:20Z")

</div>

Thank you&nbsp;Junko Werner &&nbsp;Mo.

&nbsp;

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [July 16, 2020, 3:10pm UTC](https://forum.kintone.dev/t/getting-kintone-apps-record-data-from-another-domain-via-rest-api/169/5 "2020-07-16T15:10:47Z")

</div>

I'm also new to Kintone and have the exact same issues.

Here is my code and the error message I'm receiving (I was to follow the AWS walkthru and get responses back from the API, thanks Mo!):

### Code

```javascript
var url = 'https://SUBDOMAIN.kintone.com/k/v1/record.json';
var method = 'POST';
var headers = {
  'Content-Type':'application/json',
  'X-Cybozu-API-Token':'token',
  'X-Cybozu-Authorization':'username:password'
};

var params = {
  app: APP_ID,
};

kintone.proxy(url, method, headers, params).then(function(r){
  console.log(JSON.parse(r));
}).catch(function(e){
  console.log(e);
});

```

### Error

Access to XMLHttpRequest at `'https://SUBODMAIN.kintone.com/k/v1/records.json?app=1&id=7'` from origin '[http://mysite.example.com](http://mysite.example.com)' has been blocked by CORS policy:

> Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Thank you in advance thanks for everyone's help!

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [July 17, 2020, 5:51pm UTC](https://forum.kintone.dev/t/getting-kintone-apps-record-data-from-another-domain-via-rest-api/169/6 "2020-07-17T17:51:40Z")

</div>

Hello Sean,

The error appears to be caused by a cross-domain constraint, and due to cross-domain restrictions, communication between [kintone.com](http://kintone.com) and external sites using XHR(XMLHttpRequest) cannot be run.

The `Access-Control-Allow-Origin` header cannot be added.

For more information, refer to the [Secure Coding Guidelines](https://kintone.dev/en/legal/secure-coding-guidelines/) article.

Also, since the errors do not seem to match up with the process, you’re performing, I was not sure about the situation you are going through the request you are running.

**Are you trying to register records from Kintone to Kintone in a different environment?**

Could you please be a little more specific about what you have done and what environment you are running the API in?

Thanks,  
Sean
