Hi
I am trying to create lead from my website purechat (Live chat) data . How I should achieve this , As I can not find purechat API details anywhere.
Thanks
Hemisha
Hi
I am trying to create lead from my website purechat (Live chat) data . How I should achieve this , As I can not find purechat API details anywhere.
Thanks
Hemisha
Great. Good to hear that It helped
Thank you Naveen ,
Its worked perfectly ! I was having issues to create web api but then I found bellow video and then all together its solved my issues .
Can you share your code here? so that I can figure out what exactly you are trying to implement. As per my understanding so far, you want to send the to D365 Leads.
This can be achieved by calling this function "purechatApi.on('chat:start', function (args) {" inside the code snippet you got from PureChat.
You can store the lead details in a local object and then call the D365 API to push the data:
purechatApi.on('chat:start', function (args) {
console.log('Visitor started a new chat!');
console.log(args.chatboxId) // Prints the ID of the chatbox to the console window
console.log(args.name) // Prints the name of the visitor that started the chat
console.log(args.email) // Prints the email of the visitor that started the chat
console.log(args.phoneNumber) // Prints the email address of the visitor that started the chat
console.log(args.question) // Prints the question the visitor entered when he / she started the chat
// Replace the endpointUrl with the URL of your CRM instance
var endpointUrl = "">yourCRMinstance.crm.dynamics.com";
// Replace the accessToken with a valid access token
var accessToken = "yourAccessToken";
//Call your method that connects to the dynamics 365
fetch(endpointUrl + '/api/data/v9.1/leads', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + accessToken
},
body: JSON.stringify({
"firstname": args.name,
"email": args.email
})
})
.then(response => response.json())
.then(data => {
console.log("Lead created with ID: " + data.id);
})
.catch(error => {
console.error('Error:', error);
});
});
Please make sure to generate the valid access token based on the client id and secret.
https://www.c-sharpcorner.com/article/generate-access-token-for-dynamics-365-single-tenant-server-to-server-authentica/
So sorry but not getting your point , I know this script but my question is for d365 . Where I need to add this js and tell d365 to create lead .
On which event or place like should create flow etc
Thanks
Hemisha
Correct. This function triggers when someone starts the chat on your site: purechatApi.on('chat:start', function (args) {
You can place your D365 connection code here to send the data to Lead/contact
I actually need when people contact on purechat via our website . people detail comes to D365 and create either lead entry or contact entry .
Hi,
You have to add the code where you are creating the object of purechatApi I mean where you have placed the code snippet from PureChat.
I believe it is placed just before your closing body tag. You need to add the above code for user info here in the same snippet.
Hi Naveen ,
Thank you for your reply . How I can do that in Live version ? and where should I add above script ?
Thanks
Hemisha
Hello,
I believe you can utilize this API for getting the data from PureChat to create a lead :
<script>
// Chat start
purechatApi.on('chat:start', function (args) {
console.log('Visitor started a new chat!');
console.log(args.chatboxId) // Prints the ID of the chatbox to the console window
console.log(args.name) // Prints the name of the visitor that started the chat
console.log(args.email) // Prints the email of the visitor that started the chat
console.log(args.phoneNumber) // Prints the email address of the visitor that started the chat
console.log(args.question) // Prints the question the visitor entered when he / she started the chat
});
</script>
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,554 Super User 2024 Season 2
Martin Dráb 228,588 Most Valuable Professional
nmaenpaa 101,148