Amazon-CreatorsAPI

 view release on metacpan or  search on metacpan

lib/Amazon/CreatorsAPI.pm  view on Meta::CPAN


    my $res = $self->ua->request(
        'POST',
        $self->operation_endpoint . '/' . $operation,
        {
            'headers' => {
                'Authorization' => $self->_auth_header,
                'Content-Type' => 'application/json',
                'x-marketplace' => $self->marketplace,
            },
            'content' => $JSON->encode({
                partnerTag => $self->partner_tag,
                marketplace => $self->marketplace,
                %{$params},
            }),
        },
    );

    if (!$res->{success}) {
        croak "failed $operation status:$res->{status} "
            . ($res->{reason} || 'reason_unknown')
            . ", $res->{content}";
    }

    my $res_data = +{};
    eval {
        $res_data = $JSON->decode($res->{content});
    };
    if (my $e = $@) {
        croak "could not JSON decode, $e : " . $res->{content};
    }

    return $res_data;
}

sub _auth_header {
    my $self = shift;

    my $am = $self->auth_manager;
    my $token = $am->get_access_token;

    return "Bearer $token" . (
        !$am->is_lwa ? ', Version ' . $self->credential_version : ''
    );
}

1;

__END__

=encoding UTF-8

=head1 NAME

Amazon::CreatorsAPI - The Amazon Creators API Helper


=head1 SYNOPSIS

    use Amazon::CreatorsAPI;
    use Data::Dumper;

    my $api = Amazon::CreatorsAPI->new(
        "{credential_id}",
        "{credential_secret}",
        "{credential_version}",
        {
            partner_tag => "{partner_tag}",
            marketplace => '{www.amazon.com}',
        },
    );

    my $res = $api->search_items({
        keywords => "{search_keyword}",
        resources => [
            'itemInfo.title',
        ],
    });

    print Dumper($res);


=head1 DESCRIPTION

What is the Amazon Creators API?

https://affiliate-program.amazon.com/creatorsapi/docs/en-us/introduction

See B<example/> directory of this module.

L<https://github.com/bayashi/Amazon-CreatorsAPI/tree/main/example>


=head1 METHODS

=head2 new

constructor

=head2 get_browse_nodes($api_params)

=head2 get_items($api_params)

=head2 get_variations($api_params)

=head2 search_items($api_params)

=head2 operation($operation, $api_params)

C<operation> method is the low level interface to call Amazon Creators API for operations not yet wrapped by helper methods in this module.

Amazon Creator API Reference: https://affiliate-program.amazon.com/creatorsapi/docs/en-us/api-reference

Locale Reference: https://affiliate-program.amazon.com/creatorsapi/docs/en-us/locale-reference


=head1 REPOSITORY

=begin html

<a href="https://github.com/bayashi/Amazon-CreatorsAPI/blob/main/README.md"><img src="https://img.shields.io/badge/Version-0.01-green?style=flat"></a> <a href="https://github.com/bayashi/Amazon-CreatorsAPI/blob/main/LICENSE"><img src="https://img.shi...



( run in 0.540 second using v1.01-cache-2.11-cpan-39bf76dae61 )