function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chuck RamseyChuck Ramsey 

REST API calls from C# return "Not Authorized" (401) status.

We have Salesforce Ultimate, Summer 2015 release. My login has adminstrator privileges and API is enabled.

I am developing a Windows forms application in C# that will use the REST Analytics API to capture report information. I am using the OAuth 2.0 User Agent flow to obtain an authentication token. I have registered my app as a Connected App, with a callback URI of sfrr:oauth2. I monitor the URLs during authentication and intercept any calls to that uri. In the Connected App setup, I selected "full" and "refresh_token, offline_access" as OAuth Scopes.

 After some initial difficulty, I am now regularly receiving my access token. However, when I tried to use that token to retreive a report, I got the 401 status (Not Authorized). At that point, I went back to the sample queries from the REST API Developer's Guide and started excuting them. The first query in the form <instance_url>/services/data/ returns a list of API versions, as expected. The next call is to <instance_url>/services/data/v34.0/. I should get a list of available resources, but I get the Not Authorized response instead. I am passing my access token in the request header using "Authorization:Bearer <access token>" and <instance_url> is the URL returned iin my OAuth User Agent results.

I saw -- once and could not find it again -- a forum response that gave the name and email address for a contact in Salesforce if your organization cannot access even though access should otherwise be available. Is that still a problem? Is there somethig else I'm missing here? Suggestions and enlightenment gratefully accepted.

Joe BriaticoJoe Briatico
The instance_url returned in the OAuth results is the url from where the connected app was setup.  If you are on a different instance of Salesforce, it will be incorrect.
omar Local polania Localomar Local polania Local
You are right and save me a lot off time, thanks.
omar Local polania Localomar Local polania Local
After you get the token you should use your instance url attribute like follows:
    "access_token": "00Dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    "instance_url": "",
    "id": "",
    "token_type": "Bearer",
    "issued_at": "1562641793937",
    "signature": "BY8xDzpVdZTCCHdeVJoUtVukRRnrPLIhbJcOYRv5+sY="