1

I need to update data in HP Quality Center with Drupal.

After login with success, I get some data from QC with the following code (simplified):

$headers = array('Cookie' => $cookie);
$request = drupal_http_request('http://qc.intra.xxx.com:8090/qcbin/rest/domains/' . $domainname . '/projects/' . $projectname . '/test-instances?query={cycle-id["' . $id . '"]}', 
    array('headers' => $headers), 
    'GET'
);
$xml = simplexml_load_string($request->data);
$json = json_encode($xml);
$testset_array = json_decode($json, TRUE);

What I want now is to update some QC fields. For that, instead of GET, I need PUT. The code I've tried to update a test instance:

    $xml_data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
            <Entity Type="test-instance">
                <Fields>
                    <Field Name="my_field">
                        <Value>my value</Value>
                    </Field>
                </Fields>
            </Entity>';

    $headers = array('Cookie' => $cookie, 'content-type' => 'application/xml');

    $url = 'http://qc.intra.xxx.com:8090/qcbin/rest/domains/' . $domainname . '/projects/' . $projectname . '/test-instances/404886';
    $request = drupal_http_request($url, 
       array('headers' => $headers), 
       'PUT', 
       $data
    );

    $xml = simplexml_load_string($request->data);
    $json = json_encode($xml);
    $testset_array = json_decode($json, TRUE);

This is not working and I don't get any error also, what am I doing wrong?

Thanks

0

1 Answer 1

3
+50

For starters, looking at your code, $xml_data is instantiated but never used in your call to drupal_http_request(), you use the $data variable instead. Intentional or the culprit?

Second, your call to drupal_http_request follows the Drupal 6 (and earlier) syntax, what system are you using?

For Drupal 7, it should look like this:

$response = drupal_http_request($url, 
  array(
    'headers' => $headers,
    'method' => 'PUT', 
    'data' => $xml_data,
  )
);

// this should reveal what was actually sent out
dsm($response->request);

Hope this helps some!

7
  • Thanks Stefanos. $xml_data and $data are the same, my mistake. About your solution, you missed a closing bracket in $response and I think that part has another error (=$request). Anyways, I tried and it didn't work. I can do it using external apps, like Postman on chrome but not in drupal.
    – zephirus
    May 29, 2016 at 23:31
  • So, to the second question, is this on a Drupal 6 or 7 system? Cheers! May 30, 2016 at 5:56
  • Drupal 7, forgot to mention that...
    – zephirus
    May 30, 2016 at 8:14
  • All right, so your function call is not correct, did you try the example I placed in the answer? Method and data should be part of the $options array (the second argument to drupal_http_request. Curious to see how this works out. May 30, 2016 at 8:16
  • I get this error: Notice: Undefined property: stdClass::$request and I get a connection timeout error, altought I make the login request with success.
    – zephirus
    May 30, 2016 at 9:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.