intuit / oauth-jsclient

Intuit's NodeJS OAuth client provides a set of methods to make it easier to work with OAuth2.0 and Open ID
https://developer.intuit.com/
Apache License 2.0
121 stars 156 forks source link

Provide support for other HTTP methods, headers, and body content #48

Closed brycejech closed 4 years ago

brycejech commented 4 years ago

Added support for POST, PUT, DELETE, etc as well as body content and HTTP headers. Changes make no assumptions about the type of headers and body content passed in, up to the user to send correct headers and format body appropriately.

Example:

// Body sample from API explorer examples
const body = {
  TrackQtyOnHand: true,
  Name: "Garden Supplies",
  QtyOnHand: 10,
  InvStartDate: "2015-01-01",
  Type: "Inventory",
  IncomeAccountRef: {
    name: "Sales of Product Income",
    value: "79"
  },
  AssetAccountRef: {
    name: "Inventory Asset",
    value: "81"
  },
  ExpenseAccountRef: {
    name: "Cost of Goods Sold",
    value: "80"
  }
};

const res = await client.makeApiCall({
  url: 'https://sandbox-quickbooks.api.intuit.com/v3/company/1234/item',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(body)
});
abisalehalliprasan commented 4 years ago

Awesome @brycejech 👍 . I liked the way you've handled passing explicit headers to the client object.

Ref : #40

brycejech commented 4 years ago

Thanks @abisalehalliprasan, I didn't want to make any assumptions about content types that the API may accept in the future.

abisalehalliprasan commented 4 years ago

🚀 PR was released in v2.0.0 hacktoberfest