API gives different responses destroying data structure

Hi there!

I need help! I’m using the Bing Search API. Depending on the query entered, the structure of the response changes.

E.g. if I enter “2+3” it response with a math equation.

E.g. if I enter Obama it response with a lot of Photos.

But since I am building a search for all cases, I don’t know what the final user will enter.

Problem: if I want to set up the Api with the Api connector, I can only enter one query type and therefore get only one type of response answer.

Meaning I only can’t build a front end that supports all scenarios.

I used a math equation to set it up in the connector. Then I wanted to add the other use case, so I changed to query in the Api connector to Obama. Now I can add the photo visualisation, but it is giving me errors, because there is no more math equation response.

I’d be thankful for any help!

I think, but not sure, that you may use the manually enter API response. This will let you add differents options that the API can return. And maybe you can use filter like (if image is empty…) to display the right result you want. Also you may consider using different call according to request (maybe you can use a menu where user can choose image, math, news…) and use call according to that (responseFilter)

1 Like

@Jici is correct. In order to have a single api connector call, you’ll need to manually enter all the response objects you want to support. If you are lucky, you can find an example online. If not, you have some work to do as the bing api returns many different object types, not to mention a different error response.

I usually open up postman, and start making calls to the api. Save the response you receive each time. Then compile it into a single (and valid) json response by merging everything together in their appropriate parent object – note merging, not simply appending all the responses.

Once you have the entire json ready, you use the api connector option to manually manage the response and paste it all in. It definitely works, but it will take some time to get all the possible options covered.

–Ken

3 Likes

Thanks soooo much @Jici and @mebeingken! You two saved my day. I didn’t know that it was possible to edit the response. It is hidden very well, I find.

Thanks!

1 Like

I am having the same issue with the USPS address validation API. The return object is usually:
image
But if it is a wrong zip code, it returns:
image
{
“AddressValidateResponse”: {
“Address”: {
“Error”: {
“Number”: “-2147219399”,
“Source”: “clsAMS”,
“Description”: "Invalid Zip Code. ",
“HelpFile”: “”,
“HelpContext”: “”
},
“Address2”: “1506 WINDING BEND LN”,
“City”: “MANCHESTER”,
“State”: “MO”,
“Zip5”: “63021”,
“Zip4”: “7046”,
“DeliveryPoint”: “06”,
“CarrierRoute”: “C086”,
“Footnotes”: “L”,
“DPVConfirmation”: “Y”,
“DPVCMRA”: “N”,
“DPVFootnotes”: “AABB”,
“Business”: “N”,
“CentralDeliveryPoint”: “N”,
“Vacant”: “N”,
“_attributes”: {
“ID”: “0”
}
}
}
}

I click SAVE, and it is not saving.
If I go back to enter it again manually, the error section I added is gone.
In my workflow, the call is returning a 7 digit number.

@hhenske Can you put your JSON between ``` quotes so we can copy and validate it?
It’s a little bit hard to read actually

{ "AddressValidateResponse": { "Address": { "Error": { "Number": "-2147219399", "Source": "clsAMS", "Description": "Invalid Zip Code. ", "HelpFile": "", "HelpContext": "" }, "Address2": "1506 WINDING BEND LN", "City": "MANCHESTER", "State": "MO", "Zip5": "63021", "Zip4": "7046", "DeliveryPoint": "06", "CarrierRoute": "C086", "Footnotes": "L", "DPVConfirmation": "Y", "DPVCMRA": "N", "DPVFootnotes": "AABB", "Business": "N", "CentralDeliveryPoint": "N", "Vacant": "N", "_attributes": { "ID": "0" } } } }

Well that’s not what I expected. But it does work.

The merged JSON look fine. I tested it to manually enter API response and I have no issue to get it parsed correctly. Can you share a screencast of what you do?