The Update Function API allows applications to update a registered function script. This includes updating the executable file or source code and modifying the function name or input schema.

Request Parameters

Public Request Parameters

📘

Public Request Parameters

Path Parameters

ParameterTypeRequiredDescription
function_idstringYesUnique ID of the function to update.

Body Parameters

ParameterTypeRequiredDescription
namespacestringYesNamespace of the function.
namestringYesFunction name.
filebinaryYesUpdated compiled .wasm file (optional).
source_codestringYesUpdated function source code (optional).

cURL Example

curl --location --request POST 'https://partners.shoplazza.com/openapi/2024-07/functions/${function_id}' \
--header 'Content-type:multipart/form-data' \
--header 'x-app-client-id:xxxx' \
--header 'X-Shoplazza-Access-Token:xxxx' \
--form 'namespace="cart-transform"' \
--form 'name="my-cart-transform-demo"' \
--form 'source_code="const input=readInput();const object=discountFunc(input);writeOutput(object);function readInput(){const chunkSize=1024;const inputChunks=[];let totalBytes=0;while(1){const buffer=new Uint8Array(chunkSize);const fd=0;const bytesRead=Javy.IO.readSync(fd,buffer);totalBytes+=bytesRead;if(bytesRead===0){break}inputChunks.push(buffer.subarray(0,bytesRead))}const{finalBuffer}=inputChunks.reduce((context,chunk)=>{context.finalBuffer.set(chunk,context.bufferOffset);context.bufferOffset+=chunk.length;return context},{bufferOffset:0,finalBuffer:new Uint8Array(totalBytes)});return JSON.parse(new TextDecoder().decode(finalBuffer))}function writeOutput(output){const encodedOutput=new TextEncoder().encode(JSON.stringify(output));const buffer=new Uint8Array(encodedOutput);const fd=1;Javy.IO.writeSync(fd,buffer)}function discountFunc(input){let config=input.discountNode?.metafield?.value;config=config?JSON.parse(config):null;let cartLines=input.cart.lines;if(!cartLines.length||!config||config.percentage===0){return{discounts:[],discountApplicationStrategy:'\''First'\''}}let targets=[];for(let line of cartLines){if(line.quantity>=config.quantity){targets.push({id:line.merchandise.id||'\'''\'',quantity:null})}}if(!targets.length){return{discounts:[],discountApplicationStrategy:'\''First'\''}}return{discounts:[{message:null,conditions:null,targets,value:{percentage:config.percentage}}],discountApplicationStrategy:'\''First'\''}}"' \
--form 'file=@"/Users/shoplazza/Desktop/go/functions-api/tests/build/rust_function.wasm"' 

Response Explanation

Public Response Parameters

📘

Public Response Parameters

Successful Response

ParameterTypeRequiredDescription
codestringYesStatus code (SUCCESS if successful, otherwise an error code).
messagestringYesResponse message.
dataobjectYesContains the updated function details.
data.function_idstringYesThe unique identifier of the function.
data.versionstringYesUpdated function version.

Error Response

FieldTypeDescriptionExample
codestringThe error code indicating the type of issue.InvalidParameter
messagestringA detailed message describing the error.wrong cursor
Language
Credentials
Click Try It! to start a request and see the response here!