Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Move API Call from jQuery to the Back End

Participant ,
May 13, 2025 May 13, 2025

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.

187
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 13, 2025 May 13, 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

 

Translate
Community Expert ,
May 13, 2025 May 13, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 13, 2025 May 13, 2025
LATEST

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#" >

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources