web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

create lead from pureChat data

(0) ShareShare
ReportReport
Posted on by 80

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

I have the same question (0)
  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    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>

    purechat.com/.../javascript-api

  • HGajjar Profile Picture
    80 on at

    Hi Naveen ,

    Thank you for your reply . How I can do that in Live version ? and where should I add above script ?

    Thanks

    Hemisha

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    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.

    pastedimage1673438003706v1.png

    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. 

  • HGajjar Profile Picture
    80 on at

    I actually need when people contact on purechat via our website . people detail comes to D365 and create either lead entry or contact entry .

  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    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

  • HGajjar Profile Picture
    80 on at

    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

  • Verified answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    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/ 

  • HGajjar Profile Picture
    80 on at

    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 .

    www.youtube.com/watch

  • Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    Great. Good to hear that It helped

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 180 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 119

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans