BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Gigiwen
Calcite | Level 5

I've read some articles on the forum but did not find the solution. My key problem is in understanding the technical specification provided on the following webpage and how to embed into SAS code:

https://www.ncdc.noaa.gov/cdo-web/webservices/v2#gettingStarted

 

In particular, it says the usage of token is:

curl -H "token:<token>" "url"
$.ajax({ url:<url>, data:{<data>}, headers:{ token:<token> } })

 

I've requested the token. Tried the following code:

%let mytoken =BgGrhHFjqqfXkZugQhzPSsBSEanFm; *API token;
filename trial temp;
proc http 
out= trial verbose
method="GET" 
url= "https://www.ncei.noaa.gov/cdo-web/api/v2/location?datasetid=GHCND"; 
Headers
"Authorization" = "Bearer &mytoken.";
run; 

It tuns out "400 Bad request."

Any help? or guidance? 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

A couple of changes needed. According to the doc, the header should include "token: <your token>" -- it's not an OAuth style "Authorization: Bearer <token>".

 

Second, the endpoint is "locations", not "location".

 

%let token=your-token-value;
filename resp temp;
proc http
 method="GET"
 out=resp
 url="https://www.ncei.noaa.gov/cdo-web/api/v2/locations?datasetid=GHCND";
 headers 
  "token" = "&token.";
run;

libname data JSON fileref=resp;

proc print data=data.results;
run;

 

ChrisHemedinger_0-1686138831705.png

 

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

1 REPLY 1
ChrisHemedinger
Community Manager

A couple of changes needed. According to the doc, the header should include "token: <your token>" -- it's not an OAuth style "Authorization: Bearer <token>".

 

Second, the endpoint is "locations", not "location".

 

%let token=your-token-value;
filename resp temp;
proc http
 method="GET"
 out=resp
 url="https://www.ncei.noaa.gov/cdo-web/api/v2/locations?datasetid=GHCND";
 headers 
  "token" = "&token.";
run;

libname data JSON fileref=resp;

proc print data=data.results;
run;

 

ChrisHemedinger_0-1686138831705.png

 

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

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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
  • 1 reply
  • 1454 views
  • 2 likes
  • 2 in conversation