Last active
November 19, 2015 14:31
-
-
Save aabir/5c3bef6e9b2eaf90982c to your computer and use it in GitHub Desktop.
Capsule CRM XML API request using PHP
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 | |
$add_person="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n | |
<person>\n | |
<contacts>\n | |
<address>\n | |
<type>Postal</type>\n | |
<city>Mountain View</city>\n | |
<zip>94043</zip>\n | |
</address>\n | |
<email>\n | |
<type>Work</type>\n | |
<emailAddress>[email protected]</emailAddress>\n | |
</email>\n | |
<phone>\n | |
<type>Mobile</type>\n | |
<phoneNumber>+1 888 555555</phoneNumber>\n | |
</phone>\n | |
</contacts> \n | |
<firstName>Test12</firstName>\n | |
<lastName>Tester12</lastName>\n | |
<about>Testing</about>\n | |
</person>"; | |
$capsulepage_person = 'https://deking.capsulecrm.com/api/person'; | |
$ch = curl_init($capsulepage_person); | |
$options = array(CURLOPT_USERPWD => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', // change accordingly | |
CURLOPT_HTTPHEADER => array('Content-Type: application/xml'), | |
CURLOPT_HEADER => true, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_POST => true, | |
CURLOPT_POSTFIELDS => $add_person | |
); | |
curl_setopt_array($ch, $options); | |
$response = curl_exec($ch); | |
$responseInfo = curl_getinfo($ch); | |
curl_close($ch); | |
//echo "<pre>"; | |
//print_r($response); | |
//echo "<br>"; | |
// get newly created party ID | |
$first_explode = explode("Location:", $response); | |
$second_explode = explode("https://deking.capsulecrm.com/api/party/", $first_explode[1]); | |
$party_id = substr($second_explode[1], 0, 8); | |
//create opportunity to the party ID | |
if($party_id){ | |
$add_oppotunity="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n | |
<opportunity> \n | |
<name>Sales Lead</name> \n | |
<description>From dekingdecks website</description> \n | |
<currency>AUD</currency> \n | |
<value>2000.00</value> \n | |
<milestone>New</milestone> \n | |
<owner>JoGreenwood</owner>\n | |
</opportunity>"; | |
} | |
$capsulepage_oppotuniy = 'https://deking.capsulecrm.com/api/party/'.$party_id.'/opportunity'; | |
$ch_oppo = curl_init($capsulepage_oppotuniy); | |
$option_oppotunity = array(CURLOPT_USERPWD => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', // change accordingly | |
CURLOPT_HTTPHEADER => array('Content-Type: application/xml'), | |
CURLOPT_HEADER => true, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_POST => true, | |
CURLOPT_POSTFIELDS => $add_oppotunity | |
); | |
curl_setopt_array($ch_oppo, $option_oppotunity); | |
$response_oppo = curl_exec($ch_oppo); | |
$responseOppoInfo = curl_getinfo($ch_oppo); | |
curl_close($ch_oppo); | |
//echo "<pre>"; | |
//print_r($response_oppo); | |
//echo "<br>"; | |
//print_r($responseOppoInfo); | |
//create tag to the party ID | |
$capsulepage_tag = 'https://deking.capsulecrm.com/api/party/'.$party_id.'/tag/Website-Lead'; | |
$ch_tag = curl_init($capsulepage_tag); | |
$option_tag = array(CURLOPT_USERPWD => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', // change accordingly | |
CURLOPT_HTTPHEADER => array('Content-Type: application/xml'), | |
CURLOPT_HEADER => true, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_POST => true | |
); | |
curl_setopt_array($ch_tag, $option_tag); | |
$response_tag = curl_exec($ch_tag); | |
$responseTagInfo = curl_getinfo($ch_tag); | |
curl_close($ch_tag); | |
echo "<pre>"; | |
print_r($response_tag); | |
echo "<br>"; | |
print_r($responseTagInfo); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment