XF 2.1 New thread with Api and result?

Robert9

Well-known member
I use the Api to create new threads;
now i would like to have the new thread_id back; but it seems there is nothing in response?

What can i do to get the new thread_id to add a second post, please?
 

Robert9

Well-known member

i should have a "true" and the thread after sending.
Hmmm ...

My fault - solved.
 

Robert9

Well-known member
print_r($response);

shows now:

Code:
PHP: GuzzleHttp\Psr7\Response Object
(
    [reasonPhrase:GuzzleHttp\Psr7\Response:private] => OK
    [statusCode:GuzzleHttp\Psr7\Response:private] => 200
    [headers:GuzzleHttp\Psr7\Response:private] => Array
        (
            [Date] => Array
                (
                    [0] => Tue, 28 Jul 2020 22:20:35 GMT
                )

            [Server] => Array
                (
                    [0] => Apache/xxx (Debian)
                )

            [XF-Latest-Api-Version] => Array
                (
                    [0] => 1
                )

            [XF-Used-Api-Version] => Array
                (
                    [0] => 1
                )

            [XF-Request-User] => Array
                (
                    [0] => 123
                )

            [XF-Request-User-Extras] => Array
                (
                    [0] => {"conversations_unread":0,"alerts_unread":276}
                )

            [Expires] => Array
                (
                    [0] => Thu, 19 Nov 1981 08:52:00 GMT
                )

            [Cache-Control] => Array
                (
                    [0] => private, no-cache, max-age=0
                )

            [Upgrade] => Array
                (
                    [0] => h2
                )

            [Connection] => Array
                (
                    [0] => Upgrade, close
                )

            [Content-Length] => Array
                (
                    [0] => 4059
                )

            [Content-Type] => Array
                (
                    [0] => application/json; charset=utf-8
                )

        )

    [headerNames:GuzzleHttp\Psr7\Response:private] => Array
        (
            [date] => Date
            [server] => Server
            [xf-latest-api-version] => XF-Latest-Api-Version
            [xf-used-api-version] => XF-Used-Api-Version
            [xf-request-user] => XF-Request-User
            [xf-request-user-extras] => XF-Request-User-Extras
            [expires] => Expires
            [cache-control] => Cache-Control
            [upgrade] => Upgrade
            [connection] => Connection
            [content-length] => Content-Length
            [content-type] => Content-Type
        )

    [protocol:GuzzleHttp\Psr7\Response:private] => 1.1
    [stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
        (
            [stream:GuzzleHttp\Psr7\Stream:private] => Resource id #215
            [size:GuzzleHttp\Psr7\Stream:private] =>
            [seekable:GuzzleHttp\Psr7\Stream:private] => 1
            [readable:GuzzleHttp\Psr7\Stream:private] => 1
            [writable:GuzzleHttp\Psr7\Stream:private] => 1
            [uri:GuzzleHttp\Psr7\Stream:private] => php://temp
            [customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
                (
                )

        )

)


But where is my new thread_id?
 

smozgur

Member
You are looking into Guzzle response object. It is not there, you need to get the body of the response. The actual API response has the following data:

1598994314188.png

PHP:
$apiResponse = json_decode($response->getBody());
$thread = $apiResponse->thread;
print_r($thread);
 
Top