Created
July 22, 2018 10:52
-
-
Save stefankugler/ebc7b9421f7ed93ca3ba874edc4afa29 to your computer and use it in GitHub Desktop.
Import accounts using SuiteCRM API
This file contains 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 | |
require_once 'unirest-php/src/Unirest.php'; | |
Unirest\Request::verifyPeer(false); | |
$token = Unirest\Request::post("https://172.16.100.100/suitecrm/api/oauth/access_token", | |
array( | |
'Content-type: application/vnd.api+json', | |
'Accept: application/vnd.api+json', | |
), | |
array( | |
'grant_type' => 'password', | |
'client_id' => 'd834123132123-923d-12312-123123-123123123123', | |
'client_secret' => 'chosensecret', | |
'username' => 'admin', | |
'password' => 'adminpassword', | |
'scope' => 'standard:create standard:read standard:update standard:delete standard:delete standard:relationship:create standard:relationship:read standard:relationship:update standard:relationship:delete' | |
) | |
); | |
echo "<pre>"; | |
//echo var_dump($token); | |
//echo $token->body->access_token; | |
$pdo = new PDO('mysql:host=localhost;dbname=erp', 'erpuser', 'erppass'); | |
$sql = "SELECT * FROM addresses where id > 570 LIMIT 125,25"; | |
foreach ($pdo->query($sql) as $row) { | |
$record = array( | |
'data' => array( | |
'type' => 'Accounts', | |
'attributes' => array( | |
'name' => trim(utf8_encode($row['title']) . " " . utf8_encode($row['name'])), | |
'phone_fax' => $row['fax'], | |
'billing_address_street' => utf8_encode($row['adress']), | |
'billing_address_city' => utf8_encode($row['city']), | |
'billing_address_postalcode' => $row['zip'], | |
'billing_address_country' => $row['country'], | |
'phone_office' => $row['phone'], | |
'phone_alternate' => $row['cell'], | |
'website' => $row['url'], | |
'email1' => $row['email'], | |
'description' => utf8_encode($row['name2']) . "\n", | |
) | |
) | |
); | |
echo "\n"; | |
print_r($record); | |
//print_r(json_encode($record)); | |
$result = Unirest\Request::post("https://172.16.100.100/suitecrm/api/v8/modules/Accounts", | |
array( | |
'Content-type' => 'application/vnd.api+json', | |
'Accept' => ' application/vnd.api+json', | |
'Authorization' => 'Bearer ' . $token->body->access_token | |
), | |
json_encode($record) | |
); | |
//echo var_dump($result); | |
echo $result->code; | |
echo "\n-------------------\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment