_:n99262556f451480b83194563a9b9a73fxb2
<http://schema.org/text>
"For CFML Programmers who end up here looking for that kick to get you rolling, here’s a short intro, written CFML’er to CFML’er.In your Application.cfc/cfm or other page that loads with every refresh, you need to identify who you are with something like this:&lt;script async type=\"text/javascript\"src=\"//static.klaviyo.com/onsite/js/klaviyo.js?company_id=#Klaviyo_Public_API_Key#\"&gt;&lt;/script&gt;Of course, you would have your Public and Private API keys from Klaviyo generated and variable-ized. We determine if we’re running this in test or production and load those variables accordingly.Then you can write a CFHTTP call to manage the information. Remember, you can use CFHTTP to POST, GET, and PATCH. Pay attention to the Klaviyo docs as to which to use for what operation. Their docs also let you start filling out the call so you can see which URL to use by using the drop-downs and inputs on that page(example:https://developers.klaviyo.com/en/reference/get_profile)I found it easiest to put the functions I need into a CFML component, and then, after creating an object from the component, it became quite easy to get what I needed with a more familiar interface.For instance, here’s the component function to retrieve a profile -- This may or may not be the most efficient way to write this, but this will at least give you the kick in the pants to move ahead with more confidence.NOTE THAT we store our profiles with our Company ID so I am using that as my “filter” term in my request for the profile. Oh -- and the revision (see below) is needed by Klaviyo to know which version of the API you’re basing this request on. All this information is in their documents, but it’s scattered far and wide with nothing put in one nice example package to give you a clue on how it all fits together, as far as I could see.  &lt;!--- ****** Get One Klaviyo Profile ****** ---&gt;  &lt;cffunction name=\"get_Klaviyo_Profile\" returnType=\"struct\" access=\"public\"      displayName=\"Get One Klaviyo Profile\"      description = \"I return a structure containing the Klaviyo profile for one person based on Customer ID number.\"&gt;    &lt;cfargument name=\"KlaviyoPrivateAPI\" type=\"string\" required=\"yes\" displayname=\"Klaviyo Private API\"&gt;    &lt;cfargument name=\"customer_id\"  type=\"numeric\" required=\"yes\" displayname=\"Customer ID\"&gt;    &lt;cfset VAR myResult = structNew() /&gt;    &lt;cfhttp method=\"get\"      charset=\"utf-8\"      url=\"https://a.klaviyo.com/api/profiles/?filter=equals(external_id,'#ARGUMENTS.customer_id#')\"      result=\"klaviyoSelectFieldsFilteredProfile\"      resolveurl=\"yes\"&gt;      &lt;cfhttpparam type=\"header\" name=\"Authorization\" value=\"Klaviyo-API-Key #ARGUMENTS.KlaviyoPRivateAPI#\"&gt;      &lt;cfhttpparam type=\"header\" name=\"revision\" value=\"2023-01-24\"&gt;      &lt;cfhttpparam type=\"header\" name=\"Accept\" value=\"application/json\"&gt;      &lt;cfhttpparam type=\"header\" name=\"Content-Type\" value=\"application/json\"&gt;    &lt;/cfhttp&gt;    &lt;cfset kResult = deserializejson(klaviyoSelectFieldsFilteredProfile.filecontent) /&gt;    &lt;cfset myResult.Klaviyo_Profile_ID = kResult['data'][1]['id'] /&gt;    &lt;cfset myResult.first_name = kResult['data'][1]['attributes']['first_name'] /&gt;    &lt;cfset myResult.last_name = kResult['data'][1]['attributes']['last_name'] /&gt;    &lt;cfset myResult.email = kResult['data'][1]['attributes']['email'] /&gt;    &lt;cfset myResult.customer_id = kResult['data'][1]['attributes']['external_id'] /&gt;    &lt;cfset myResult.phone_number = kResult['data'][1]['attributes']['phone_number'] /&gt;    &lt;cfset myResult.anonymous_id = kResult['data'][1]['attributes']['anonymous_id'] /&gt;    &lt;cfset myResult.organization = kResult['data'][1]['attributes']['organization'] /&gt;    &lt;cfset myResult.title = kResult['data'][1]['attributes']['title'] /&gt;    &lt;cfset myResult.image = kResult['data'][1]['attributes']['image'] /&gt;    &lt;cfset myResult.address1 = kResult['data'][1]['attributes']['location']['address1'] /&gt;    &lt;cfset myResult.address2 = kResult['data'][1]['attributes']['location']['address2'] /&gt;    &lt;cfset myResult.city = kResult['data'][1]['attributes']['location']['city'] /&gt;    &lt;cfset myResult.country = kResult['data'][1]['attributes']['location']['country'] /&gt;    &lt;cfset myResult.latitude = kResult['data'][1]['attributes']['location']['latitude'] /&gt;    &lt;cfset myResult.region = kResult['data'][1]['attributes']['location']['region'] /&gt;    &lt;cfset myResult.zip = kResult['data'][1]['attributes']['location']['zip'] /&gt;    &lt;cfset myResult.timezone = kResult['data'][1]['attributes']['location']['timezone'] /&gt;    &lt;cfreturn myResult /&gt;  &lt;/cffunction&gt;So once you have this in a component (for example “oKlaviyoFunctions”, e.g. oKlaviyoFunctions  = CreateObject(\"component\",\"components.klaviyo\")), you can retrieve your results by a simple function call, such as:    structProfile=oKlaviyoFunctions.get_Klaviyo_Profile(customer_id=\"123456\",KlaviyoPrivateAPI=\"#Klaviyo_Private_API_Key#\");    WriteDump(var='#structProfile#');I hope this helps to reduce the hair pulling and gnashing of teeth for you. It would have zoomed me to the productivity line much more quickly."
<https://community.klaviyo.com/integrations-and-reviews-39/cfml-assistance-requested-7067>