lib/API/TemplatesApi.php
/**
     * Operation sendTemplateWithHttpInfo
     *
     * Render and Send Template
     *
     * @param  string $template_id (required)
     * @param  string $from_email (required)
     * @param  string $from_name (required)
     * @param  string $subject (required)
     * @param  string $to **Mixed**. string, or JSON encoded array of objects with \\\&quot;email\\\&quot; and \\\&quot;name\\\&quot; keys. &#x60;abraham.lincoln@klaviyo.com&#x60; OR &#x60;[{\\\&quot;name\\\&quot;:\\\&quot;Abraham Lincoln\\\&quot;,\\\&quot;email\\\&quot;:\\\&quot;abraham.lincoln@klaviyo.com\\\&quot;}]&#x60; (required)
     * @param  string $context Optional, JSON object. This is the context your email template will be rendered with. Email templates are rendered with contexts in a similar manner to how Django templates are rendered. This means that nested template variables can be referenced via dot notation and template variables without corresponding context values are treated as falsy and output nothing. ex: &#x60;{ \\\&quot;name\\\&quot; : \\\&quot;George Washington\\\&quot;, \\\&quot;state\\\&quot; : \\\&quot;VA\\\&quot; }&#x60; (optional, default to '{ "name" : "George Washington", "state" : "VA" }')
     *
     * @throws \Klaviyo\ApiException on non-2xx response
     * @throws \InvalidArgumentException
     * @return array of array<string,object>, HTTP status code, HTTP response headers (array of strings)
     */
Operation sendTemplateWithHttpInfo
Render and Send Template



@throws \Klaviyo\ApiException on non-2xx response
@throws \InvalidArgumentException
@return array of array, HTTP status code, HTTP response headers (array of strings)
Operation sendTemplateWithHttpInfo Render and Send Template @throws \ Klaviyo \ ApiException on non - 2xx response @throws \ InvalidArgumentException @return array of array HTTP status code HTTP response headers ( array of strings )
public function sendTemplateWithHttpInfo($template_id, $from_email, $from_name, $subject, $to, $context = '{ "name" : "George Washington", "state" : "VA" }')
    {
        $request = $this->sendTemplateRequest($template_id, $from_email, $from_name, $subject, $to, $context);
        try {
            $options = $this->createHttpClientOption();
            try {
                $response = $this->client->send($request, $options);
            } catch (RequestException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    $e->getResponse() ? $e->getResponse()->getHeaders() : null,
                    $e->getResponse() ? (string) $e->getResponse()->getBody() : null
                );
            } catch (ConnectException $e) {
                throw new ApiException(
                    "[{$e->getCode()}] {$e->getMessage()}",
                    (int) $e->getCode(),
                    null,
                    null
                );
            }
            $statusCode = $response->getStatusCode();
            if ($statusCode < 200 || $statusCode > 299) {
                throw new ApiException(
                    sprintf(
                        '[%d] Error connecting to the API (%s)',
                        $statusCode,
                        (string) $request->getUri()
                    ),
                    $statusCode,
                    $response->getHeaders(),
                    (string) $response->getBody()
                );
            }
            switch($statusCode) {
                case 200:
                    if ('array<string,object>' === '\SplFileObject') {
                        $content = $response->getBody(); 
                    } else {
                        $content = (string) $response->getBody();
                    }
                    $parsed_content = json_decode($content, TRUE);
                    if (json_last_error() != JSON_ERROR_NONE) {
                        $parsed_content = $content;
                    }
                    return [
                        $parsed_content,
                        $response->getStatusCode(),
                        $response->getHeaders()
                    ];
            }
            $returnType = 'array<string,object>';
            if ($returnType === '\SplFileObject') {
                $content = $response->getBody(); 
            } else {
                $content = (string) $response->getBody();
            }
            $parsed_content = json_decode($content, TRUE);
            if (json_last_error() != JSON_ERROR_NONE) {
                $parsed_content = $content;
            }
            return [
                $parsed_content,
                $response->getStatusCode(),
                $response->getHeaders()
            ];
        } catch (ApiException $e) {
            switch ($e->getCode()) {
                case 200:
                    $data = ObjectSerializer::deserialize(
                        $e->getResponseBody(),
                        'array<string,object>',
                        $e->getResponseHeaders()
                    );
                    $e->setResponseObject($data);
                    break;
            }
            throw $e;
        }
    }
public function sendTemplateWithHttpInfo ( $ template_id , $ from_email , $ from_name , $ subject , $ to , $ context = '{ "name" : "George Washington", "state" : "VA" }' ) { $ request = $ this -> sendTemplateRequest ( $ template_id , $ from_email , $ from_name , $ subject , $ to , $ context ) ; try { $ options = $ this -> createHttpClientOption ( ) ; try { $ response = $ this -> client -> send ( $ request , $ options ) ; } catch ( RequestException $ e ) { throw new ApiException ( " [ { $ e -> getCode ( ) } ]  { $ e -> getMessage ( ) } " , ( int ) $ e -> getCode ( ) , $ e -> getResponse ( ) ? $ e -> getResponse ( ) -> getHeaders ( ) : null , $ e -> getResponse ( ) ? ( string ) $ e -> getResponse ( ) -> getBody ( ) : null ) ; } catch ( ConnectException $ e ) { throw new ApiException ( " [ { $ e -> getCode ( ) } ]  { $ e -> getMessage ( ) } " , ( int ) $ e -> getCode ( ) , null , null ) ; } $ statusCode = $ response -> getStatusCode ( ) ; if ( $ statusCode < 200 || $ statusCode > 299 ) { throw new ApiException ( sprintf ( '[%d] Error connecting to the API (%s)' , $ statusCode , ( string ) $ request -> getUri ( ) ) , $ statusCode , $ response -> getHeaders ( ) , ( string ) $ response -> getBody ( ) ) ; } switch ( $ statusCode ) { case 200 : if ( 'array<string,object>' === '\SplFileObject' ) { $ content = $ response -> getBody ( ) ; } else { $ content = ( string ) $ response -> getBody ( ) ; } $ parsed_content = json_decode ( $ content , TRUE ) ; if ( json_last_error ( ) != JSON_ERROR_NONE ) { $ parsed_content = $ content ; } return [ $ parsed_content , $ response -> getStatusCode ( ) , $ response -> getHeaders ( ) ] ; } $ returnType = 'array<string,object>' ; if ( $ returnType === '\SplFileObject' ) { $ content = $ response -> getBody ( ) ; } else { $ content = ( string ) $ response -> getBody ( ) ; } $ parsed_content = json_decode ( $ content , TRUE ) ; if ( json_last_error ( ) != JSON_ERROR_NONE ) { $ parsed_content = $ content ; } return [ $ parsed_content , $ response -> getStatusCode ( ) , $ response -> getHeaders ( ) ] ; } catch ( ApiException $ e ) { switch ( $ e -> getCode ( ) ) { case 200 : $ data = ObjectSerializer :: deserialize ( $ e -> getResponseBody ( ) , 'array<string,object>' , $ e -> getResponseHeaders ( ) ) ; $ e -> setResponseObject ( $ data ) ; break ; } throw $ e ; } }
Operation sendTemplateWithHttpInfo
 Render and Send Template
Operation sendTemplateWithHttpInfo Render and Send Template
//stream goes to serializer //stream goes to serializer