John Davidson

c# - ASP.NET MVC integration with LACRM Api

0 comments
Message:


I have asked this question before in another post, however I didn't received a respond. I am trying to integrate ASP.Net MVC with Less Annoying CRM API. The purpose is to store form submissions into the CRM so as to organised each submissions into categories or tasks. The LACRM api is designed for PHP and the developers mentioned that they lack the skills to help in regards to C#.
Here is my code (The LACRM uses default fields "FullName"and "Email" then it have a parameter "CustomFields" so that custom form inputs can be created. The issue I am experiencing is that only FullName is getting registered and the "Email and "CustomFields are showing in the Api logs but not registering in the fields on the crm):
My Code:




public async Task createContact(Booking booking)
{

//string APITOKEN = "some token";
//string UserCode = "98992";
//string Function = "CreateContact";
//string PipeLineId = "3687195324475747612076041165694";
//string url = "https://api.lessannoyingcrm.com?APIToken=" + APITOKEN + "&UserCode=" + UserCode + "&Function=" + Function + "&PipelineId=" + PipeLineId + "";
string url = "https://api.lessannoyingcrm.com?APIToken=sometoken&UserCode=A2575&Function=CreateContact&PipelineId=3727019319364096972431828675722";
var postData = new List>
{

};
postData.Add(new KeyValuePair
(
"Email[1]", (new KeyValuePair("Text", booking.Email),
new KeyValuePair("Type", "Work")).ToString()
));

postData.Add(new KeyValuePair
(
"Phone[1]", (new KeyValuePair("Text", booking.Phone),
new KeyValuePair("Type", "Work")).ToString()
));

postData.Add(new KeyValuePair
(
"Website[0]", (new KeyValuePair("Text", "")).ToString()
));


postData.Add(new KeyValuePair
(
"Location", (
new KeyValuePair("", booking.PostCode)

).ToString()
));


postData.Add(new KeyValuePair
(

"CustomFields", (

new KeyValuePair("Conservatory", booking.Consevatory),
new KeyValuePair("Size", booking.Size),
new KeyValuePair("Type", booking.RoofType),
new KeyValuePair("Source", booking.HearAboutUs),
new KeyValuePair("Comment", booking.OtherInfo),
new KeyValuePair("Conservatory", booking.SelectedProduct)


).ToString()


));


using (var httpClient = new HttpClient())
{
using (var content = new FormUrlEncodedContent(postData))
{
content.Headers.Clear();
content.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

HttpResponseMessage response = await httpClient.PostAsync(url, content);

var apiresponse = await response.Content.ReadAsAsync();
}
}
return true;
}


And this is the LACRM PHP code:




$_REQUEST['ContactName'],
"Email"=>array(
0=>array(
"Text"=>"$_REQUEST[Email]",
"Type"=>"Work"
)
),
"Phone"=>array(
0=>array(
"Text"=>"$_REQUEST[Phone]",
"Type"=>"Work"
)
),
);

//...And then use the "CallAPI" function to send the information to LACRM
$Result = CallAPI($UserCode, $APIToken, $Function, $Parameters);
//That's it, the contact will now show up in the CRM!

//Now let's enter the "Comment" field from the HTML form as a note on the contact's record
//Get the new ContactId
$ContactId = $Result['ContactId'];


$Function = "CreateNote";
$Parameters = array(
"ContactId"=>$ContactId,
"Note"=>$_REQUEST['Comment']
);

//And pass that note to the API
$Result = CallAPI($UserCode, $APIToken, $Function, $Parameters);

/*
There are all kinds of other things you might want to do here as well such as:
-Set a task to follow up with the contact (https://www.lessannoyingcrm.com/help/topic/API_Example_Code_PHP/11/)
-Add the contact as a lead (https://www.lessannoyingcrm.com/help/topic/API_Example_Code_PHP/87/)
-Add the contact to a group (https://www.lessannoyingcrm.com/help/topic/API_Example_Code_PHP/13/)
-Send an email to yourself letting you know a form was submitted (you can use the PHP "mail" function)
*/


//Now forward the visitor to an html page confirming that we got their contact info
header('location:confirm.html');


/*
This function takes all of the settings needed to call the API and puts them into
one long URL, and then it makes an HTTP request to that URL.
*/
function CallAPI($UserCode, $APIToken, $Function, $Parameters){
$APIResult = file_get_contents("https://api.lessannoyingcrm.com?UserCode=$UserCode&APIToken=$APIToken&".
"Function=$Function&Parameters=".urlencode(json_encode($Parameters)));
$APIResult = json_decode($APIResult, true);

if(@$APIResult['Success'] === true){
//echo "Success!";
}
else{
echo "API call failed. Error:".@$APIResult['Error'];
exit;
}
return $APIResult;
}


I would great appreciate any help in getting the customfield working. thank you



My Answer:
Hello! How can I assist you today?

Rate this post

3 of 5 based on 1999 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us