Created
October 4, 2024 09:50
-
-
Save BhargavBhandari90/a4147a4ee9d12f90d111efe6b9b85045 to your computer and use it in GitHub Desktop.
Add Account in Salesforce for WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$access_token = 'your_access_token'; | |
if (!$access_token) { | |
return 'Error: Unable to authenticate with Salesforce'; | |
} | |
$instance_url = 'https://youraccount.salesforce.com'; // Replace with your instance URL | |
$endpoint = $instance_url . '/services/data/v55.0/sobjects/Account'; | |
$account_data = array( | |
'Name' => $first_name, | |
'Phone' => '1234567890', | |
'RecordTypeId' => 'xxxxxxxxxxx', // Replace with your actual RecordTypeId | |
'Type' => 'TypeofAccount' | |
); | |
$response = wp_remote_post($endpoint, array( | |
'headers' => array( | |
'Authorization' => 'Bearer ' . $access_token, | |
'Content-Type' => 'application/json' | |
), | |
'body' => json_encode($account_data) | |
)); | |
if (is_wp_error($response)) { | |
return 'Error: Unable to create account'; | |
} | |
$body = wp_remote_retrieve_body($response); | |
$data = json_decode($body, true); | |
if (isset($data['id'])) { | |
return $data['id']; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment