For the latest version of JMP Help, visit JMP.com/help.


Publication date: 07/24/2024

Examples of HTTP Requests

The following examples communicate with the National Aeronautics and Space Administration (NASA) API. You must request a key from https://api.nasa.gov/index.html#apply-for-an-api-key and assign it to the key variable to run the scripts successfully.

Write Data to the Log

url = "http://technology.nasa.gov/api/query/patent/all";
request = New HTTP Request( URL( url ), Method( "Get" ) );
data = request << Send();
Write( data );

{"results":[["59fa04859600022b4d2e076f","LAR-TOPS-48","All-Organic Electroactive Device","NASA's Langley Research Center offers you an all-organic electroactive device system fabricated with single-wall carbon nanotube (SWCNT)....}

// JSON output written to the log

Notes:

The query string is at the end of the URL, following “?”. For example, in https://www.google.com/search?q=jmp, “q=jmp” is the query string. New HTTP Request() automatically URI-encodes key/value pairs in a query string (and FORM).

When you put an associative array in either a query string or a form, the key/value pairs get URI encoded. Spaces, ampersands, and other characters get encoded to ASCII, and the ampersand is escaped. The encoding is a “%” encoding.

The web service defines the valid key/value pairs that it accepts. Refer to the API documentation for valid key/value pairs.

For Kerberos authentication, specify the password as follows:

Password(":")

Return Data as an Associative Array and Write it to the Log

url = "http://technology.nasa.gov/api/query/patent/all";
request = New HTTP Request( URL( url ), Method( "Get" ) );
json = request << Send();
jsl_json = Parse JSON( json );

// turns JSON data into a JSL associative array

results = jsl_json["results"];
Write( results );

{{"59fa04859600022b4d2e076f", "LAR-TOPS-48", "All-Organic Electroactive Device", "NASA's Langley Research Center offers you an all-organic electroactive device system fabricated with single-wall carbon nanotube (SWCNT)....}}

// associative array

Return Data as a JMP Data Table

url = "http://technology.nasa.gov/api/query/patent/all";
request = New HTTP Request( URL( url ), Method( "Get" ) );
json = request << Send();
jsl_json = Parse JSON( json );
json = As JSON Expr( jsl_json["results"] );
dt = JSON To Data Table(
	json,
	JSON Settings(
		Stack( 0 ),
		Col(
			"/root",
			Column Name( "root" ),
			Fill( "Use Once" ),
			Type( "Pandas Values" ),
			Format( {"Best"} ),
			Modeling Type( "Continuous" )
		)
	)
);
dt << Set Name( "NASA Patents" );

Figure 14.5 Data Imported in a Data Table 

Data Imported in a Data Table

Disable Certificate Revocation Checks for SSL Backends

When you use curl with Windows SSPI, curl sometimes considers certificates to be revoked.

The Verify SSL(1) message sets the CURLSSLOPT_NO_REVOKE option in a CA bundle when the message is sent to a New HTTP Request() object.

Names Default To Here( 1 );
request = New HTTP Request(
    Url( "https://developer.mozilla.org/en-US/docs/Web/HTTP/Conditional_requests/cache1.png" ),
    Method( "GET" ),
    Verify SSL( 1 )
);
bytes = request << Send;
img = Open( bytes, jpg );
obj = New Window( "Mastering JMP", img );
Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).