• Javier García 24
  • NEWBIE
  • 10 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
Hi!
I'm trying to access Salesforce content from an external site. For this I want to use the APIs provided by Salesforce.

From Postman it works OK and I do the following:

I have created a connected app in salesforce with this settings:
- Available OAuth Scopes -> full access
- OAuth Policies -> IP Relaxation -> Relax IP restrictions
- OAuth Policies -> Permited Users -> All users may self-authorize

From Postman:
- I do a post request with the following body:
User-added image

- In hit this endpoint 'https://test.salesforce.com/services/oauth2/token' and I get a good response

User-added image

With this access token I can build another request and I get my resource from salesforce until here everything ok...

My problem is when I try to get the access token from the site's javascript. My code:

User-added image

I get this error:
User-added image

To resolve this issue I have added the site from which I launch the requests to the salesforce CORS whitelist and I have enabled the Enable CORS for OAuth endpoints but nothing seems to change.

With the access token obtained via Postman I can do the following request from my site and it works:

User-added image

This SOQL request send me a JSON with a good response.

Therefore, to solve my problem I would need to obtain this access token from my site in order to later build the following request .
Anybody knows how can I resolve this issue?

Thank you very much in advance,
Best regards
 
Hi!
I'm trying to access Salesforce content from an external site. For this I want to use the APIs provided by Salesforce.

From Postman it works OK and I do the following:

I have created a connected app in salesforce with this settings:
- Available OAuth Scopes -> full access
- OAuth Policies -> IP Relaxation -> Relax IP restrictions
- OAuth Policies -> Permited Users -> All users may self-authorize

From Postman:
- I do a post request with the following body:
User-added image

- In hit this endpoint 'https://test.salesforce.com/services/oauth2/token' and I get a good response

User-added image

With this access token I can build another request and I get my resource from salesforce until here everything ok...

My problem is when I try to get the access token from the site's javascript. My code:

User-added image

I get this error:
User-added image

To resolve this issue I have added the site from which I launch the requests to the salesforce CORS whitelist and I have enabled the Enable CORS for OAuth endpoints but nothing seems to change.

With the access token obtained via Postman I can do the following request from my site and it works:

User-added image

This SOQL request send me a JSON with a good response.

Therefore, to solve my problem I would need to obtain this access token from my site in order to later build the following request .
Anybody knows how can I resolve this issue?

Thank you very much in advance,
Best regards