Adding custom fields - 401 authorisation error - support pointed me here

Hi, I am integrating ServiceM8 with BUZ and (long story) need to hold the GUID of a BUZ lead created via Power Automate/Zapier back in the serviceM8 quote job.

I have successfully created a note with the full URL of the Buz job in ServiceM8 and my users can right click on the link and jump to BUZ.

Due to limitations in BUZ I need to pull the GUID field from the note - I can get all notes but cannot use an odata contains to limit the number of notes I get back. As the system matures, the number of notes will grow.

So next step is to look at creating a custom field on the quote job itself in Servicem8. However I have run into the 401 not authorised issue - and looking at the forum many people have the same issue - but it has never been answered.

I logged a case with servicem8 and they offered to create up to 10 custom fields for $140. I wrote back asking if I could update the custom fields using basic authentication via the job modify rest end point. (Obviously if I can’t update the value in the field I have just spent $140 for nothing. They have referred me to this forum!!!

If I added a field called BUZGUID to the job entity could I via the rest endpoint (https://api.servicem8.com/api_1.0/job/{uuid}.json} just include

{
“BUZGUID”:“970628f2-be1f-4718-916a-0fbd3d6a5a5b”
}

And later via a retrieve job rest call use a $filter such as

BUZGUID eq “970628f2-be1f-4718-916a-0fbd3d6a5a5b”

Hi Stan

You can store the BUZ GUID in a ServiceM8 Custom Field and update it via the normal Job REST endpoint, but it won’t be a top-level field named BUZGUID and you’ll need to use the customfield_ prefix.

Why you’re hitting 401 when trying to add custom fields
The Custom Fields API is Public Applications only, so you’ll need to implement OAuth 2.0 and use an access token to create custom fields via /custom_fields_1.0.

If you’re authenticating as a private integration, the REST API uses an API key sent in the X-API-Key header.

How to write the GUID to the Job once the field exists
Once a Custom Field exists, it becomes available on the REST API as customfield_{field_name}, and you can read/write it via the standard REST API.

So if your custom field is created with field_name = buzguid, you’d update the job like this:

POST https://api.servicem8.com/api_1.0/job/{uuid}.json

{
“customfield_buzguid”: “970628f2-be1f-4718-916a-0fbd3d6a5a5b”
}

(If you’re using OAuth instead of an API key, the Job update endpoint requires the manage_jobs scope.)

Filtering by the GUID
ServiceM8 filtering uses the format ?$filter={field} {operator} {value}.

String values need to be wrapped in single quotes (not double quotes), so you’d try something like:

/api_1.0/job.json?$filter=customfield_buzguid eq ‘970628f2-be1f-4718-916a-0fbd3d6a5a5b’

The documented filter operators are eq, ne, gt, and lt (so functions like contains aren’t listed as supported in the REST filter syntax).

If you’re still getting a 401 after switching to X-API-Key (or OAuth access tokens), email support@servicem8.com with a copy of the request and response (with credentials removed) so we can confirm what’s failing authentication.

Thanks,
Cody

Thank you Cody - very clear and concise.

Stan