Created
August 16, 2020 13:28
-
-
Save pbattisson/3b47838a64dd6be312b3c46f8c5afd86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void sendMessage(Message msg) { | |
HttpRequest req = new HttpRequest(); | |
req.setMethod('POST'); | |
//req.setEndpoint('https://api.learnsfdevwithapex.com/messages'); | |
req.setEndpoint('callout:LearningSFDevAPI/messages'); //This is for the final version at the end of the chapter | |
req.setBody(JSON.serialize(msg)); | |
req.setHeader('X-Auth-Token', 'SEE_BOOK_FOR_VALUE'); | |
req.setHeader('content-type', 'application/json'); | |
Http http = new Http(); | |
HttpResponse res = http.send(req); | |
if(res.getStatusCode() != 200) { | |
throw new LearningSFDevAPIException('API callout returned with a status of ' + res.getStatus()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment