Saving API response on submit

I’m currently using the Campaign Monitor API to let users create / send their own campaigns.

The issue I’m having is that the ID is generated once the form has been created / sent and I’m wondering what the best way to grab the generated ID then place it in the db as a field.

I am getting the ID as a variable $result->response, just not sure how to properly grab this in yii and save through the form.

My code looks like


public function actionEmailCreateCampaign($title, $subject) {




            require_once 'protected/extensions/createsend-php-5.0.1/csrest_campaigns.php';


            $auth = array('api_key' => 'key');

            $wrap = new CS_REST_Campaigns(NULL, $auth);





            $result = $wrap->create('clientid', array(

                'Subject' => $subject,

                'Name' => $title,

                'FromName' => $name,

                'FromEmail' => $email,

                'ReplyTo' => $replyto,

                'HtmlUrl' => $url,

                # 'TextUrl' => 'Optional campaign text import URL',


                //default testlist includes test emails

                'ListIDs' => $list,


                //'SegmentIDs' => $segment

            ));


            echo "Result of POST /api/v3.1/campaigns/{clientID}\n<br />";

            if($result->was_successful()) {

                echo "Created with ID\n<br />".$result->response;


            } else {

                echo 'Failed with code '.$result->http_status_code."\n<br /><pre>";

                var_dump($result->response);

                echo '</pre>';

            }

    }



so I need to grab the result->response and place it in the following piece of code at the same time as model->save


public function actionCreate()

{

    $model=new CMCampaign;

    // Uncomment the following line if AJAX validation is needed

    // $this->performAjaxValidation($model);


    if(isset($_POST['CMCampaign']))

    {   


        $model->attributes=$_POST['CMCampaign'];


        //grab data for use in the campaign monitor API

        $title = $model->title;

        $subject = $model->subject;


        $this->actionEmailCreateCampaign($title, $subject);


        if($model->save())




            $this->redirect(array('view','id'=>$model->id));

    }


    $this->render('create',array(

        'model'=>$model,

    ));

}

I have tried $model->cm_campaign_id = $result->response; but it does not save the id at all.

bump