Best answer

Error message: Cannot convert undefined or null value to object (throttled)


Userlevel 2
Badge

I am trying to create a post request that returns an array of gross pay items. I thought I did it correctly and it said that my request was successful, but seconds later I got this big red alert that said “Cannot convert undefined or null value to object (throttled).”

I have attached the return code I am using and the model of the data it should be returning. I also attached a photo of the error message. Does anyone have any idea what is going on here?

Here is the Model of the data that should be returned. I am trying to pull in only the grossPayItems Array.
Here is the code I am using to pull in the grossPayItems. I have tried wrapping it in an array and not wrapping it in an array with the same results both times.
Here is the error message it is giving.

 

icon

Best answer by Danvers 26 March 2020, 13:23

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

11 replies

Userlevel 7
Badge +12

@jacob_nolley - Try to `z.console.log(results)`. Is it an object or a null/empty response? You probably need to check if the response is an object before returning it. Otherwise just return an empty array if it’s a search action, or an empty object if it’s a create action.

Userlevel 2
Badge

Do you mean like this? I tried this and I got the same result. It is a Search action. Is there a way to specify that an empty array is okay?

 

Userlevel 7
Badge +12

@jacob_nolley - Here’s what I meant:

const results = z.JSON.parse(response.content);

z.console.log(results); // <--- Here

return results;

To answer your question, you should actually check if the result is an array, like this:

const results = z.JSON.parse(response.content);
if (Array.isArray(results)) {
return results;
} else {
return [];
}

 

Userlevel 2
Badge

@ikbelkirasan

I did what you said and it said that that my results were not an array.

 

When my code looked like this, it said that my results were not an array:

const results = z.JSON.parse(response.content);

z.console.log(results.grossPayItems);

return results.grossPayItems;  

});

 

When my code looked like this, it gave me the red error code:

const results = z.JSON.parse(response.content);

z.console.log([results.grossPayItems]);

return [results.grossPayItems];  

});

 

When my code looked like this, it gave me the results pictured below. I am trying to get all of the results from the subObject “grossPayItems”:

const results = z.JSON.parse(response.content);

z.console.log(results);

return results;  

});

 

Userlevel 7
Badge +12

@jacob_nolley  - I suspect the API is returning an object, not an array. So, try the snippet below:

const results = z.JSON.parse(response.content);

const grossPayItems = results.grossPayItems;
if (Array.isArray(grossPayItems)) {
return grossPayItems;
} else {
return [];
}
Userlevel 2
Badge

@ikbelkirasan 

I received [ ] as a response. Do you know how I could fix this?

 

 

Userlevel 7
Badge +12

@jacob_nolley  - Can you post any console logs you got when you used `z.console.log` as I mentioned earlier? It’s important to see what the API response looks like exactly.

Userlevel 2
Badge

@ikbelkirasan 

When I do the z.console.log, it says “no logs to show”

Userlevel 7
Badge +12

Hi @jacob_nolley - were you able to get to the bottom of this one? If not please let me know and I can ask the Support Team to take a look for you. 

Userlevel 2
Badge

Heyy @Danvers,

 

I fortunately I didnt. Instead, I just implemented a work around and have been able to get that to work!

 

Thank you,

Jacob

Userlevel 7
Badge +12

Thanks for letting us know, I’m glad that you were able to find a workaround 🙌