Creating Your First Point
This guide will walk you through creating a code point using the example hello_world.js file. You will define a function, upload it as a code point, and execute it. Be sure to replace placeholders with your actual values.
Step 1: Define the Function
Create a JavaScript file named hello_world.js and define the execute_process function as follows. This function will make a REST API call to https://example.com and return whether or not it was successful.
// hello_world.js
const fetch = require('node-fetch'); // Ensure node-fetch is available
async function execute_process() {
try {
const response = await fetch('https://example.com');
const success = response.ok;
console.log("Hello World");
return {
said_hello: true,
api_call_successful: success // Return the success status of the API call
};
} catch (error) {
console.error('API call failed:', error);
return {
said_hello: true,
api_call_successful: false // Indicate the API call failed
};
}
}
Step 2: Upload the Code Point
Use the following curl command to upload hello_world.js as the code to a new point. Be sure to update the domain, apiKey, and organization_id with your actual values.
curl --request POST \
--url https://<domain>.melodyarc.app/api/v1/code \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-api-key: <<apiKey>>' \
--data '{
"version": "latest",
"language": "javascript",
"organization_id": "org_abc123",
"name": "hello_world",
"code": "'"$(<hello_world.js)"'",
"tags": [
"test"
]
}'
Step 3: Execute the Code Point
Execute the point you created and review the logs and output. Use the following curl command, updating the domain, apiKey, and organization_id with your actual values.
curl --request POST \
--url https://<domain>.melodyarc.app/api/v1/test \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-api-key: <<apiKey>>' \
--data '{
"type": "code",
"organization_id": "org_abc123",
"token": {},
"point": "hello_world"
}'
Updated 2 months ago