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
Nelson Chisoko 15Nelson Chisoko 15 

[Beginner] - Calling out an external web service API using REST and OAUTH

Hello Guys

I have been struggling to find a way on how I can call an external web service via apex  which uses OAUTH via REST services. Basically I am trying to access an API on https://api.envisionme.co.za/v1/docs#oauth. Now they use OAUTH to grant access to make calls such as retrieving jobs, candidates etc. They have set up an app on their side with a client_id and a client_secret. Now based on their doc Im suppose to follow a process: make a login call, get a token etc...

I have absolutely no idea how to do this...how do I set up an apex class that will
  1. Login and get the token
  2. Enable me to make those Http POST, GET etc methods
Because ultimately I wanna have a trigger that will call on it to retrieve the data from that external web service.

I do know a bit of apex but I am a rookie when it comes to integration stuff. Please help if you can.
so_mayankso_mayank
Hi Nelson,

I don't know if this will answer your questions but here it goes. In simple words, OAuth is a login process where the authentication happens via a third party vendor. Once the Oauth Process completes it would generate two tokens(Strings) i.e. Access token and Refresh Token. Access tokens expire after some time(depending on the configuration) like HTTP sessions and refresh tokens are used to get a new access token.

The idea is that you would authenticate a REST call using this Access token and can get a new access token using the refresh token without involving the users in subsequent calls. This also makes sure that user does not have to reauthenticate in case the change passwords.

If you are still looking into this I would recommend you to explore Named Credentials feature in Salesforce.



 
Nikhil Shrigod 25Nikhil Shrigod 25
Hello Nelson,
You can use a tool named Postman to test whether your OAuth authorization works well, if you are successfully able to authenticate the API through Postman, then you can follow the same steps to make an Http callout from Apex.