Re: filterRadius in GET Request via JavaScript (No Postman)

63 views
Skip to first unread message
Message has been deleted

Richard Saffell

unread,
Mar 2, 2022, 8:11:56 PM3/2/22
to apidev, Matthew Sudekum
Matthew,

The filter information goes in the POST body. You'll need to change your request to POST and provide body content.

If you're using the v5 API your raw POST body could look like this:

{
    "data": {
        "filterRadius":
            {
                "miles": 25,
                "postalcode": 48420
            }
        
    }
}

Hope that helps,

Richard

On Wednesday, March 2, 2022 at 7:42:51 PM UTC-5 Matthew Sudekum wrote:
I've been trying to filter any search by location and distance via JavaScript but I can't seem to figure out where to add this code in the fetch request:

'filterRadius': {
'postalcode': 48420,
'miles': 25
}

This is what my fetch looks like without me trying to filter(this works):
fetch(apiURL, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/vnd.api+json',
            'Authorization': apiKey
        }
    })

I've tried adding body: after the headers section and adding it there(no luck).
I've tried adding adding just the snippet after the headers section with and without the quotes around filterRadius(no luck).
I'm lost on what to do. The documentation isn't specific enough for a beginner to know how to implement the filterRadius in JS. It mentions putting it in the POST data, which I think would be that section even when trying to do a GET request.

Please help me
Message has been deleted

Richard Saffell

unread,
Mar 2, 2022, 9:16:25 PM3/2/22
to apidev, Matthew Sudekum, Richard Saffell
What is the value of apiURL?

On Wednesday, March 2, 2022 at 8:30:40 PM UTC-5 Matthew Sudekum wrote:
If I change the method to POST, I get 405 Method Not Allowed error in the browser's console.
Also if I use that code like this:

fetch(apiURL, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/vnd.api+json',
            'Authorization': apiKey
        },
        {
            'data':{
                'filterRadius': {
                    'postalcode': 48420,
                    'miles': 25
                }
            }
        }
    })

I get a "Property assignment expected." error in the editor.

Richard Saffell

unread,
Mar 2, 2022, 9:33:10 PM3/2/22
to apidev, Richard Saffell, Matthew Sudekum
Matthew,

The URL you are POSTing to shouldn't have anything sensitive (e.g., your API Key) if you are using POST with the key in the POST body. I need to know what URL you are POSTing to so I can troubleshoot the issue. You can remove anything sensitive, but there shouldn't be anything.

Richard

Message has been deleted
Message has been deleted

Richard Saffell

unread,
Mar 3, 2022, 1:42:22 PM3/3/22
to apidev, Matthew Sudekum, Richard Saffell
Matthew,

I believe you have to stringify the data.


Richard

On Thursday, March 3, 2022 at 1:25:16 PM UTC-5 Matthew Sudekum wrote:
Here is my revised code. It now allows the POST method after I changed the url. I added the body property. Now the error I get is 400, saying the data provided is not valid JSON
Reply all
Reply to author
Forward
Message has been deleted
0 new messages