Discussions

Ask a Question
Back to all

Webhook Not working

Hi there,

I hope you're doing well.

I’ve created a webhook using a custom Lambda-based add-on. I've also prepared a manifest.json file (included below), and implemented the webhook callback function to process incoming events.

However, the webhook doesn't appear to be triggering as expected. I referred to the sample webhook add-ons provided in the addon-sdk GitHub repository while building this.

I've attached the relevant code and configuration. Could you please review and guide me on what might be missing or misconfigured?

Thank you in advance for your support.

Best regards,
Rajinder Dhiman


{
"name": "YesM8 Payment Info Staging",
"version": "1.0",
"iconURL": "https://staging.jobinfoapi.yesm8australia.com.au/assets/img/yesm8_jobinfo_icon.png",
"supportURL": "http://yesm8australia.com.au/",
"supportEmail": "jrmdevelopements@gmail.com",
"oauth": {
"scope": "publish_email manage_jobs manage_attachments read_job_contacts read_job_attachments publish_job_attachments read_jobs read_customer_contacts read_job_materials read_customers read_schedule read_inventory read_staff vendor publish_job_notes read_job_contacts"
},
"actions": [


],
"menuItems": [  

],
"webhooks": [
	{
		"object": "job",
		"fields": [  
					 "uuid",  
					"job_address",  
					"billing_address"  
				]

	}
]
```}

=====================================================

<br />

exports.handler = async (event, context, callback) => {  
  try {  
    switch (event.eventName) {  
      case "yesm8_add_jobinfo_event_online_staging":  
        return callback(null, {  
          eventResponse: await wrap_jobinfo_online_callback_staging(event),  
        });  
      case "yesm8_add_jobinfo_event_app_staging":  
        return callback(null, {  
          eventResponse: await wrap_jobinfo_app_callback_staging(event),  
        });  
      case "yesm8_add_staff_jobinfo_event_online_staging":  
        return callback(null, {  
          eventResponse: await wrap_staff_jobinfo_online_callback_staging(event),  
        });  
      // case "yesm8_scripting_event_staging":  
      //   return callback(null, {  
      //     eventResponse: await wrap_scripting_callback_staging(event),  
      //   });  
      case "yesm8_jobinforeporting_event_staging":  
        return callback(null, {  
          eventResponse: await wrap_jobinfo_report_callback_staging(event),  
        });  
      case "filter_jobinfo_event_staging":  
        return callback(null, {  
          eventResponse: await wrap_filter_jobinfo_callback_staging(event),  
        });  
      case "webhook_subscription":  
        return callback(null, { result:  await webhook_subscription_staging(event)} );  
      default:  
        return callback(null, { error: "Invalid event name" });  
    }  
  } catch (error) {

return callback(null, {
statusCode: 500,
body: JSON.stringify({ error: error.message || "Unhandled error" }),
});


  }  
};

<br />

async function webhook_subscription_staging(event) {  
  const token = event.auth.accessToken;

  const options = {  
    method: 'POST',  
    url: '<https://api.servicem8.com/platform_service_email'>,  
    headers: {  
      'Content-Type': 'application/json',  
      'Authorization': `Bearer ${token}`  
    },  
    body: JSON.stringify({  
      "to": "[jrmdevelopements@gmail.com](mailto:jrmdevelopements@gmail.com)",  
      "subject": "test",  
      "htmlBody": "<p>This is a <strong>test</strong> email.</p>",  
      "textBody": "This is a test email."  
    })  
  };

  request(options, function (error, response, body) {  
    if (error) throw new Error(error);  
    return "successfull email";  
  });

// };
// request(options, function (error, response) {
// if (error) throw new Error(error);
// console.log(response.body);
// });


}