HomeWiki
HomeWiki
  1. Web Requests
  • Back to home
  • 2. Connectivity
  • Introduction
  • Custom Script
  • Playground
  • Database Explorer
  • Log Stream
  • Direct Communication
  • Softone
    • Getting Started
  • Datapump
    • Getting Started
    • Crons
    • Legacy Windows Support
    • SDK
      • DB
        • _executeQuery
        • _executeStoreProcedure
        • _executeInsertQuery
        • _executeInsertQueriesInTransaction
      • Import
        • _productsImport
        • _categoriesImport
        • _brandsImport
        • _attributesImport
        • _attributeSetsImport
        • _unitsImport
        • _quantityImport
        • _customersImport
        • _contactsImport
        • _callsImport
        • _eventsImport
        • _tasksImport
        • _ordersImport
        • _usersImport
        • _customerSourceTagsImport
        • _productSourceTagsImport
      • Log
        • _logDebug
        • _logInfo
        • _logWarn
        • _logError
      • Web Requests
        • _httpGetJson
        • _httpPostJson
        • _httpPutJson
        • _httpDeleteJson
        • _httpPatchJson
      • Variables
        • _saveVariable
        • _getVariable
        • _deleteVariable
      • Blob
        • _blobConnect
        • _blobExists
        • _blobGet
        • _blobFind
      • Utils
        • _encodeBase64
        • _sleep
        • _getLastSyncDate
        • _updateLastSyncDate
        • _resetLastSyncDate
  1. Web Requests

_httpPatchJson

Documentation: _httpPatchJson Function#

The _httpPatchJson function is designed to perform an HTTP PATCH request to a specified URL. It allows for the inclusion of custom headers and payload data, with support for different encoding formats. The function returns the HTTP status code and the content of the response.

Function Signature:#

Parameters:#

url (Required):
Description: The URL to which the PATCH request is sent. This should be a valid URL pointing to the resource or API endpoint that will handle the patch operation.
Type: String
Example:
headers (Required):
Description: An object containing key-value pairs representing the headers to be included in the PATCH request. These headers can be used for authorization, content type, or any other required metadata.
Type: Object
Example:
payload (Required):
Description: The data to be sent in the body of the PATCH request. This should be an object or data structure that contains the updates to be applied to the resource.
Type: Object
Example:
encoding (Optional):
Description: The encoding format used to decode the response content. If not provided, the default encoding is utf-8. This can be useful when dealing with different character encodings.
Type: String
Default: 'utf-8'
Example:

Return Value:#

Returns:
A JSON object containing the HTTP status code and the content of the response. The object includes:
StatusCode: The HTTP status code returned by the server.
Content: The body of the response, typically a JSON object or string, depending on the response format.
Type: Object
Example:

Function Workflow:#

1.
Validate Input:
The function checks if the url, headers, and payload are provided and valid. If any of these are missing or invalid, the function may raise an error or abort the operation.
2.
Prepare HTTP Request:
The function creates an HTTP client and prepares the PATCH request with the specified url.
It sets the request headers using the headers object, which typically includes Authorization tokens and Content-Type.
3.
Send HTTP Request:
The function sends the PATCH request to the specified url with the payload included in the request body.
4.
Handle Response:
The function checks the response status code. If the response is successful (e.g., status code 200), it reads the response content.
The content is decoded using the specified encoding and parsed as JSON if applicable.
5.
Return JSON Object:
The function constructs a JSON object containing the StatusCode and the Content of the response. This JSON object is returned to the caller.
6.
Exception Handling:
If any exception occurs during the request (e.g., network errors, invalid JSON), the function may log the error and return an appropriate response object with an error status code.

Example Usage:#

Important Considerations:#

Ensure URL Validity:
The url parameter must be a valid and reachable URL. If the URL is incorrect or unreachable, the function may return an error or an unsuccessful status code.
Include Necessary Headers:
The headers object should include all necessary headers, such as authorization tokens and content types.
Handle Different Encodings:
If the response content uses a different encoding format, specify the correct encoding in the encoding parameter to ensure proper handling.
By using _httpPatchJson, you can efficiently update resources on APIs and other endpoints while managing custom headers and payload data. The function simplifies the process of making PATCH requests and handling responses in your application.
Previous
_httpDeleteJson
Next
_saveVariable
Built with