Created
July 29, 2021 20:41
-
-
Save iamricks/455a14c93959d46d352e9c40f45f117c to your computer and use it in GitHub Desktop.
Walmart API multipart feed submission in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
figured out if you are sending JSON this is the correct way to do it