Example #1
0
    def plenty_api_get_orders_by_date(self,
                                      start,
                                      end,
                                      date_type='create',
                                      additional=None,
                                      refine=None):
        """
            Get all orders within a specific date range.

            Parameter:
                start       [str]   -   Start date
                end         [str]   -   End date
                date_type   [str]   -   Specify the type of date
                                        {Creation, Change, Payment, Delivery}
                additional  [list]  -   Additional arguments for the query
                                        as specified in the manual
                refine      [dict]  -   Apply filters to the request
                                        Example:
                                        {'orderType': '1,4', referrerId: '1'}
                                        Restrict the request to order types:
                                            1 and 4 (sales orders and refund)
                                        And restrict it to only orders from
                                        the referrer with id '1'

            Return:
                [JSON(Dict) / DataFrame] <= self.data_format
        """

        date_range = utils.build_date_range(start=start, end=end)
        if not date_range:
            print(f"ERROR: Invalid range {start} -> {end}")

        if not utils.check_date_range(date_range=date_range):
            print(f"ERROR: {date_range['start']} -> {date_range['end']}")
            return {}

        query = utils.build_query_date(date_range=date_range,
                                       date_type=date_type)

        query = utils.sanity_check_parameter(domain='order',
                                             query=query,
                                             refine=refine,
                                             additional=additional)

        orders = self.__repeat_get_request_for_all_records(domain='orders',
                                                           query=query)

        orders = utils.transform_data_type(data=orders,
                                           data_format=self.data_format)

        return orders
Example #2
0
    def plenty_api_get_items(self,
                             refine: dict = None,
                             additional: list = None,
                             last_update: str = '',
                             lang: str = ''):
        """
            Get product data from PlentyMarkets.

            Parameter:
                refine      [dict]  -   Apply filters to the request
                                        Example:
                                        {'id': '12345', 'flagOne: '5'}
                additional  [list]  -   Add additional elements to the
                                        response data.
                                        Example:
                                        ['variations', 'itemImages']
                last_update [str]   -   Date of the last update given as one
                                        of the following formats:
                                            YYYY-MM-DDTHH:MM:SS+UTC-OFFSET
                                            YYYY-MM-DDTHH:MM
                                            YYYY-MM-DD
                lang        [str]   -   Provide the text within the data
                                        in one of the following languages:

                developers.plentymarkets.com/rest-doc/gettingstarted#countries

            Return:
                [JSON(Dict) / DataFrame] <= self.data_format
        """
        items = None
        query = {}

        query = utils.sanity_check_parameter(domain='item',
                                             query=query,
                                             refine=refine,
                                             additional=additional,
                                             lang=lang)

        if last_update:
            query.update(
                {'updatedBetween': utils.date_to_timestamp(date=last_update)})

        items = self.__repeat_get_request_for_all_records(domain='items',
                                                          query=query)

        items = utils.transform_data_type(data=items,
                                          data_format=self.data_format)
        return items
Example #3
0
    def plenty_api_get_price_configuration(self,
                                           minimal: bool = False,
                                           last_update: str = ''):
        """
            Fetch the price configuration from PlentyMarkets.

            Parameter:
                minimal     [bool]  -   reduce the response data to necessary
                                        IDs.
                last_update [str]   -   Date of the last update given as one
                                        of the following formats:
                                            YYYY-MM-DDTHH:MM:SS+UTC-OFFSET
                                            YYYY-MM-DDTHH:MM
                                            YYYY-MM-DD

            Result:
                [JSON(Dict) / DataFrame] <= self.data_format
        """
        prices = None
        minimal_prices: list = []
        query = {}

        if last_update:
            # The documentation refers to Unix timestamps being a valid
            # format, but that is not the case within my tests.
            query.update({'updatedAt': last_update})

        prices = self.__repeat_get_request_for_all_records(domain='prices',
                                                           query=query)

        if not prices:
            return None

        if minimal:
            for price in prices:
                minimal_prices.append(
                    utils.shrink_price_configuration(data=price))
            prices = minimal_prices

        prices = utils.transform_data_type(data=prices,
                                           data_format=self.data_format)
        return prices
Example #4
0
    def plenty_api_get_manufacturers(self,
                                     refine: dict = None,
                                     additional: list = None,
                                     last_update: str = ''):
        """
            Get a list of manufacturers (brands), which are setup on
            PlentyMarkets.

            Parameter:
                refine      [dict]  -   Apply a filter to the request
                                        The only viable option currently is:
                                        'name'
                additional  [list]  -   Add additional elements to the
                                        response data.
                                        Viable options currently:
                                        ['commisions', 'externals']
                last_update [str]   -   Date of the last update given as one
                                        of the following formats:
                                            YYYY-MM-DDTHH:MM:SS+UTC-OFFSET
                                            YYYY-MM-DDTHH:MM
                                            YYYY-MM-DD

            Return:
                [JSON(Dict) / DataFrame] <= self.data_format
        """
        manufacturers = None
        query = {}
        query = utils.sanity_check_parameter(domain='manufacturer',
                                             query=query,
                                             refine=refine,
                                             additional=additional)

        if last_update:
            query.update({'updatedAt': last_update})

        manufacturers = self.__repeat_get_request_for_all_records(
            domain='manufacturer', query=query)

        manufacturers = utils.transform_data_type(data=manufacturers,
                                                  data_format=self.data_format)
        return manufacturers
Example #5
0
    def plenty_api_get_variations(self,
                                  refine: dict = None,
                                  additional: list = None,
                                  lang: str = ''):
        """
            Get product data from PlentyMarkets.

            Parameter:
                refine      [dict]  -   Apply filters to the request
                                        Example:
                                        {'id': '2345', 'flagOne: '5'}
                additional  [list]  -   Add additional elements to the
                                        response data.
                                        Example:
                                        ['stock', 'images']
                lang        [str]   -   Provide the text within the data
                                        in one of the following languages:
                                        Example: 'de', 'en', etc.

                developers.plentymarkets.com/rest-doc/gettingstarted#countries

            Return:
                [JSON(Dict) / DataFrame] <= self.data_format
        """
        variations = None
        query = {}

        query = utils.sanity_check_parameter(domain='variation',
                                             query=query,
                                             refine=refine,
                                             additional=additional,
                                             lang=lang)

        variations = self.__repeat_get_request_for_all_records(
            domain='variations', query=query)

        variations = utils.transform_data_type(data=variations,
                                               data_format=self.data_format)
        return variations
Example #6
0
    def plenty_api_get_referrers(self, column: str = ''):
        """
            Get a list of order referrers from PlentyMarkets.

            The description within the PlentyMarkets API documentation
            is just wrong, the parameter doesn't expect an integer nor a
            list of integers, it actually cannot query multiple columns.
            All the parameter can query is a "single" column, which
            is why I renamed the parameter in this method.

            Parameter:
                column      [str]   -   Name of the field from the referrer
                                        to be exported.

            Return:
                [JSON(Dict) / DataFrame] <= self.data_format
        """
        # TODO actually only backendName, id and name are actually useful
        # because all other attributes are useless without identification
        valid_columns = [
            'backendName', 'id', 'isEditable', 'isFilterable', 'name',
            'orderOwnderId', 'origin'
        ]
        referrers = None
        query = {}
        if column in valid_columns:
            query = {'columns': column}
        else:
            print(f"Invalid column argument removed: {column}")

        # This request doesn't export in form of pages
        referrers = self.__plenty_api_request(method='get',
                                              domain='referrer',
                                              query=query)

        referrers = utils.transform_data_type(data=referrers,
                                              data_format=self.data_format)

        return referrers
Example #7
0
    def plenty_api_get_vat_id_mappings(self, subset: List[int] = None):
        """
            Get a mapping of all VAT configuration IDs to each country or
            if specified for a subset of countries.
            A VAT configuration is a combination of country, vat rates,
            restrictions and date range.

            Parameter:
                subset      [list]  -   restrict the mappings to only
                                        the given IDs (integer)
                You can locate those IDs in your Plenty- Markets system under:
                Setup-> Orders-> Shipping-> Settings-> Countries of delivery

            Return:
                [JSON(Dict) / DataFrame] <= self.data_format
        """
        vat_data = self.__repeat_get_request_for_all_records(domain='vat',
                                                             query={})

        vat_table = utils.create_vat_mapping(data=vat_data, subset=subset)

        vat_table = utils.transform_data_type(data=vat_table,
                                              data_format=self.data_format)
        return vat_table
Example #8
0
    def plenty_api_get_attributes(self,
                                  additional: list = None,
                                  last_update: str = '',
                                  variation_map: bool = False):
        """
            List all attributes from PlentyMarkets, this will fetch the
            basic attribute structures, so if you require an attribute value
            use: additional=['values'].
            The option variation_map performs an additional request to
            /rest/items/variations in order to map variation IDs to
            attribute values.

            Parameter:
                additional  [list]  -   Add additional elements to the
                                        response data.
                                        Viable options:
                                        ['values', 'names', 'maps']
                last_update [str]   -   Date of the last update given as one
                                        of the following formats:
                                            YYYY-MM-DDTHH:MM:SS+UTC-OFFSET
                                            attributes-MM-DDTHH:MM
                                            YYYY-MM-DD
                variation_map [bool]-   Fetch all variations and add a list
                                        of variations, where the attribute
                                        value matches to the corresponding
                                        attribute value

            Return:
                [JSON(Dict) / DataFrame] <= self.data_format
        """
        attributes = None
        query = {}

        query = utils.sanity_check_parameter(domain='attribute',
                                             query=query,
                                             additional=additional)

        if last_update:
            query.update({'updatedAt': last_update})

        # variation_map was given but the required '&with=values' query is
        # missing, we assume the desired request was to be made with values
        if variation_map:
            if not additional:
                query.update({'with': 'values'})
            if additional:
                if 'values' not in additional:
                    query.update({'with': 'values'})

        attributes = self.__repeat_get_request_for_all_records(
            domain='attributes', query=query)

        if variation_map:
            variation = self.plenty_api_get_variations(
                additional=['variationAttributeValues'])
            attributes = utils.attribute_variation_mapping(
                variation=variation, attribute=attributes)

        attributes = utils.transform_data_type(data=attributes,
                                               data_format=self.data_format)

        return attributes