How to connect Magento 2 with Freshsales via Webhook

Freshsales is a platform that helps store owners manage and track activities, events of a store or businesses in terms of Leads, Contacts, Accounts, Deals, Notes, Tasks, Appointments, Sales activities, Search, Phone, Files. With the storage of transaction and customers information at Freshsales, the store owner can easily manage the store as well as capture the market trends and customers needs. Currently, Magento 2 does not support integration with Freshsales. To solve this problem, Mageplaza develops Webhook extension which allows Magento 2 to integrate with Freshsales. As a result, store owners can easily manage and grow their business.

Also, you can find the ultimate extension to automatically sychronize Magento 2 data to Freshsales here.

What Is Webhook?

Webhook is a helpful tool which allows online stores to configure to send an API request to a configurable destination (URL) such as other servers or applications in cases trigger events including new order, customer login, abandoned carts, etc occur. As a result, store owners can instantly update important notifications and have suitable activities shortly.

Table Of Content

Webhook supports the following entities of Magento:

  • Customer
  • Order
  • Invoice
  • Shipment
  • Credit Memo
  • Product
  • Category
  • Abandoned Cart

These entities of Freshsales:

  • Leads
  • Contacts
  • Accounts
  • Deals
  • Notes
  • Tasks
  • Appointments
  • Sales activities
  • Search
  • Phone
  • Files

How To Integrate Freshsales with Magento 2 With Webhook

Instructions For Registering And Using Freshsales

Access to here, then click Sign up to register > Fill in all fields with information > Click on the Sign up for free button to complete the registration.

Instructions For Registering And Using Freshsales 1

After signing up successfully, please click on your account icon on the top right corner of the screen and select Settings. Instructions For Registering And Using Freshsales 2

Please click Settings > API Setting to get your API key.

Instructions For Registering And Using Freshsales 3

These Fields Of Freshsales

To view the latest fields of Freshsales, you can click here.

Instructions For Creating Hook

How to create a new lead in Freshsales via Magento 2

Required fields

  • last_name

Optional fields:

  • first_name
  • job_title
  • department
  • email
  • work_number
  • mobile_number
  • address
  • city
  • state
  • zipcode
  • country
  • has_authority
  • do_not_disturb
  • medium
  • keyword
  • time_zone
  • facebook
  • twitter
  • linkedin
  • creat_at
  • update_at

In this part, I will give detail instructions on how to configure Webhook which helps Magento 2 integrate with Freshsales.

From the Admin Panel, go to System > Webhook > Manage Hooks, select Add New on the right corner, then you will see many options including New Order, New Customer, Update Customer, Delete Customer, etc.

Step 1: Fill all information in the General Information tab

Instructions For Creating Hook 1

Step 2: Enter the data on the Action tab

Instructions For Creating Hook 2 Instructions For Creating Hook 3

Note:

Payload URL: Use the link coming from Freshsales:

  • Method POST: https://domain.freshsales.io/api/leads,
  • GET: https://domain.freshsales.io/leads/view/4000831345 or https://domain.freshsales.io/leads/view/4000831345new_customer= with the domain being your API account.

Headers: Click Add button to add values of headers such as Name and Value, according to requests of servers, in order to call this API. The Value field is the API key coming from Freshsales.

  • Example: Name: Authorization, Value is Token token= “Your API Key”.
  • With method POST, you need to add: Name = Content Type, Value = Value of Content Type on Headers.
  • For example:

Instructions For Creating Hook 4

Body: With POST or PUT method, you need to add content on Content section to send the request. Click Insert Variable to choose variable.

  • For example: When you create a hook with the customer with POST method, you need to insert the following content into Body part:
 {
   "lead": {
     "first_name": "Eric",
     "last_name": "Sampleton (sample)",
     "email": null,
     "mobile_number": "1-926-652-9504",
     "address": null,
     "city": null,
     "state": null,
     "zipcode": null,
     "country": null,
     "display_name": "Eric Sampleton (sample)",
     "avatar": null,
     "keyword": null,
     "custom_field": {}
   }
}

Note: If you want to get any data field, you need to change the value of this data field with variable coming from Insert Variable.

The results of creating a hook:

Instructions For Creating Hook 5

Once some events in Store such as adding new customer, new order, etc occurs, the data will be saved on Hook Logs: Instructions For Creating Hook 6

Click Select > View to redirect to View log page, in order to view the data information: Instructions For Creating Hook 7

The Result Shown In Freshsales:

The Result Shown In Freshsales

These Available Body Templates

New Contact

  • End point: POST /api/contacts

Required fields:

  • last_name

Optional fields:

  • first_name
  • job_title
  • department
  • email
  • work_number
  • mobile_number
  • address
  • city
  • state
  • zipcode
  • country
  • sales_account_id
  • has_authority
  • do_not_disturb
  • medium
  • keyword
  • time_zone
  • facebook
  • twitter
  • linkedIn
  • created_at
  • updated_at

Payload URL: https://domain.freshsales.io/api/contacts with the domain being your Freshsale account. With the POST method, you need to insert the following content into Body part:

{
	"contact": {
		"first_name": "James",
		"last_name": "Sampleton (sample)",
		"display_name": "James Sampleton (sample)",
		"avatar": null,
		"city": null,
		"state": null,
		"zipcode": null,
		"country": null,
		"email": null,
		"mobile_number": "1-926-555-9503",
		"address": null,
		"last_contacted": null,
		"open_deals_amount": "0.0",
		"keyword": null,
	}
}

New Account

End point: POST /api/sales_accounts

Required fields:

  • name

Optional fields:

  • address
  • city
  • state
  • zipcode
  • country
  • number_of_employees
  • annual_revenue
  • website
  • phone
  • facebook
  • twitter
  • linkedIn
  • created_at
  • updated_at
  • parent_sales_account_id

Payload URL: https://domain.freshsales.io/api/sales_accounts. with the domain being your Freshsales account. With the POST method, you need to insert the following content into Body part:

{
	"sales_account": {
		"name": "Widgetz.io (sample)",
		"address": null,
		"city": null,
		"state": null,
		"zipcode": null,
		"country": null,
		"number_of_employees": null,
		"phone": null,
		"last_contacted": null,
		"avatar": null
	}
}

New Deal

End point: POST /api/deals

Required fields:

  • name
  • amount

Optional fields:

  • base_currency_amount
  • sales_account_id
  • expected_close
  • closed_date
  • probability
  • created_at
  • updated_at

Payload URL: https://domain.freshsales.io/api/deals. With the domain” is your account name in Freshsales.

With the POST method, you need to insert the following content into Body part:

{
	"users": [{
		"id": 1,
		"display_name": "Sample User",
                    "email":"sampleuser@yourcompany.com"
		            	}],
   	"deal": {
		"id": 1,
		"name": "Sample deal",
		"amount": "23456.0",
		"base_currency_amount": "23456.0", 
		"expected_close": null,
		"closed_date": null,	 
		"probability": null		
		"age": null,
		"creater_id": 1
	}
}

Note: If you want to get any data field, you need to change the value of null with variable coming from Insert Variable.

Conclusion

In this tutorial, we introduce how to register Freshsales, create Hook with Mageplaza Webhook Extension, and integrate Freshsales with Magento 2. In addition, you can refer to other useful extensions for your store here.

Explore Mageplaza Webhook for Magento 2 now!






Back Ask Mageplaza

magento-2-tutorial
webhook