ProductOpener::API - implementation of READ and WRITE APIs
This module contains functions that are common to multiple types of API requests.
Specialized functions to process each type of API request is in separate modules like:
APIProductRead.pm : product READ APIProductWrite.pm : product WRITE
Add an error to the response object.
Reference to the response object.
Reference to the error object.
HTTP status code to return in the response, defaults to 400 bad request.
API V3 POST / PUT / PATCH requests do not use CGI Multipart Form data, and instead pass a JSON structure in the body. This function reads the request body and saves it in $request_ref->{body}
It must be called before any call to CGI.pm param() which will read the body.
Reference to the request object.
Decodes the JSON body of a request and store it in $request_ref->{request_body_json}
Errors are returned in $request_ref->{api_response}
Reference to the request object.
Based on the response's errors and warnings, determine the overall status of the request.
Reference to the response object.
Functions that process API calls may add message ids in $request_ref->{api_response} to indicate the result and warnings and errors.
This functions adds English and/or localized messages for those messages.
API messages (result, warning and errors messages and impacts) are generated: - in English in the "name" field: those messages are intended for use by developers, monitoring systems etc. - in the language of the user in the "lc_name" field: those messages may be displayed directly to users (e.g. to explain that some field values are incorrect and were ignored)
Reference to the response object.
Send the API response with the right headers and status code.
Reference to the request object.
Reference to the customized product object.
Process API v3 requests.
Reference to the request object.
Normalize the product barcode requested by a READ or WRITE API request. Return a warning if the normalized code is different from the requested code.
Reference to the request object.
Reference to the response object.
Normalized code and, if available, GS1 AI data string.
Return a list of images that are too old, or that are missing. This is used to ask users to update images.
Reference to the product object
Target language code
Reference to a hash of images that need to be updated. The keys are the image ids (e.g. front_fr), and the value is the age in seconds of the image (or 0 if we don't have an image yet)
Packaging components are stored in a compact form: only taxonomy ids for shape, material and recycling.
This function returns a richer structure with local names for the taxonomy entries.
Reference to the request object.
Reference to the product object (retrieved from disk or from a MongoDB query)
Reference to the customized product object.
Using the fields parameter, API product or search queries can request a specific set of fields to be returned.
This function filters the field to return only the requested fields, and computes requested fields that are not stored in the database but created on demand.
Reference to the request object.
Reference to the product object (retrieved from disk or from a MongoDB query)
Comma separated list of fields (usually from GET query parameters), default to none.
Special values: - none: no fields are returned - all: all fields are returned, and special fields (e.g. attributes, knowledge panels) are not computed - updated: fields that were updated by a WRITE request
Reference to a list of fields (alternative way to provide fields, e.g. from a JSON body).
Reference to the customized product object.
Check the user has a specific permission, before processing an API request. If the user does not have the permission, an error is added to the response.
Reference to the request object.
Reference to the response object.
Permission to check.
1 if the user has the permission, 0 otherwise.