Integrate Xero with Magento 2 With Webhook
Xero is known as useful online accounting software for businesses. There are many useful features of Xero such as creating orders, creating invoices, sending invoices, etc. To help the Magento 2 store owners be able to use Xero to develop their businesses, Mageplaza develops Webhook extension to allow Xero to integrate with Magento 2 conveniently.
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.
These entities of Magento which Webhook supports:
- Customer
- Order
- Invoice
- Shipment
- Credit Memo
- Product
- Category
- Abandoned Cart
These entities which Xero supports:
- Business
- Accounting
- Contacts
How To Integrate Xero with Magento 2 With Webhook
Instructions For Registering And Using Xero
Access to here, click the Free trial button on the right corner, then fill information in the below form completely
After completing the above registration form, click the Get started button. You need to confirm your email to complete your registration
Enter your password to active your account
Complete this below form, then click the Start Trial button or the Buy Now button to complete your registration
After signing up Xero account successfully, you need to create a new app by clicking here, then selecting My Apps > Click the New App button
Fill the information in below form, then click the Create App button to create a new app
After creating the app successfully, you will see the information about this app, as below:
OAuth 1.0a Credentials of the app will be used to verify.
In this instruction, we use Postman tool to get the value of Authorization.
Follow the instruction> to identify Authorization.
These Fields Of Xero:
To view the latest fields of Xero, you can click here
Instructions For Creating Hook
How to create a new contact in Xero via Magento 2
- Required fields
- Name
- Optional fields
- ContactID
- ContactNumber
- AccountNumber
- ContactStatus
- FirstName
- LastName
- EmailAddress
- SkypeUserName
- ContactPersons
- BankAccountDetails
- TaxNumber
- AccountsReceivableTaxType
- AccountsPayableTaxType
- Addresses
- Phones
- IsSupplier
- IsCustomer
- DefaultCurrency
- XeroNetworkKey
- SalesDefaultAccountCode
- PurchasesDefaultAccountCode
- SalesTrackingCategories
- PurchasesTrackingCategories
- TrackingCategoryName
- TrackingCategoryOption
- PaymentTerms
In this part, I will give detail instructions on how to configure Webhook which helps Magento 2 integrate with Xero.
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
Step 2: Enter the data on the Action tab
Note
- Payload URL: https://api.xero.com/api.xro/2.0/Contacts
- Headers: Click the Add button to add the value of headers such as Name and Value.
- Name: Authorization
- Value: Value of Authorization which is founded from postman according to the above instruction
- Body: With POST or PUT method, you need to add content on the Content section to send the request. Click Insert Variable to choose variable.
- For example, we use the POST method, and we want a new contract will come up in Xero when a new customer is added in Magento 2 store, we need to insert the following content into the body section:
{
"Name": "Lya Jame",
"FirstName": "Lya",
"LastName": "James",
"EmailAddress": "example@mageplaza.com"
}
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:
Once some events of Store such as add new customer, new order, etc occurs, the data will be saved on Hook Logs:
Click Select > View to redirect to View log page where you can view the data information.
The Result Shown In Xero:
These Available Body Templates:
New Invoices
Endpoint: /Invoices
- Required fields:
- Type
- Contact
- LineItems
- Optional fields:
- Date
- DueDate
- LineAmountTypes
- InvoiceNumber
- Reference
- BrandingThemeID
- Url
- CurrencyCode
- CurrencyRate
- Status
- SentToContact
- ExpectedPaymentDate
- PlannedPaymentDate
- Description
- Quantity
- UnitAmount
- ItemCode
- AccountCode
- LineItemID
- TaxType
- TaxAmount
- LineAmount
- DiscountRate
- Tracking
- Name (Name of the tracking category)
- Option (Name of the option)
Payload URL: https://api.xero.com/api.xro/2.0/Invoices
With the POST method, you need to insert the following content into the body part:
{
"Type": "ACCREC",
"Contact": {
"ContactID": "eaa28f49-6028-4b6e-bb12-d8f6278073fc"
},
"Date": "\/Date(1518685950940+0000)\/",
"DueDate": "\/Date(1518685950940+0000)\/",
"DateString": "2009-05-27T00:00:00",
"DueDateString": "2009-06-06T00:00:00",
"LineAmountTypes": "Exclusive",
"LineItems": [
{
"Description": "Consulting services as agreed (20% off standard rate)",
"Quantity": "10",
"UnitAmount": "100.00",
"AccountCode": "200",
"DiscountRate": "20"
}
]
}
Note: If you want to get any data field, you need to change the null value with variable coming from Insert Variable.
Conclusion
In this tutorial, we introduce how to register Xero, create Hook with Mageplaza Webhook Extension to integrate Xero with Magento 2 via Webhooks. In addition, you can refer to other useful extensions for your store here.
Back Ask Mageplaza