Skip to content

Instantly share code, notes, and snippets.

@omidnasri
Last active May 26, 2019 11:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omidnasri/42e162779c73eaac31c717dbb132b7b3 to your computer and use it in GitHub Desktop.
Save omidnasri/42e162779c73eaac31c717dbb132b7b3 to your computer and use it in GitHub Desktop.
A simple solution to store person in CRM.
<?php
/**
* Target: SavePerson
*
* Authors: Hossein Neshati, Omid Nasri
*
* Description: A simple solution to store person in CRM.
*
* Version: 1.0
*/
try
{
// Enter the field with the username and password that has the necessary permission to store the person.
$username = 'admin';
$password = 'admin';
// Replace <url> keyword to your CRM host address.
$url = 'http(s)://<url>/services/api/IPerson.svc?wsdl';
// Create new instance of SoapClient to call SavePerson method.
$soapClient = new SoapClient( $url );
$params = array(
'username' => $username,
'password' => $password,
'person' => array(
'CrmObjectTypeCode' => 'code1',
'CrmObjectTypeIndex' => 24,
'Categories' => array(
array(
'Key' => 'keyno'
)
),
'IdentityType' => 'Person',
'FirstName' => 'Hossein',
'LastName' => 'Akbari'
)
);
// Calling the SavePerson method.
$result = $soapClient->SavePerson($params);
// Checked that the operation was successful or not.
if ($result->SavePersonResult->Success)
{
//Converting Object to JSON type then print output vlaue.
echo json_encode($result, JSON_UNESCAPED_UNICODE);
}
else
echo $result->SavePersonResult->Message;
}
catch ( Exception $e )
{
// Print exception message
echo $e->getMessage();
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment