• Hello, I have simple PHP rest api code (OAuth 1.0a) and I want to switch to JWT.

    <?php
    error_reporting(E_ALL & ~E_NOTICE); ini_set('display_errors', '1');
    if(isset($_POST['submit']))
        {
            
            // Token
            $authToken = 'OAuth oauth_consumer_key="XXXXXXX",oauth_token="XXXXXXXXX",oauth_signature_method="HMAC-SHA1",oauth_timestamp="XXXXXXXX",oauth_nonce="XXXXXX",oauth_version="1.0",oauth_signature="XXXXXXXXXX"';
    
            // The data to send to the API
            $postData = array('id' => $_POST["my_value"]);
    
            // Setup cURL
            $ch = curl_init('https://www.mysite.com/wp-json/wc/v1/customers/'.$postData['id'] );
            curl_setopt_array($ch, array(
                CURLOPT_RETURNTRANSFER => TRUE,
                CURLOPT_HTTPHEADER => array(
                    'Authorization: '.$authToken,
                    'Content-Type: application/x-www-form-urlencoded'
                ),
                //CURLOPT_POSTFIELDS => json_encode($postData)
            ));
    
            // Send the request
            $response = curl_exec($ch);
            var_dump($response);
    
            // Check for errors
            if($response === FALSE){
                die(curl_error($ch));
            }
    
            // Decode the response
            $responseData = json_decode($response, TRUE);
            $responseData = json_decode($response);
            // Print the date from the response
            echo "</br>";
            echo $responseData->id;
            echo $responseData->billing->first_name;
    
        }
    ?>
  • The topic ‘PHP Example’ is closed to new replies.