0

I'm trying to work with the API here: https://abr.business.gov.au/json/ but it requires a callback function to be passed in as a query parameter. How can I actually use this API from a react app and pass in a callback function?

I really have no idea.

1 Answer 1

1

The API calls return some javascript.

So when you make the following request:

https://abr.business.gov.au/json/AbnDetails.aspx?abn=74172177893&callback=callback&guid=myguid

It will return this:

callback({"Abn":"","AbnStatus":"","Acn":"","AddressDate":null,"AddressPostcode":"","AddressState":"","BusinessName":[],"EntityName":"","EntityTypeCode":"","EntityTypeName":"","Gst":null,"Message":"The GUID entered is not recognised as a Registered Party"})

This will invoke a function on the window object named callback, so somewhere in your code you have to define a function named callback which handles the call.

Here is an example of it being done for the request where callback=abnCallback, note the abnCallback function: https://abr.business.gov.au/json/Script/abnlookup-sample.js

Good luck, this doesn't really have anything to do with react btw. It's just a javascript thing.

Sign up to request clarification or add additional context in comments.

4 Comments

So I send a request like this fetch(`${abnAddress}?guid=${GUID}&abn=${abnNo}&callback=callbackFunction`, { mode: 'no-cors' }) and i've got a function const callbackFunction = (e) => { console.log('call back func') setCallBack(e) } that should get called? But I can't see the console.log anywhere in my localhost. How can I get the results of the callback function into my app?
Don't say const callbackFunction = .... Say window.callbackFunction = ...
@Ogen Let's say i'm not using a scripting language and I'm calling this endpoint. Is there any recommended way to extract the json object instead of the function call?
@LakshanThilakarathne regexp and JSON.parse. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.