Skip to content

Instantly share code, notes, and snippets.

@iamricks
Created July 29, 2021 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamricks/455a14c93959d46d352e9c40f45f117c to your computer and use it in GitHub Desktop.
Save iamricks/455a14c93959d46d352e9c40f45f117c to your computer and use it in GitHub Desktop.
Walmart API multipart feed submission in ruby
# Submits a feed to Walmart
# @param feed_data [Hash] data that will be submited with the feed
# @param type [String] Enum: "item" "RETIRE_ITEM" "MP_ITEM" "MP_WFS_ITEM" "MP_ITEM_MATCH" "MP_MAINTENANCE" "SKU_TEMPLATE_MAP" "SHIPPING_OVERRIDES"
def submit_feed(feed_data, type)
# To add a param to a multipart POST request you need to append the params to the URL
endpoint = "https://marketplace.walmartapis.com/v3/feeds?feedType=" + type
headers = self.api_client.headers.with_indifferent_access
uri = URI(endpoint)
request = Net::HTTP::Post.new(uri)
# Add Required Headers
request['Authorization'] = headers["Authorization"]
request['WM_SEC.ACCESS_TOKEN'] = headers["WM_SEC.ACCESS_TOKEN"]
request['WM_QOS.CORRELATION_ID'] = headers["WM_QOS.CORRELATION_ID"]
request['WM_SVC.NAME'] = headers["WM_SVC.NAME"]
request['Accept'] = headers["Accept"]
# Set form wants an array of arrays, basically the first item is the key and the second the value
request.set_form([["file", feed_data.to_s]], 'multipart/form-data')
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
end
@iamricks
Copy link
Author

figured out if you are sending JSON this is the correct way to do it

    # Submits a feed to Walmart
    # @param feed_data [Hash] data that will be submited with the feed
    # @param type [String] Enum: "item" "RETIRE_ITEM" "MP_ITEM" "MP_WFS_ITEM" "MP_ITEM_MATCH" "MP_MAINTENANCE" "SKU_TEMPLATE_MAP" "SHIPPING_OVERRIDES" 
    def submit_feed(feed_data, type)
      # To add a param to a multipart POST request you need to append the params to the URL
      endpoint = "https://marketplace.walmartapis.com/v3/feeds?feedType=" + type

      uri = URI.parse(endpoint)
      http = Net::HTTP.new(uri.host, uri.port)
      http.use_ssl = true
      http.post(uri.path, feed_data, self.api_client.headers)
    end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment