Need Help with adding Params

Hi All

A UI/UX designer by trade so I’m a bit new to APIs… Hopefully someone can help me here

In Mockaroo, I have a Schema:

I want to get a API that allows me to query for example just New items (from the State column. My API Handler is as follows:

schema “ServiceNow”
generate 10
set “State”, State: params[‘value’]

Using the route: /servicenow.json/State=New

But I get the following error message

{“error”:“undefined method `State=’ for #\u003cColumn:0x00007ff53a0f4858\u003e\nDid you mean? states=\n states\n states?”}

Can anyone help please?
Thanks
Stewart

It looks like you just want to return a record from the SN Data dataset. You can do that directly in your Mock API using:

from_dataset("SN Data", criteria: { State: params['value'] })

This will return a random record from SN Data where the State field has a value of “New”.

Hey - thanks for responding. I did try that:

but when I click the check in browser link, I get:

{“error”:“783: unexpected token at ‘Number,Short Description,Account,State,Substate,Subcategory,Updated,Opened,Priority,Category,Parent,Incident,Environment\n’”}

Do I need to do something with the route?

Thanks again

Technically, the last slash should be a question mark, so it would be
/servicenow.json?State=New

However, that still throws an error although you might see the record at the end of the error string. I was getting different results with that, sometimes I would get the values, sometimes just the fields.