QuickBooks Online

Employee Management In QuickBooks Online Using C#

In this blog, I explain how to add employee, get employee and update employee using the QuickBooks API v3 in c#.

An Employee object represents a person working for the company.

SAMPLE OBJECT

{
  "Employee": {
    "SyncToken": "0", 
    "domain": "QBO", 
    "DisplayName": "Bill Miller", 
    "PrimaryPhone": {
      "FreeFormNumber": "234-525-1234"
    }, 
    "PrintOnCheckName": "Bill Miller", 
    "FamilyName": "Miller", 
    "Active": true, 
    "SSN": "XXX-XX-XXXX", 
    "PrimaryAddr": {
      "CountrySubDivisionCode": "CA", 
      "City": "Middlefield", 
      "PostalCode": "93242", 
      "Id": "116", 
      "Line1": "45 N. Elm Street"
    }, 
    "sparse": false, 
    "BillableTime": false, 
    "GivenName": "Bill", 
    "Id": "71", 
    "MetaData": {
      "CreateTime": "2015-07-24T09:34:35-07:00", 
      "LastUpdatedTime": "2015-07-24T09:34:35-07:00"
    }
  }, 
  "time": "2015-07-24T09:35:54.805-07:00"
}

 

Add Employee

Request Body

The minimum elements to create an employee are listed here.

{
  "GivenName": "Bhavdip", 
   "PrimaryAddr": {
    "CountrySubDivisionCode": "CA", 
    "City": "Middlefield", 
    "PostalCode": "93242", 
    "Id": "50", 
    "Line1": "45 N. Elm Street"
  }, 
  "PrimaryPhone": {
    "FreeFormNumber": "408-525-1234"
  }, 
  "FamilyName": "Talaviya"
}

Now I add the employee using the C# code.

Employee _employee = new Employee();
employee.GivenName = "Bhavdip";
employee.FamilyName = "Talaviya";


TelephoneNumber _Mobile = new TelephoneNumber();
Mobile.FreeFormNumber = "408-525-1234";
employee.Mobile = _Mobile;


PhysicalAddress PrimaryAddr= new PhysicalAddress();
PrimaryAddr.CountrySubDivisionCode = "CA";
PrimaryAddr.PostalCode = "94030";
PrimaryAddr.Country = "U.S.A";
PrimaryAddr.Line1 = "29834 Mustang Ave.";
PrimaryAddr.City = "Millbrae";
employee.PrimaryAddr= PrimaryAddr;
employee.Active = true;
Employee_employeeAdded = dataService.Add(employee);

you get the added employee response in the  _employeeAdded so you can see or update to your DB.

Get Employee

Query

Select * From employee

you can also make the query as you like below :

get employee by LastUpdatedTime: select * from employee where Metadata.LastUpdatedTime > ‘2015-03-01’

get employee by ID: Select * From employee where Id = ‘1’

You need Realmid and AccessTocken for the get any data from the QuickBooks.

Now I get the all employee using the C# code.

var realmid="add here your realm id";
var AccessTocken="add here your AccessTocken";

QueryService<Employee> QueryService = new QueryService<Employee>(GetContext(realmid, AccessTocken));
List<Employee> _getEmployee = QueryService.ExecuteIdsQuery("Select * From Employee").ToList();

you get the employee response in the _getEmployee variable so you can store this data into your DB.

Update Employee

In update employee, you need Quickbooks inserted Id and also SyncToken which get when the employee added.

ATTRIBUTES

  • Id

    Datatype: string
    Unique identifier for this object. Sort order is ASC by default.
  • SyncToken

    Datatype: string
    The version number of the object. It is used to lock an object for use by one app at a time. As soon as an application modifies an object, its SyncToken is incremented. Attempts to modify an object specifying older SyncToken fails. Only the latest version of the object is maintained by QuickBooks Online.

Now I update the employee using the C# code, here I update the only family name for the employee.

Employee emp = new Employee();
 emp.FamilyName  = "patel";

  
 emp.Id = "1"; 
 emp.SyncToken = "1";
 Employee _employeeUpdated = dataService.Update(emp);

 

you get the updated employee response in the _employeeUpdated so you can see or update to your DB.

you can not delete the employee in QuickBooks online, you can update this employee as In-active like below:
emp.Active = false;

so In this blog, I explained add employee, update employee and also get an employee.

Bhavdip Talaviya

I'm an Asp.net MVC, Angular developer at Surat. I am an open-minded individual with a proven track record in designing websites and creating databases. I have strong technical skills as well as excellent interpersonal skills. I am eager to be challenged in order to grow and improve my communication and professional IT skills gained through previous experiences in the IT sector

View Comments

  • How to add the data available in the _employeeAdded into the database? Can you please share the code? I am stuck at this point as data is not getting inserted.

  • How to add the values from _employeeAdded into the DB in the online QuickBooks? Can you please share the sample code as I am a newbie

Share
Published by
Bhavdip Talaviya

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago