I have a use case where I will be needing to post data to a wordpress site. Specifically to a custom post type with a bunch of ACF fields.
I have setup trigger event correctly for Tookan and can receive data from the webhook.
In order to post the data to the site I am needing to use a custom function.
I setup the function as a map with parameters passed in as string values for all the values returned from the Tookan webhook.
Here is my current code:
map Tookan_ReportAutomation(
string tracking_link,
string total_time_spent_at_task_till_completion,
string job_address,
string total_distance,
string order_id,
string customer_id,
string customer_email,
string acknowledged_datetime,
string arrived_datetime,
string started_datetime,
string completed_datetime,
string job_time,string timezone,
string fleet_name,
string fleet_email,
string fleet_phone,
string fleet_id,
string CAR_DETAILS,
string SERVICE_DETAILS,
string LABOUR_CHARGED,
string MECHANIC_EARNINGS,
string CAR_LICENSE_DISC,
string MILEAGE,
string DASH,
string WARNING_LIGHTS,
string DIAGNOSTIC_MACHINE_OUTPUT,
string BRAKES_TYRES,
string FRONT_BRAKE_PADS,
string REAR_BRAKE_PADS_SHOES,
string FRONT_DISCS,
string REAR_DISCS,
string BRAKE_CALIPERS,
string FRONT_TYRES,
string REAR_TYRES,
string SPARE_TYRES,
string JACK_TOOLS,
string FLUIDS,
string ENGINE_OIL,
string TRANSMISSION_OIL,
string BRAKE_FLUID,
string COOLANT,
string ENGINE_BATTERY,
string ENGINE_OIL_LEAKS,
string TRANSMISSION_OIL_LEAKS,
string OTHER_LEAKS,
string DRIVE_BELT_CONDITION,
string FAN_WORKING,
string SPARK_GLOW_PLUGS,
string BATTERY_CORROSION,
string BATTERY_CASE_LEAKS,
string BATTERY_LOAD_TEST,
string BATTERY_VOLTAGE,
string LIGHTS,
string INDICATOR_LIGHTS,
string REVERSE_LIGHTS,
string HEADLIGHTS,
string OTHER_LIGHTS,
string SUSPENSION,
string SHOCKS_STRUT_CONDITION,
string BALL_JOINTS,
string CV_JOINT_AXLE,
string WHEEL_BEARINGS,
string WINDSHIELD_WINDOWS,
string WINDSHIELD_WINDOW_CONDITION,
string WINDSHIELD_WIPERS_OPERATIONAL,
string WINDSHIELD_WIPER_BLADE_CONDITION,
string WASHER_SYSTEM,
string AC,
string AC_BELT_CONDITION,
string AC_AIRFLOW,
string DOORS_MIRRORS,
string DOOR_CONDITION,
string MIRROR_CONDITION,
string TEST_DRIVE,
string STARTER_OPERATIONAL,
string SPEEDOMETER_OPERATIONAL,
string ENGINE_SOUNDS_NORMAL,
string GEARS_CHANGE_SMOOTHLY,
string BRAKES_SOLID_FIRM,
string STEERING_VIBRATES_WHEN_BRAKES_APPLIED,
string SUSPENSION_IS_SMOOTH,
string INDICATOR_CANCELS_AUTOMATICALLY,
string HANDBRAKE_HOLDS_FIRM,
string HANDBRAKE_LIGHT_ON_WHEN_SET,
string OTHER,
string SEATBELTS,
string HOOTER,
string REMOTE_KEYS,
string DOOR_LOCKS,
string ANTENNA,
string EXHAUST_SYSTEM_CONDITION,
string FEEDBACK_ON_ISSUES,
string PARTS_REQUIRED
){
// Define your authentication credentials using Map()
const authCredentials = Map();
authCredentials.put("username", “my-email”);
authCredentials.put("password", "my-password");
// Step 1: Authenticate and get the token
const authResponse = postUrl(https://my-domain/wp-json/jwt-auth/v1/token, authCredentials);
const authToken = authResponse.token; // Assuming your response structure provides the token
// Step 2: Construct the post data
const postData = Map();
postData.put("title", "New Report Title"); // Use a relevant title
postData.put("content", "Report content goes here."); // Use relevant content
postData.put("status", "publish");
// Define fields using Map() for ACF values
const fields = Map();
fields.put("field_1", CAR_DETAILS);
fields.put("field_2", DASH);
// ... (other ACF fields)
postData.put("fields", fields);
const headers = Map();
headers.put("Content-Type", "application/json");
headers.put("Authorization", "Bearer " + authToken); // Include the token in the headers
// Step 3: Make the POST request and capture the response
const response = postUrl(https://my-domain/wp-json/wp/v2/posts, postData, headers,false);
// Return the API response
return response;
}
I keep getting a syntax error though: Syntax error. Expecting
'throws','sendmail','sendsms','break',function call
statement,executeshellscript statement,'pushnotification',assignment statement
,'try','if','for',invokeurl statement,'return',invokeintegration
statement,'continue' or 'cancel'. Found 'authCredentials'. at line number 97.
Resolve the errors and try again
The same approach in a function in Zoho CRM works just fine and I can post to api endpoints but not from my custom function in Zoho Flow.
What am I missing? Any help would be super appreciated!
Writer is a powerful online word processor, designed for collaborative work.