Class: MuffinMan::Uploads::V20201101

Inherits:
SpApiClient show all
Defined in:
lib/muffin_man/uploads/v20201101.rb

Constant Summary

Constants inherited from SpApiClient

SpApiClient::ACCESS_TOKEN_URL, SpApiClient::AWS_REGION_MAP, SpApiClient::SERVICE_NAME, SpApiClient::UNPROCESSABLE_ENTITY_STATUS_CODE

Instance Attribute Summary

Attributes inherited from SpApiClient

#access_token_cache_key, #client_id, #client_secret, #config, #credentials, #local_var_path, #pii_data_elements, #query_params, #refresh_token, #region, #request_body, #request_type, #sandbox, #scope

Instance Method Summary collapse

Methods inherited from SpApiClient

#initialize, #request

Constructor Details

This class inherits a constructor from MuffinMan::SpApiClient

Instance Method Details

#create_upload_destination_for_resource(marketplace_id, resource, content_md5, content_type: nil) ⇒ Hash

Creates a new upload destination for a resource.

This method generates a signed upload destination URL for a specific resource that you can use to upload files to Amazon SP-API.

Examples:

client = MuffinMan::Uploads::V20201101.new
response = client.create_upload_destination_for_resource(
  "ATVPDKIKX0DER",
  "aplus/2020-11-01/contentDocuments",
  "510700ca1b152c729b62f2fd13c8dbbe",
  "application/pdf"
)
puts response

Parameters:

  • marketplace_id (String)

    The identifier of the marketplace for the request (e.g., ‘ATVPDKIKX0DER’).

  • resource (String)

    The resource type and path, such as:

    • ‘/messaging/v1/orders/amazonOrderId/messages/legalDisclosure`

    • ‘aplus/2020-11-01/contentDocuments`.

  • content_md5 (String)

    The MD5 hash of the file’s content. Use ‘Digest::MD5.file(file_path).hexdigest` to calculate this.

  • content_type (String) (defaults to: nil)

    (optional) The content type of the file (e.g., ‘application/pdf’).

Returns:

  • (Hash)

    The response from the API, which includes the signed upload URL and additional metadata.

Raises:

  • (StandardError)

    Raises an error if the API request fails.



35
36
37
38
39
40
41
42
# File 'lib/muffin_man/uploads/v20201101.rb', line 35

def create_upload_destination_for_resource(marketplace_id, resource, content_md5, content_type: nil)
  @local_var_path = "/uploads/2020-11-01/uploadDestinations/#{resource}"
  @query_params = { "marketplaceIds" => marketplace_id, "contentMD5" => content_md5 }
  @query_params["contentType"] = content_type if content_type
  @request_type = "POST"

  call_api
end