Title: Plugin Dev: Making direct API calls from a JS script?
Last modified: March 7, 2021

---

# Plugin Dev: Making direct API calls from a JS script?

 *  [hedgerh](https://wordpress.org/support/users/hedgerh/)
 * (@hedgerh)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/plugin-dev-making-direct-api-calls-from-a-js-script/)
 * My admin plugin is using React for its UI. It needs to make calls to AWS Cognito
   for user authentication and make calls to my company’s APIs for data.
 * According to [the plugin AJAX docs](https://developer.wordpress.org/plugins/javascript/ajax/#url),
   all WordPress AJAX requests must go through wp-admin/admin-ajax.php. Does that
   also apply to requests made in JS scripts?
 * An article I was reading had interpreted it this way, and they created a WP REST
   endpoint just to proxy the requests. However, someone else told me that this 
   isn’t necessary.
 * Can anyone clarify this guideline? Thank you.
    -  This topic was modified 5 years, 1 month ago by [hedgerh](https://wordpress.org/support/users/hedgerh/).

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/plugin-dev-making-direct-api-calls-from-a-js-script/#post-14147221)
 * > According to the plugin AJAX docs, all WordPress AJAX requests must go through
   > wp-admin/admin-ajax.php. Does that also apply to requests made in JS scripts?
 * I think you have taken something out of context. That document is for AJAX calls
   to WordPress. And there are no AJAX requests except in JS.
 * If your code needs to talk to an external site, talk directly, not through WP.
   But any time you need to use AJAX with WP functions, it should do it the WordPress
   way, which loads WordPress in order to handle the request. Trying to load WordPress
   yourself instead of using admin-ajax.php is the wrong way, and that is what is
   to be avoided.
 * If you are writing a plugin to be in the WP repository, you need the user’s permission
   to contact external sites.
 *  Thread Starter [hedgerh](https://wordpress.org/support/users/hedgerh/)
 * (@hedgerh)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/plugin-dev-making-direct-api-calls-from-a-js-script/#post-14147388)
 * Thank you for the reply. It looks like the author of the articlel I was reading
   misinterpreted the docs.
 * > If you are writing a plugin to be in the WP repository, you need the user’s
   > permission to contact external sites.
 * Do you happen to know where this is documented? I can’t seem to find it in the
   plugin guidelines. I see that you can’t embed external links without permission,
   but nothing about external requests.
 * Thanks again!
 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/plugin-dev-making-direct-api-calls-from-a-js-script/#post-14147453)
 * It seems pretty clear [here](https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/#7-plugins-may-not-track-users-without-their-consent):
 * > In the interest of protecting user privacy, plugins may not contact external
   > servers without explicit and authorized consent.
 *  Thread Starter [hedgerh](https://wordpress.org/support/users/hedgerh/)
 * (@hedgerh)
 * [5 years, 1 month ago](https://wordpress.org/support/topic/plugin-dev-making-direct-api-calls-from-a-js-script/#post-14147490)
 * Oh! Thank you. I didn’t realize that guideline was so broad. Cheers!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Plugin Dev: Making direct API calls from a JS script?’ is closed to new
replies.

## Tags

 * [ajax](https://wordpress.org/support/topic-tag/ajax/)
 * [js](https://wordpress.org/support/topic-tag/js/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 2 participants
 * Last reply from: [hedgerh](https://wordpress.org/support/users/hedgerh/)
 * Last activity: [5 years, 1 month ago](https://wordpress.org/support/topic/plugin-dev-making-direct-api-calls-from-a-js-script/#post-14147490)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
