I'm need to connect to Oracle Cloud Services using a REST API and extract data into a data set.
Does anyone have a code example for this?
Hi @BillSut - I see you asked this question in another board, but ran into a dead end -- maybe due to your org proxy. PROC HTTP supports PROXY* options that you can use to punch through that -- you might need to get the proper settings from your IT. I recommend you use this standalone test first to make sure things are working.
In using any REST service with PROC HTTP, I often work backwards by starting with API doc that offers examples in cURL. You can find some of these for Oracle Cloud Services here (If I have done my Google searching correctly).
Beginning with this example:
curl -u service_cloud_user -X GET -H "OSvC-CREST-Application-Context:Retrieve all incidents" https://mysite.example.com/services/rest/connect/v1.4/incidents
The PROC HTTP version would look like:
filename resp "path-to-json-response-to-create";
proc http
method="GET"
url="https://mysite.example.com/services/rest/connect/v1.4/incidents"
out=resp
webusername='service_cloud_user'
webpassword='your-password'
/* proxy options if needed */
/* proxyhost='host' proxyport=8080 */
;
headers
"OSvC-CREST-Application-Context"="Retrieve all incidents";
run;
The result would be a JSON response in the file you specify. You can then use LIBNAME JSON to parse this as data.
I think it's likely that you won't authenticate with user/password though, and that instead you'll use an auth token. That's pretty standard these days. I see Oracle Cloud Services supports a variety of different schemes. I have several examples of using OAuth2-supported services, including Microsoft Office 365 and Google.
You could try
PROC HTTP
+
LIBNAME 's JSON engine.
@ChrisHemedinger wrote a couple of blogs about it.
Thank you for the response. That is what I'm trying to use but I can't find any examples with a user name and password. These are required for the API that I'm required to use.
Hi @BillSut - I see you asked this question in another board, but ran into a dead end -- maybe due to your org proxy. PROC HTTP supports PROXY* options that you can use to punch through that -- you might need to get the proper settings from your IT. I recommend you use this standalone test first to make sure things are working.
In using any REST service with PROC HTTP, I often work backwards by starting with API doc that offers examples in cURL. You can find some of these for Oracle Cloud Services here (If I have done my Google searching correctly).
Beginning with this example:
curl -u service_cloud_user -X GET -H "OSvC-CREST-Application-Context:Retrieve all incidents" https://mysite.example.com/services/rest/connect/v1.4/incidents
The PROC HTTP version would look like:
filename resp "path-to-json-response-to-create";
proc http
method="GET"
url="https://mysite.example.com/services/rest/connect/v1.4/incidents"
out=resp
webusername='service_cloud_user'
webpassword='your-password'
/* proxy options if needed */
/* proxyhost='host' proxyport=8080 */
;
headers
"OSvC-CREST-Application-Context"="Retrieve all incidents";
run;
The result would be a JSON response in the file you specify. You can then use LIBNAME JSON to parse this as data.
I think it's likely that you won't authenticate with user/password though, and that instead you'll use an auth token. That's pretty standard these days. I see Oracle Cloud Services supports a variety of different schemes. I have several examples of using OAuth2-supported services, including Microsoft Office 365 and Google.
Thanks Chris. My Proc HTTP that I've written looks like yours except the header part. It's not working though. I'm new to SAS so this is way over my head. Thanks for your input.
Sometimes I use Postman (free tool for testing/building REST API calls) to build a prototype of the API calls I want -- easier to test and see results outside of SAS. Once that's working, it's easy to transcribe into SAS code.
Chris
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.