API error response and parsed outpout

I am working with an API that has non standard responses. When looking up a record and it is not found, it just returns a JSON like this:

And the parsed output looks like this:

image

When I try to use the Mock output with live data, I get the failed to populate error:

image

When I input the “path to detailed error message field” to “error”, I still get the same API response and the parse output looks better but I still can’t populate the mockup output because the parsed output is in an array. Why is it parsed into an array and not just an object? I don’t seem to be able to test mockup with an array. Same “failed to populate” error.

A successful response and parsed output looks like this:

How can I get a simple API response of

{
"error": "Could not find affiliates with this keyword."
}

in a proper parsed output for mockup testing?

@Daniel_P - Currently, it isn’t possible to store an error in the mock output section.

If you want to test a specific step, you can create dummy data in the lookup results mapping. To do this, update the error block in the input section, then copy the resulting output and use it in the downstream steps for testing.

@sreevaniamara Thank you, but that is not what I was asking. I don’t need to store error in the mock output. I just need the mock output to reflect the parsed output but it appears because it is parsed as an array instead of object, it is not working?

You're right - currently, the mock output only supports the canonical formats listed here: Celigo platform’s canonical format for mock data.

If the parsed output is a valid record, it should ideally be wrapped in one of the page_of_records formats so it can be stored and reflected correctly in the mock output.

Can you confirm if there’s a scenario where the record itself isn’t getting stored as expected? That would help us understand whether the issue is with the structure of the parsed output or with how it’s being saved.

@sreevaniamara I have provided detailed screenshots of the parsed output for success and error above. From what I can tell, the parsed output on the error is an array, instead of an object containing page_of_records array. I have no control over the parsed output. I might have to give up on this. Anyone else have any ideas?

It's good feedback. Lookups don't really have a "mock response" and instead only have a "mock output," which is the parsed output (of successful API calls) with the page_of_records contract. Since an error is not handled as a record, it doesn't get put there. In the case of imports, you are able to do this because it is a true "mock response" where it has an array of errors, the returned raw JSON, and other things. In your case, I assume you're wanting to test a failure case of a lookup so you can then branch off, check preview data of results mapper, postResponseMap script, and anything else downstream for if an error occurs on that step.

Since I don't have the full background, I assume you're wanting to handle this in a subsequent step or figure out how to ignore this error. If you're trying to ignore it, since a non-result can also be handled later in the flow by branching off and you don't want an error returned and the record to stop since a thing was found, you can follow this article to ignore the error (Handling errors in lookups with PreSavePage scripts). If you do want an error to be thrown, but you also want the record to continue, you can use the proceed regardless of error function, result map in errors to your course record data, then branch later for if errors.length > 0.

Thanks @tylerlamparter . I am trying to use a post submit hook to look for the error and ignore it. Is there a way to log the api response while running the flow in real time? It seems those mockup responses are not helping me much.

Yeah you can enable debug logs for this lookup, then view the logs so you can correctly make a preSavePage function. You can also create a preSavePage hook, then put console.log(JSON.stringify(options.errors)); to see what the input to your script is, then make the script.