SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BillSut
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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.

 

 

 

 

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

View solution in original post

5 REPLIES 5
Ksharp
Super User

You could try 

PROC HTTP

+

LIBNAME 's  JSON engine.

 

@ChrisHemedinger  wrote a couple of blogs about it.

https://blogs.sas.com/

BillSut
Calcite | Level 5

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.

ChrisHemedinger
Community Manager

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.

 

 

 

 

 

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
BillSut
Calcite | Level 5

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.

ChrisHemedinger
Community Manager

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

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 4016 views
  • 2 likes
  • 3 in conversation