Atlassian Confluence Basic Login API NOT Working: Page Not Found

275 views Asked by At

Working on Atlassian Confluence Basic Login API in PHP

$url = 'https://mysubdomain.atlassian.net/jira/rest/auth/1/session/';

    $curl = curl_init();
    $headers = array(
        'Content-Type:application/json',
        'Authorization: Basic '. base64_encode($username . ":" . $password)
    );
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);       
    //curl_setopt($curl, CURLOPT_USERPWD, $username.":".$password);     
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);          
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);      
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

    $postfields = array(
        'username' => urlencode($username),
        'password' => urlencode($password)
    );

    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode( $postfields ));
    $result = curl_exec($curl);

It show only Page not Found. When I give wrong username or password, it showed authentication error.

What will be the correct code for Atlassian Confluence Basic Login through REST API.

1

There are 1 answers

0
Patrick On

Try using CURLOPT_USERPWD instead of the Authorization header.

curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");