Call the REST API from JavaScript (CORS)
Browser-based apps can call the WordPress.com REST API directly from JavaScript. WordPress.com sends the CORS headers your app needs: unauthenticated GET requests work from any origin, and authenticated requests work from the origins you add to your application’s settings.
Unauthenticated requests
Unauthenticated GET requests need no token and no app setup. The examples on this page use the Fetch API:
fetch("https://public-api.wordpress.com/rest/v1.2/sites/yourgroovysite.wordpress.com/")
.then(response => response.json())
.then(data => {
// data contains site information
})
.catch(error => {
console.error('Error:', error);
});Authenticated requests
An authenticated request sends an OAuth2 access token, which shows that the user approved your app.
User tokens for browser apps
A browser-only app gets its token through the implicit flow, because the app has no server to keep a client secret and the OAuth2 endpoints don’t support PKCE. If your app has a server, we recommend the authorization code flow instead. For token lifetime and the authorization parameters, see OAuth2 authentication.
Authenticated request example
Send the access token as a bearer token in the Authorization header:
fetch(`https://public-api.wordpress.com/rest/v1.2/sites/${site_id}/posts/new`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${access_token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
content: 'Hello from my app.'
})
})
.then(response => response.json())
.then(data => {
// Handle the response data
})
.catch(error => {
console.error('Error:', error);
});Allowed origins
WordPress.com sends CORS headers on authenticated requests only when they come from an origin you’ve added to your application. A request from any other origin is blocked with an error like this one:
Access to fetch at 'https://public-api.wordpress.com/rest/v1.1/me/' from origin 'https://yourgroovydomain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.To add your app’s origins, follow these steps:
- Open My Applications and click the “Manage Application” link under your app.
- Click the “Manage Settings” link.
- In the “Javascript Origins” field, enter each origin on its own line, including the protocol, for example
https://yourgroovydomain.com:

- Click the Update button.
Your app’s overview page lists the saved origins under Javascript Origins. To add origins while creating a new app, fill in the same field on the “Create New Application” screen.
Last updated: December 03, 2026