Post a proudct with MWS api and Ruby on Rails - ruby-on-rails

I'm trying to upload a new product to mws with the mws api and mws gem
The product is added (like Fix failed listings, because, doen't have a quantity and price)
I'm trying with the next code:
mws = Mws.connect(
merchant: 'merchant',
access: 'access',
secret: 'secret'
)
Later:
product = Mws::Product('11333663') { upc '1234355462233' tax_code
'GEN_TAX_CODE' name 'Some Pduct 034' brand 'Some Bnd' msrp 18.9,
'USD' quantity 10 manufacturer 'Some Mufacturer' category :ce
details {
cable_or_adapter {
cable_length as_distance 5, :feet
} } }
later:
submission_id = mws.feeds.products.add(product)
The product is added, but when I excuted this line:
submission_id = mws.feeds.products.update(product)
The next message is displayed:
=> #<Mws::Apis::Feeds::SubmissionResult:0x9d9ae78 #transaction_id="12345678", #status=#<Mws::EnumEntry:0x9d96170
#sym=:complete, #val="Complete">, #messages_processed=0,
#counts={:success=>0, :error=>1, :warning=>0},
#responses={:"0"=>#, #code=90208, #description="Purge
and replace is not allowed for this feed type.">}>
2.0.0-p195 :050 > result = mws.feeds.get(submission_id.id)
=> #, #messages_processed=1,
#counts={:success=>0, :error=>1, :warning=>0},
#responses={:"0"=>#, #code=90000,
#description="http://sellercentral.amazon.com/myi/search/ErrorListingsSummary?batchId=7564766086">,
:"1"=>#, #code=99042, #description="A
value was not provided for \"item_type\". Please provide a value for
\"item_type\". Please use the Product Classifier or download the
category-specific Browse Tree Guide from Seller Help to see a list of
valid \"item_type\" values. This information tells Amazon where your
product should be classified and affects how easily customers can find
your product.", #additional_info={:sku=>"11333668"}>}>
But, when I tried update the inventory and the price, the follow error ocurred:
result = mws.feeds.get(price_submission_id.id) =>
#sym=:complete, #val="Complete">, #messages_processed=0,
#counts={:success=>0, :error=>1, :warning=>0},
#responses={:"0"=>#, #code=90208, #description="Purge
and replace is not allowed for this feed type.">}>
What can I do?

Without any indepth knowledge of that Ruby Gem (and of Ruby), I can probably still point you in the right direction:
In MWS, feeds automatically update information already in the Amazon database. The call to create a record is identical to a subsequent call to update it. That also means you don't have to keep track of which items were already added to Amazon in the past.
In terms of your Ruby library, you probably should call mws.feeds.products.add(product) for subsequent updates of that product record and not call mws.feeds.products.update(product) at all. The latter seems to create what's called PurgeAndReplace feeds in MWS which you should avoid like the plague.
All other errors you encountered seem to be related to the same root cause.

Related

create inboundshipment using peddler in rails

I tried to create InboundShipment.
client.create_inbound_shipment(id, inbound_shipment_header, inbound_shipment_items)
id is shipplan id created by Shipplan.
inbound_shipment_header = {:shipment_name=>"kum_03_01_2019_AVP1", :ship_from_address=>{:name=>"xxxx", :address_line1=>"xxxx", :address_line2=>"", :city=>"xxxx", :state_or_province_code=>"XX", :postal_code=>"xxxx", :country_code=>"xxxx"}, :destination_fulfillment_center_id=>"AVP1", :label_prep_preference=>"SELLER_LABEL", :are_cases_required=>false, :shipment_status=>"WORKING", :intended_box_contents_source=>"2D_BARCODE"}
inbound_shipment_items = [{:seller_sku=>"SKU", :quantity=>25, :prep_details=>[{:prep_instruction=>"Labeling", :prep_owner=>"SELLER"}]}]
But it return error following as.
#<Peddler::Errors::InvalidRequestException: Error: You must include a valid ShipmentId with a call to the CreateInboundShipment operation. Get ShipmentId values by calling the CreateInboundShipmentPlan operation. The request to CreateInboundShipment must include only items and quantities that have been previously planned through CreateInboundShipmentPlan. If a ShipmentId is not used to create a shipment within 48 hours it will expire.>
When I tried this on MWS scratch pad, it's working normally.
What's the solution to create the Inbound Shipment on RubyOnRails?
I just solved the issue.
There was an mistake when write the inbound_shipment_item.
inbound_shipment_item should be following as.
inbound_shipment_items = [{:seller_sku=>"SKU", :quantity_shipped=>25, :prep_details=>[{:prep_instruction=>"Labeling", :prep_owner=>"SELLER"}]}]

Stripe API auto_paging get all Stripe::BalanceTransaction except some charge

I'm trying to get all Stripe::BalanceTransaction except those they are already in my JsonStripeEvent
What I did =>
def perform(*args)
last_recorded_txt = REDIS.get('last_recorded_stripe_txn_last')
txns = Stripe::BalanceTransaction.all(limit: 100, expand: ['data.source', 'data.source.application_fee'], ending_before: last_recorded_txt)
REDIS.set('last_recorded_stripe_txn_last', txns.data[0].id) unless txns.data.empty?
txns.auto_paging_each do |txn|
if txn.type.eql?('charge') || txn.type.eql?('payment')
begin
JsonStripeEvent.create(data: txn.to_json)
rescue StandardError => e
Rails.logger.error "Error while saving data from stripe #{e}"
REDIS.set('last_recorded_stripe_txn_last', txn.id)
break
end
end
end
end
But It doesnt get the new one from the API.
Can anyone could help me for this ? :)
Thanks
I think it's because the way auto_paging_each works is almost opposite to what you expect :)
As you can see from its source, auto_paging_each calls Stripe::ListObject#next_page, which is implemented as follows:
def next_page(params={}, opts={})
return self.class.empty_list(opts) if !has_more
last_id = data.last.id
params = filters.merge({
:starting_after => last_id,
}).merge(params)
list(params, opts)
end
It simply takes the last (already fetched) item and adds its id as the starting_after filter.
So what happens:
You fetch 100 "latest" (let's say) records, ordered by descending date (default order for BalanceTransaction API according to Stripe docs)
When you call auto_paging_each on this dataset then, it takes the last record, adds its id as the
starting_after filter and repeats the query.
The repeated query returns nothing because there are noting newer (starting later) than the set you initially fetched.
As far as there are no more newer items available, the iteration stops after the first step
What you could do here:
First of all, ensure that my hypothesis is correct :) - put the breakpoint(s) inside Stripe::ListObject and check. Then 1) rewrite your code to use starting_after traversing logic instead of ending_before - it should work fine with auto_paging_each then - or 2) rewrite your code to control the fetching order manually.
Personally, I'd vote for (2): for me slightly more verbose (probably), but straightforward and "visible" control flow is better than poorly documented magic.

delete files from Google Drive Service account with the google drive gem

We created a synchronizer plugin for discourse and it should synchronize backups to the google drive service account.
In order to keep the admin's google drive account clutterfree, we built a method at the end of the synchronizer, that is called remove_old_files
def remove_old_files
google_files = session.files
sorted = google_files.sort_by {|x| x.created_time}
keep = sorted.take(SiteSetting.discourse_sync_to_googledrive_quantity)
trash = google_files - keep
trash.each { |d| d.delete(true) }
end
we memoized the session object before in an instance variable. So with session.files we get an array of all the files in our google drive account. In the sorted variable we sort them from new to old. In the keep variable we take the first few (the admin hat to set the quantity) and in the trash variable we define the rest. Until here the method works in the console.
Now in the documentation for the Google Drive gem there is a delete method for the File object:
File 'lib/google_drive/file.rb', line 182
def delete(permanent = false)
if permanent
#session.drive.delete_file(id)
else
#session.drive.update_file(id, { trashed: true }, {})
end
nil
end
But when I try to delete via the rails console, it tells me Success - nil as if everything went fine. But ! the files are still there when I count them or call them. Even though I tried to delete them setting permanent = true :/
Why doesn't google delete the old backup files?

Unit Price Attribute Not Visible in Quickbooks Desktop API

I don't see the Unit Price attribute available in the Item Class when it comes to QBD. Its available in QBO. I am trying to download and fill a database using the items entered via Quickbooks desktop version. Can someone help please?
How can I get the Unit Price for an item in Intuit.Ipp.Data.Qbd.Item?
Extra Information Added after comment by Shivan Raptor (7-Nov-2013)
I am having a Quickbooks Pro Trial 2014 UK version installed in my computer. I have created a company file and items for the company. When I create an item I can enter a Price to that item. Quickbooks must be saving it somewhere. I need to access it using the Quickbooks API from my .Net application.
I am interested on the stock items here. I am using Intuit.Ipp.Data.Qbd.Item class to access it. Am I using the right class? If you go to the API documentation the Item class has a field called Unit Price but its not listed when you actually check from the .Net application.
Shivan Raptor wanted the code (8-Nov-2013)
Given below is the code snippet. If you understand the question properly you would realize it cannot give a run time error because you cannot compile a code if you write it with object attributes that are not exposed. And the compiler error is kind of obvious too:
ATTRIBUTE_NAME not present in CLASS_NAME
In this case, ATTRIBUTE_NAME = UnitPrice and CLASS_NAME = Intuit.Ipp.Data.Qbd.Item (this is already there in the first post itself)
The relevant code sample is given below. Its the code behind of an ASP.Net page.
Try
Dim varItemBL As New BL.ItemManagement
'Preparing Query
Dim qbdItemQuery As New Intuit.Ipp.Data.Qbd.ItemQuery
qbdItemQuery.ItemElementName = Intuit.Ipp.Data.Qbd.ItemChoiceType4.StartPage
qbdItemQuery.Item = "1"
qbdItemQuery.ChunkSize = "10"
'Quering Quickbooks Desktop
Dim qbdItems = qbdItemQuery.ExecuteQuery(Of Intuit.Ipp.Data.Qbd.Item)(context).ToList
'Synchronising Items from Quickbooks to MyDigiRep
For i As Integer = 0 To qbdItems.Count - 1
Dim varUnitPrice As Decimal
'Checking whether Unit Price is entered
If qbdItems(i).UnitPrice Is Nothing Then
varUnitPrice = 0
Else
varUnitPrice = qbdItems(i).UnitPrice.Amount
End If
'Synchronising Item with the MyDigiRep database
varItemBL.fnAddItemsAPI(qbdItems(i).Name, "NS", varUnitPrice, _
qbdItems(i).UOMAbbrv, HttpContext.Current.Session("companyID"), _
qbdItems(i).Id.Value)
Next
'Updating UI to display synchronisation results
lblItemSycnStatus.Text = qbdItems.Count & " Item Records Synchronised."
Catch ex As Exception
lblItemSycnStatus.Text = "Item Records Synchronisation Failed."
End Try
The version of the Intuit.Ipp.Data.dll is 2.1.12.0

ElasticSearch percolate over a set

From tire gem's DSL example the following code was given.
index = Tire.index('weather') do
delete
create
# First, a query named _warning_,
register_percolator_query('warning', :tags => ['warning']) { string 'warning OR severe OR extreme' }
# a query named _tsunami_,
register_percolator_query('tsunami', :tags => ['tsunami']) { string 'tsunami' }
end
matches = index.percolate(:message => '[Warning] Extreme flooding expected after tsunami wave.')
I was wondering how can we set the matching criteria to a set of terms instead of ORed string.
For instance string 'warning weather OR severe weather OR extreme weather' would match warning or weather and not both warning weather together.
I am studying ElasticSearch because I will use it soon, but I did not use it yet so I can try and share my thin knowledge :)
Please check their doc http://www.elasticsearch.org/guide/reference/query-dsl/query-string-query/
And look at the default_operator setting, I guess you need to set it to AND

Resources