Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding users to a list via PHP #1110

Open
Rvnd0m opened this issue Jun 24, 2024 · 1 comment
Open

Adding users to a list via PHP #1110

Rvnd0m opened this issue Jun 24, 2024 · 1 comment

Comments

@Rvnd0m
Copy link

Rvnd0m commented Jun 24, 2024

Good morning,

I come from a Sendgrid ticket, as they told me to continue here as they can not discuss about PHP code via ticket...

I wonder if it is possible to add an email address to an specific user list, via PHP code execution. The objective with that code is to insert it on an Elementor Form, and then when the user submits the form, the PHP code is executed to add that user email address to the automation marketing list.

I am trying with this code, but I get an error when I submit the form (= when the PHP is executed).

Thank you in advance if someone could help! :)

$curl = curl_init();
 
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.sendgrid.com/v3/marketing/contacts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode(array(
  "list_ids" => ["b*****my_list_ID*****uhrega15"],
  "contacts" => [
    ["email" => $email]
  ]
)),
CURLOPT_HTTPHEADER => array(
  "authorization: Bearer SG.****my_api_key*****igedRsD",
  "content-type: application/json"
),
));
 
$response = curl_exec($curl);
$err = curl_error($curl);
 
curl_close($curl);
 
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}

@ahmadzissa
Copy link

ahmadzissa commented Aug 13, 2024

I suggest you to add more info like what error do you get

I believe the array should be like this

"list_ids" => ["bmy_list_IDuhrega15"],
"contacts" => [
"email" => $email,
//rest of the data
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants