mercredi 15 novembre 2017

In Laravel How to create subscriber mailchimp using Guzzle HTTP

I am using guzzle HTTP to send the request and I am getting this error Client error: POST http://ift.tt/2z3erhd resulted in a 401 Unauthorized response: {"type":"http://ift.tt/1OKTDN5","title":"API Key Missing","statu (truncated...)

        $userArray = [];
        $operations = [];
        //used to get the patient that need to sync mailchimp
        $getPatientToSync = Patient::select('NameFirst', 'NameLast' , 'Email')      
        ->where([['flag_name' , '=', '1'], ['mailchimp_synced' ,'=' , '0']])->get();
        if($getPatientToSync->isEmpty()){
            return true;
        }
        foreach ($getPatientToSync as  $patient){
            $data = array(
                "apikey"        => config('mailchimp.api_key'),
                "email_address" => $patient->Email,
                "status"        => "subscribed",
                "merge_fields"  => array(
                    'FNAME' => $patient->NameFirst,
                    'LNAME' => $patient->NameLast,
                )
            );
            $userArray[] =  json_encode($data);
           }
        foreach ($userArray as $userArr){
            $temp = array(
                "method" => "POST",
                "path" => "/lists/".config('mailchimp.list_id')."/members/",
                "body" => $userArr
            );
            $operations['operations'][] =$temp;
        }
        $json_post = json_encode($operations);
        $auth = base64_encode( 'user:'.config('mailchimp.api_key') );
        //API URL
        $urll="https://".config('mailchimp.data_center')."http://.api.mailchimp.com/3.0/batches";
       $headers = array('Content-Type: application/json', 'Authorization: Basic 
        '.$auth , $userlist);
        $client = new Client();
        $response =  $client->request('POST', $urll , $headers,json_post );
        dd($response);



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2yIbPRG
via IFTTT

Aucun commentaire:

Enregistrer un commentaire