cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar

HTTP Request with Headers?

Hi,

 

I'm trying to do a REST request to pull some JSON data with the following code but am getting an error. The owner of the site says I need to put the key in the request header as opposed to appending it. How does one do this in JSL with HTTP Request?

 

Site documentation here: https://jsonodds.com/documentation

 

Thanks in advance,

-Mike

 

 

key = "cb8abaa5-9b10-11e8-9bbb-0b704e36c1ea"; // substitute your key
url = "https://jsonodds.com/api/odds";
request = New HTTP Request(
URL( url ), // the restAPI endpoint
Method( "GET" ),
Query String( // define key pairs
[["x-api-key" => key]] // JSL associative array
)
);
data = request << Send(); // send the request to the API

 

 

//ERROR BELOW

GET https://jsonodds.com/api/odds?x-api-key=cb8abaa5-9b10-11e8-9bbb-0b704e36c1ea
schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.
Empty()

1 ACCEPTED SOLUTION

Accepted Solutions
uday_guntupalli
Level VIII

Re: HTTP Request with Headers?

@Anonymous,

Getting Started With REST in JMP. Feel free to get this addin, it is helpful.  

 

I am actually trying something similar on my end for an internal API and I am running into issues. While there is good documentation on Post examples, I dont see many examples in either Scripting Guide or Documentation Reference around making Get requests with access tokens. If there is anything specific you find around get requests with access tokens, please share it. 


Here is my attempt 

Request = New HTTP Request(
																	   URL(URLDes),
																	   Method("Get"),
																	   Headers({"Authorization = Bearer " || AccessDetails["access_token"] })
																	   //Query String([["Authorization" => "Bearer" ||AccessDetails["access_token"]]])
																		  )<< Send;

 

 

Best
Uday

View solution in original post

2 REPLIES 2
uday_guntupalli
Level VIII

Re: HTTP Request with Headers?

@Anonymous,

Getting Started With REST in JMP. Feel free to get this addin, it is helpful.  

 

I am actually trying something similar on my end for an internal API and I am running into issues. While there is good documentation on Post examples, I dont see many examples in either Scripting Guide or Documentation Reference around making Get requests with access tokens. If there is anything specific you find around get requests with access tokens, please share it. 


Here is my attempt 

Request = New HTTP Request(
																	   URL(URLDes),
																	   Method("Get"),
																	   Headers({"Authorization = Bearer " || AccessDetails["access_token"] })
																	   //Query String([["Authorization" => "Bearer" ||AccessDetails["access_token"]]])
																		  )<< Send;

 

 

Best
Uday

Re: HTTP Request with Headers?

Using Uday's solution above I was able to get things to work. This is a pretty brief piece of code and you may need to add some variables for the URL, header, etc.

 

Thanks to Uday for his help...

 

-Mike

 

 

request = New HTTP Request(
URL( "https://jsonodds.com/api/odds" ), // the restAPI endpoint
Method( "GET" ),
headers( {"x-api-key: //yourkeyhere// "} ) // add your custom headers
);
dt = Open( Char To Blob( request << Send() ), "JSON" );