简体   繁体   中英

PHP Jira Service Desk REST API

I am struggling to create a request on Jira Service Desk in PHP.

My code is :

public function reportIssue(Request $request) { 

    //post
    //authenticate to Jira ...
    //create request ...
    //response ....
    //do something afterwards ... post ...

    $jdata = json_encode($request);

    $ch = curl_init();

    curl_setopt_array($ch, array(

        CURLOPT_POST => 1,
        CURLOPT_URL => SERVICE_DESK_URL . '/rest/servicedeskapi/request/' . $request,
        CURLOPT_USERPWD => SERVICE_USERNAME . ':' . SERVICE_PASSWORD,
        CURLOPT_POSTFIELDS => $jdata,
        CURLOPT_HTTPHEADER => array('Content-type: application/json'),
        CURLOPT_RETURNTRANSFER => true
    ));

    $result = curl_exec($ch);

    curl_close($ch);

    return json_decode($result);
}

I am getting empty response body, still like something is wrong.

Pardon me if my mistake is obvious.

Had the same issue. Here is my working curl config:

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, SERVICE_DESK_URL . '/rest/servicedeskapi/request/' . $request);
    curl_setopt($curl, CURLOPT_HEADER, 0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_USERPWD, SERVICE_USERNAME . ':' . SERVICE_PASSWORD);
    curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
            "Content-Type: application/json;charset=UTF-8",
            'X-ExperimentalApi: opt-in'
        )
    );
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($jdata));
    $response = curl_exec($curl);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM