Documentation: _usersImport
Function#
The _usersImport
function is designed to import a batch of user data into the Shopranos platform. It handles authentication, sends a POST request with the user data to the Shopranos API, and processes the response and potential errors. The function returns a structured result indicating the outcome of the import operation.Function Signature:#
Parameters:#
payload
(Array of users):Description: An array of user objects to be sent in the POST request body. Each object should represent a user with their relevant details. This data is used by the Shopranos platform to process the import operation.
Return Value:#
A JSON object containing the result of the HTTP POST request to the Shopranos platform. The object includes:StatusCode
: The HTTP status code of the response from the Shopranos platform.
Content
: The content of the response body from the Shopranos platform, typically containing success or error messages.
Function Workflow:#
1.
The function retrieves a certificate required for authentication. If the certificate cannot be obtained, it logs an error and returns a JSON object indicating "NO CERTIFICATE".
2.
It then retrieves an access token for authorization. If the token is not available or is empty, it logs an error and returns a JSON object indicating "NO TOKEN".
3.
Prepare and Send HTTP Request:The function creates an HTTP client and configures it with the access token and base address for the Shopranos platform.
It sets the request headers, including the Authorization
header with the Bearer token and x-companyid
header with the company ID from the certificate.
The payload
is converted to a JSON string and sent in the request body.
4.
The function sends the POST request to the specified URL and checks if the response is successful. If not, it logs an error with the status code.
It reads the response content and logs it for debugging purposes.
It then constructs a JSON object with the StatusCode
and Content
from the response.
5.
If any exception occurs during the process, it logs the exception message and returns a JSON object with StatusCode
set to "EXCEPTION" and the exception message as the Content
.
Example Usage:#
Important Considerations:#
Ensure proper handling of cases where the certificate or token cannot be retrieved. The function handles these errors by returning appropriate messages.
The payload
parameter must be an array of user objects formatted according to the Shopranos API requirements.
The HTTP client has a timeout of 120 seconds. Ensure that this is sufficient for the Shopranos platform to process the request.
By using _usersImport
, you can automate the import of user data into the Shopranos platform, ensuring that the data is sent securely and that any issues are handled and reported appropriately.Modified at 2024-08-23 11:45:15