Skip to main content
Inspiring
May 13, 2025
Answered

Move API Call from jQuery to the Back End

  • May 13, 2025
  • 1 reply
  • 367 views

I currently have a jQuery ajax call to a third-party API, which checks a vehicle's licence plate against a national database:

 

$.ajax({
    type: "get",
    url: "https://test.carjam.co.nz/a/vehicle:abcd", 
    data: {key:key,plate:plate},
    dataType: "json",
    success: function(res){
        // display message validating license plate and save response data into database
    }
    // other code
});			

However, the third party now requires the call to be from the "back end", as any attempts to use browser code such as JS or juery will result in a "cross-origin" related error.

 

What would be the most effective way to bring this into the back-end? Via a cfc?

They also give the option of using node.js, which I know nothing about.

    Correct answer Dave Watts

    This should be pretty easy with CFHTTP whether you use a CFC for it or not. This is kind of an old-school response, but it should get you started:

     

    https://stackoverflow.com/questions/58090695/trying-to-convert-json-http-post-to-cfhttp-post

     

    1 reply

    Dave WattsCommunity ExpertCorrect answer
    Community Expert
    May 14, 2025

    This should be pretty easy with CFHTTP whether you use a CFC for it or not. This is kind of an old-school response, but it should get you started:

     

    https://stackoverflow.com/questions/58090695/trying-to-convert-json-http-post-to-cfhttp-post

     

    Dave Watts, Eidolon LLC
    BKBK
    Community Expert
    Community Expert
    May 14, 2025

    I would also suggest cfhttp:

    • using method="get";
    • in a CFM file.

     

    licencePlateCheck.cfm

    <cfhttp method="get" url="https://test.carjam.co.nz/a/vehicle:abcd" > 
       <cfhttpparam type="url" name="key" value="myKey" >
       <cfhttpparam type="url" name="plate" value="myPlate" >
    </cfhttp>
    
    <cfdump var="#cfhttp.filecontent#" >