API with $_GET Route URL Parameter

I am using an SPA page setup with routing and have it working as intended with the dynamic URL parameter.

routing-get

As part of my SPA, I utilize an API to retrieve information.

The issue I am having is how to tell the API to “get” the route URL Parameter and use it to retrieve specific information.

I set the Server Action > Globals ? $_GET variable as I normally would. In this case, batchid.

I added the variable to the API.

"batchId": "{{$_GET.batchid}}",

The error being displayed from the API is that the datatype is not a numericString. The value is stored in the mysql database as an INT.

Using the non-route way works as intended and returns results.

routing-get-2

So I am not clear why it works without routing, but does not work with routing.

May be way of the mark here but GET parameters are basically passed as strings. Have you tied using the toNumber() formatter on the parameter before sending it to the API. try $_GET.batchid.toNumber()

1 Like

In the browser dev tools, can you check what’s the API call, and what are its parameters and values? I.e. what’s being sent in the request?

I got a new error message:

{code: “E00013”, text: “Batch ID is invalid.”}

I am not sure if this is what you mean, but this is what I see with “batchId”: “{{$_GET.batchid}}”,

OK, no solution but at least that seems to confirm the api expects “123456” (numeric string) not 123456 as a number

I’m more interested to see the headers, sent with the request (the left tab).

Is it possible that your API expects a string as a value?
Maybe try using .toString() formatter for the $_GET variable?

With .toString(), I receive the original error about the datatype being invalid.

Can you please check in your API docs, what does it expect as a value and data type exactly?

Source: https://developer.authorize.net/api/reference/index.html#transaction-reporting-get-transaction-list

So it’s just a string, passing a number.
Strange it’s not working with your GET variable, will have to investigate this.

Thanks @Teodor,

While not as pretty as with routing, I can make it work with the non-routing method. :slight_smile: