ruckus / quickbooks-ruby

Quickbooks Online REST API V3 - Ruby
MIT License
374 stars 302 forks source link

Invalid Type : CATEGORY is supported only in minorVersion >= 4 #517

Closed szymonlipka closed 4 years ago

szymonlipka commented 4 years ago

Hey, I'm trying to create item with "Category" type and I'm getting error "Invalid Type : CATEGORY is supported only in minorVersion >= 4". I'm doing something like this:

batch_request = Quickbooks::Model::BatchRequest.new
service = Quickbooks::Service::Batch.new(access_token: access_token, realm_id: realm_id)
item = Quickbooks::Model::Item.new(id: 1, type: "Category", name: "test")
batch_request.add("bId1", item, "create")
batch_response = service.make_request(batch_request)
batch_response.response_items.first.fault.errors
=> #<Quickbooks::Model::Fault::Error:0x00007fedf2f41ce8
  @code="2120",
  @detail="Invalid Type : CATEGORY is supported only in minorVersion >= 4",
  @element="Type",
  @message="Invalid Type",
  @roxml_references=
...

I'm wondering if I'm doing something wrong or maybe type "Category" isn't really allowed for Items and the gem shouldn't allow it?

drewish commented 4 years ago

That's interesting because the model is showing 33: https://github.com/ruckus/quickbooks-ruby/blob/49f495bf77063648267bec89c61551b422d58afa/lib/quickbooks/model/item.rb#L13

If you try it outside of the batch does it give you a different result?

szymonlipka commented 4 years ago

@drewish ok, I tried and it works when I don't use batch. I don't have to use batches so good enough for me, but I think the issue is still there and should be fixed for batches.

I was trying to overwrite this MINORVERSION variable to 41 but it still didn't work, so unfortunately solution isn't so simple.

ruckus commented 4 years ago

Thanks for the update. Yeah, having the MINORVERSION specified at the model is not the best solution. Or at least there should be a facility to default to that but allow the user to over-ride at query-time.

This should be doable by overriding each service url_for_query or fetch_by_id and reading it from the options hash. I don't know if there could be a more general way to do it

ruckus commented 4 years ago

Before now I had not fully looked at the minor version documentation:

https://developer.intuit.com/app/developer/qbo/docs/develop/explore-the-quickbooks-online-api/minor-versions#working-with-minor-versions

It suggests you can apply a minorversion query param to all requests globally. That is, it doesn't need to be specified per request.

This would suggest we could do:

  1. implement a minorversion=X query param at the base of all GET requests
  2. The library can hard-code to the latest minorversion
  3. But also accept this to be provided via an over-ride

Quickbooks.platform_minor_version = 42

Thoughts?

szymonlipka commented 4 years ago

Agree. I think one, configurable minor version for all would be really nice. In my opinion it's a bit misleading that there is possibility that gem in one endpoint uses different version than in other.

drewish commented 4 years ago

Ah yeah I realized what I'd been doing for this was setting the query param for the whole batch with the version:

      options = { query: { requestid: SecureRandom.uuid, minorversion: 4 } }
      connection.quickbooks.execute_with_retries(logger: logger) do
        connection.quickbooks.service(:batch).make_request(request, options)
      end

Having it as a client level could be nice. Is there every a reason to want to downgrade the version?

ruckus commented 4 years ago

@drewish @szymonlipka I worked on this in a branch/PR: https://github.com/ruckus/quickbooks-ruby/pull/518

Basically you can set

Quickbooks.minorversion = X

as needed. The library defaults to the current highest number (47 as of now).

Anyone want to take a look?

ruckus commented 4 years ago

Pushed gem version 1.0.9 with support for this global minorversion