Created
August 29, 2019 19:35
-
-
Save Farmatique/4ee707844ec3ba6f6a4209293f48e4ae to your computer and use it in GitHub Desktop.
Wordpress php get JSON data from API fetch data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = "https://endpoint.api"; | |
$username = "username"; | |
$password = "password"; | |
$args = array( | |
'headers' => array( | |
'Authorization' => 'Basic ' . base64_encode( $username . ':' . $password ) | |
) | |
); | |
$response = wp_remote_get($url, $args); | |
$body = wp_remote_retrieve_body( $response ); | |
$api_response = json_decode( $body ); | |
?> | |
<div class="api-response"> | |
<?php print_r($api_response);//returns Array ?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment