API Procedures
Snoweaver provides a set of stored procedures and functions within each connection schema. These allow users to retrieve or update data or files via HTTP/REST requests.
Reference
REQUEST
(function)
Sends an HTTP/REST request with a JSON document or text as the body and returns the result as a JSON (Variant) object.
Arguments:
type (varchar) Default: “GET”
The type of the request. Valid values are “GET”, “POST”, “PUT”, “DELETE”, and “PATCH”.
endpoint (varchar) Default: “”
The endpoint of the request. This will be concatenated to the base URL of the connection schema to form the complete request URL.
parameters (variant, optional) Defaults: {}
A map of key-value pairs that will be added to the request URL as query parameters.
headers (variant, optional) Defaults: {}
A map of key-value pairs that will be added to the request headers.
body (variant:object or string, optional) Defaults: {}
The body of the request.
If the type is “POST”, “PUT”, or “PATCH”, the body should be a JSON object or a String.
Not required if the type is “GET” or “DELETE”.
preview (boolean, optional) Defaults: False
If true, the function will return the content of the HTTP request prepared for execution instead of executing the request.
Return Value: (variant:object)
{
"success": true,
"data": {
"status_code": (integer, status code of the response)
"headers": (json, headers of the response)
"payload": (json|text, body of the response)
}
}
or
{
"success": false,
"data": "error message."
}
or
{
"success": true,
"data": "content of the HTTP request prepared for execution"
}
REQUEST
(procedure)
This procedure facilitates file uploads and downloads in conjunction with HTTP/REST requests.
Uploading: Sends an HTTP/REST request, using a file from the DATA stage as the request body. The function returns the result of the request as a JSON (Variant) object.
Downloading: Sends an HTTP/REST request and stores the downloaded file in the DATA stage. The function returns the relative path to the downloaded file.
Arguments:
type (varchar) Default: “GET”
The type of the request. Valid values are “GET”, “POST”, “PUT”, “DELETE”, and “PATCH”.
endpoint (varchar) Default: “”
The endpoint of the request. This will be concatenated to the base URL of the connection schema to form the complete request URL.
parameters (variant, optional) Defaults: {}
A map of key-value pairs that will be added to the request URL as query parameters.
headers (variant, optional) Defaults: {}
A map of key-value pairs that will be added to the request headers.
filepath (varchar) Defaults: “”
The relative path to the file within the DATA stage.
For uploads, this is the file to be sent as the request body.
For downloads, it’s where the response will be saved. For example, if the path is /dir1/file.csv, the full path will be @DATA/dir1/file.csv.
compress_decompress (boolean, optional) Defaults: True
If true, the file will be compressed before uploading or decompressed after downloading from the DATA stage.
parallel (integer, optional) Defaults: 4
The number of threads to use for file transfers to or from the DATA stage.
overwrite (boolean, optional) Defaults: True
Specifies whether Snowflake should overwrite existing files with the same name during the upload process.
Not required for downloading files.
preview (boolean, optional) Defaults: False
If true, the function will return the content of the HTTP request prepared for execution instead of executing the request.
Return Value: (variant:object)
{
"success": true,
"data": {
"status_code": (integer, status code of the response)
"headers": (json, headers of the response)
"payload": (json|text, relative path of the file for downloading or body of the request for uploading)
}
}
or
{
"success": false,
"data": "error message."
}
or
{
"success": true,
"data": "content of the HTTP request prepared for execution"
}