Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Answered

create lead from pureChat data

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

  • Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 Moderator on at
    RE: create lead from pureChat data

    Great. Good to hear that It helped

  • HGajjar Profile Picture
    HGajjar 80 on at
    RE: create lead from pureChat data

    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

  • Verified answer
    Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 Moderator on at
    RE: create lead from purChat data

    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
    HGajjar 80 on at
    RE: create lead from purChat data

    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

  • Suggested answer
    Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 Moderator on at
    RE: create lead from purChat data

    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
    HGajjar 80 on at
    RE: create lead from purChat data

    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
    Naveen Ganeshe 3,393 Moderator on at
    RE: create lead from purChat data

    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
    HGajjar 80 on at
    RE: create lead from purChat data

    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
    Naveen Ganeshe 3,393 Moderator on at
    RE: create lead from purChat data

    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

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,554 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,588 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans