Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7601765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:14:36+00:00 2026-05-30T23:14:36+00:00

I have an existing CFC that works fine when passing structures into the method.

  • 0

I have an existing CFC that works fine when passing structures into the method.

The problem is, we also now need to pass data into the same function via JSON.

Here is the CFC snippet:

<cffunction 
  name="subscribeAPI" 
  access="remote" 
  returntype="struct" 
  returnformat="json" 
  output="false">

  <cfargument 
    name="structure" 
    type="struct" 
    required="true" 
    hint="data structure received from call">

<cfif StructKeyExists(arguments.structure, "listID") 
  AND len(arguments.structure.listID)>
 ...
</cfif>

<cfreturn LOCAL />

Here is how we pass in the structure:

<cfset preStruct = {
  apiAction="Create",
  listID="1463",
  email="#form.cartEmail#",
  firstname="#form.first_name#",
  preCart="#now()#",
  planDescription="#application.name.site#"
  }
/>

<cfscript>voidReturn = application.goxObj.subscribeAPI(preStruct);</cfscript>

Now, we also need to pass in the following but are obviously getting errors due to the CFC expecting a structure:

function HandleSubscribe(){
  $j.getJSON(
    "/com/list.cfc?wsdl",
    {
      method : "subscribeAPI",
      action : "Create",
      listID : $j( "#listID" ).val(),
      triggerKey : $j( "#triggerKey" ).val(),
      email : $j( "#emailNL" ).val(),
      firstname : $j( "#firstnameNL" ).val()
    },
  handleSubscribeCallback
);

}

How can we successfully pass in the getJSON snippet?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T23:14:38+00:00Added an answer on May 30, 2026 at 11:14 pm

    JSON is just a string, so you need to “handle” the method call before it reaches your actual service layer.

    Danimal is right in that what you need to do is create a web service layer wrapper around your service.

    So your service method looks like this :

    <cffunction name="CreateSubscription" access="public" returntype="struct" output="false">
        <cfargument name="listID" required="true" type="numeric">
        <cfargument name="emailaddress" required="true" type="string">
        <cfargument name="firstname" required="true" type="string">
    
        <cfset var resultset = {success=false}>
    
        <!--- Validate your listid and subscription details --->
        <!--- If Valid Then insert subscription --->
        <cfset resultset.success = true>
    
        <!--- else --->
        <cfset resultset.message = 'kerboom!'>
    
        <!--- only return what you need as a struct, not the whole local scope! --->
        <cfreturn resultset />
     </cffunction>
    

    Your subscription API looks like this :

    <cffunction name="subscribeAPI" access="remote" returntype="struct" returnformat="json" output="false">
    
       <cfargument name="JSONPacket" type="string" required="true" hint="data structure received from call">
       <cfset var incomingData = deserializeJSON(arguments.JSONPacket)>
       <cfset var resultset = {success=false,message='invalid data'}>
    
       <cfif StructKeyExists(incomingData, "apiAction")>
           <cfif incomingData.apiAction EQ "create">
               <!--- You should also check you have the required fields for the createSubscription method here too. --->
               <cfset resultset = subscriptionService.createSubscription(incomingData)>
           </cfif>
       <cfelse>
           <cfset resultset.message = 'No API Action specified'>
       </cfif> 
    
       <cfreturn resultset>
    </cffunction>
    

    So you push the JSON at the subscribe API, which converts the data to a struct and makes sure you have all the right data available and passes it off to your subscription service. The createSubscription method in the subscription service checks to see if the listid exists and checks to see if the person is already subscribed. If the list is good and the subscription doesn’t exist, insert the new subscription into the database, otherwise return results that indicate what went wrong in a struct to your API layer, which converts it to JSON and returns it.

    The benefit to this is you can re-use the services in your application without having to go through the API layer and your api layer handles pushing the requests to the correct service methods and making sure that there is appropriate data available for them.

    Don’t be passing the local scope around! There can be a shed load of stuff in there including all the other methods in the service. Just return what is required and nothing more.

    There are other ways you can solve this that might be neater – for example you can actually put arguments into a method method call on a CFC from JSON. You could use cfajaxproxy to create the layer between your service and your javascript, enabling you to call your cfc methods directly as javascript functions. And I’m sure there are other solutions on top of these.

    Remember…. ColdFusion == Serverside, Javascript == clientside. Separate them. Put a layer between them to handle communications.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have existing java code and need to create Design Document based on that.
I have: existing object oriented native code API (non GUI) GUI application that works
i have existing code that generates a spreadsheet from excel using OpenXML. It works
I have an existing website that I need to develop a small portion of
I currently have existing code that automates and email and sends files. I now
I have existing code that uses CMNewProfileSearch to find then iterate over the color
For whatever reason, I have a lot of clients that have existing data that's
We have an existing WCF service that makes use of wsDualHttpBinding to enable callbacks
I have existing database and ADO Data services on top of it. Right now
I have existing chat server code written in C/C++ that communicates over TCP/IP with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.