title: Sending Grade Data back to LMS using LTI
body: <p>I've created an LTI enabled tool and am having some trouble with sending data back to an LMS such as Desire2Learn. Based on my understanding alone, you generate an XML payload containing the grade item itself and send this via POST back to the LMS using cURL. The problem I'm running into is that my $result variable is returning false and I can't figure it out right now. Here is my code:</p>
  
  <pre><code>session_start();
  
  require_once 'blti/blti.php';
  require_once 'blti/blti_util.php';
  
  define('OAUTH_CONSUMER_KEY', 'key');
  define('OAUTH_CONSUMER_SECRET', 'secret');
  
  $blti = new BLTI(OAUTH_CONSUMER_SECRET, true, false);
  if ($blti-&gt;valid) {
      $_SESSION['lis_outcome_service_url'] = $_REQUEST['lis_outcome_service_url'];
      $_SESSION['lis_result_sourcedid']    = $_REQUEST['lis_result_sourcedid'];
      $_SESSION['lis_person_name_given']   = $_REQUEST['lis_person_name_given'];
      $_SESSION['oauth_consumer_key']      = $_REQUEST['oauth_consumer_key'];
      $_SESSION['oauth_consumer_secret']   = OAUTH_CONSUMER_SECRET;
  
      sendGradeBackToLMS();
  }else {
      exit($blti-&gt;message);
  }
  
  function sendGradeBackToLMS() {
      $ch = curl_init();
      if (!$ch) { exit('curl is not supported!'); }
  
      $url = 'http://localhost/endpoint.php';
  
      $xmldata = getPOXRequest();
      $xml = str_replace(
          array('MESSAGE_IDENTIFIER', 'SOURCEDID', 'GRADE'),
          array(uniqid(), $_SESSION['lis_result_sourcedid'], 0.75),
          $xmldata);
      $request_headers = array();
      $request_headers[] = 'User-Agent: '. $_SERVER['HTTP_USER_AGENT'];
      $request_headers[] = 'Accept:     text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
  
      curl_setopt_array($ch, array(
          CURLOPT_URL =&gt; $url,
          CURLOPT_HTTPHEADER =&gt; $request_headers,
          CURLOPT_POST =&gt; true,
          CURLOPT_POSTFIELDS =&gt; $xml
      ));
  
      $results = curl_exec($ch);
      curl_close($ch);
  
      echo $results;
  }
  
  function getPOXRequest() {
      return &lt;&lt;&lt;XML
      &lt;?xml version = "1.0" encoding = "UTF-8"?&gt;
      &lt;imsx_POXEnvelopeRequest xmlns = "http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0"&gt;
        &lt;imsx_POXHeader&gt;
          &lt;imsx_POXRequestHeaderInfo&gt;
            &lt;imsx_version&gt;V1.0&lt;/imsx_version&gt;
            &lt;imsx_messageIdentifier&gt;MESSAGE_IDENTIFIER&lt;/imsx_messageIdentifier&gt;
          &lt;/imsx_POXRequestHeaderInfo&gt;
        &lt;/imsx_POXHeader&gt;
        &lt;imsx_POXBody&gt;
          &lt;replaceResultRequest&gt;
            &lt;resultRecord&gt;
              &lt;sourcedGUID&gt;
                &lt;sourcedId&gt;SOURCEDID&lt;/sourcedId&gt;
              &lt;/sourcedGUID&gt;
              &lt;result&gt;
                &lt;resultScore&gt;
                  &lt;language&gt;en&lt;/language&gt;
                  &lt;textString&gt;GRADE&lt;/textString&gt;
                &lt;/resultScore&gt;
              &lt;/result&gt;
            &lt;/resultRecord&gt;
          &lt;/replaceResultRequest&gt;
        &lt;/imsx_POXBody&gt;
      &lt;/imsx_POXEnvelopeRequest&gt;
  XML;
  }
  </code></pre>
  
  <p>Just to summarize it up, $blti is an instance that checks if it is a valid Basic LTI launch or not. If that is true, I initialize the SESSION by storing LTI request variables into SESSION variables. Next in the sendGradeBackToLMS() function I send a block of XML data containing the grade item to the path given in $url. </p>
  
  <p><strong>Any</strong> kind of input would be helpful!
  Thanks!</p>