Pull and update article HTML

PHP Example

public function updateArticleHtml()
{
    $agent 	= "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)";
    $articleID 	= "{{ARTICLE ID}}";
    $endPoint	= "https://app.knowledgeowl.com/api/head/article/{$articleID}.json";
    $postparams = array();
    $postparams['_authbykey'] = "{{API KEY}}";
    $postparams['_fields'][] = 'current_version'; //if not specified will return all fields
    $postparams = http_build_query($postparams);
    
    //pull back the article html and update
    $ch=curl_init();
    curl_setopt($ch, CURLOPT_URL, $endPoint . '?' . $postparams);
    curl_setopt($ch, CURLOPT_NOPROGRESS, 1);  
    curl_setopt($ch, CURLOPT_VERBOSE, 0);  
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);  
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    
    $buffer = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);
    
    if(!empty($error))
    {
        //handle error
    }
    
    $json = json_decode($buffer, true);
    if(!$json['valid'])
    {
        //handle error
    }
    else
    {
        $currentHTML = $json['data']['current_version']['en']['text'];
        
        //update text
        $updatedHTML = str_replace('some string', 'some new string', $currentHTML);
    }
    
    //push the updated html back into the article
    $postparams = array();
    $postparams['_authbykey'] = "{{API KEY}}";
    $postparams['current_version']['en']['text'] = $updatedHTML;
    $postparams['_method'] = 'PUT';
    $postparams = http_build_query($postparams);
    
    //pull back the article html and update
    $ch=curl_init();
    curl_setopt($ch, CURLOPT_URL, $endPoint . '?' . $postparams);
    curl_setopt($ch, CURLOPT_NOPROGRESS, 1);  
    curl_setopt($ch, CURLOPT_VERBOSE, 0);  
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);  
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_USERAGENT, $agent);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$postparams);
    
    $buffer = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);
    
    if(!empty($error))
    {
        //handle error
    }
    
    $json = json_decode($buffer, true);
    if(!$json['valid'])
    {
        //handle error
    }
    else
    {
        //article updated successfully
    }
}