XF 2.1 issues with API and Curl PHP

margo13

New member
Hello,

I'm have troubles creating a thread with Xenforo API via CURL in PHP.
Here's my code :

Code:
$sUrl = 'https://mydomain.com/api/threads/';

        $aData = [
                    'node_id' => 13,
                    'title' => 'test title',
                    'message' => 'test message'];

        $headers = ['Content-type: application/json',
        'XF-Api-Key: ' . self::$_sApiKey,
        'XF-Api-User: 1',
        'Content-Length: ' . strlen(json_encode($aData))];



        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($ch, CURLOPT_USERPWD, "user:pwd");
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_URL, $sUrl);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aData));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $json = curl_exec($ch);
        curl_close($ch);
        var_dump($json);
        exit;

It returns false and it actually takes a lot of time to answer.

If you have any idea...?

Besides, when I try with real data, for example :

Code:
$aData = ['node_id' => '13' 
  'title' =>  '[Instruments électroniques] [SONDAGE] encore un sondage pour tester'
  'message' => '[Instruments électroniques] 
 
  Thread : [url=http://mydomain.com/test.html]http://mydomain.com/test.html[/url]
 
 Créé par : [url=http://mydomain.com/membres/2/]user[/url]
 
 signalé par [url=http://mydomain.com/membres/2/]user[/url] 

raison évoquée : 

 [quote]testtest[/quote] 
 ']

It ends up saying parameters are missing.

please help :)
 
same issue with me
{
"errors": [
{
"code": "requested_page_not_found",
"message": "The requested page could not be found.",
"params": []
}
]
}
 
Top Bottom