Jump to content

How to handle zero id values ?


Dev_Guy

Recommended Posts

I'm developing a library that is basically a wrapper for the different PS resources.

The thing is that looking at the values returned by some resources I have noticed that sometimes I receive a zero value as the identifier of a resource.

For example: If I call the addresses resource I receive a Json with the following form:

{
	"address": {
		"id": 2,
		"id_customer": "2",
		"id_manufacturer": "0",
		"id_supplier": "0",
		"id_warehouse": "0",
		"id_country": "8",
		"id_state": "0",
		"alias": "Mon adresse",
		"company": "My Company",
		"lastname": "DOE",
		"firstname": "John",
		"vat_number": "",
		"address1": "16, Main street",
		"address2": "2nd floor",
		"postcode": "75002",
		"city": "Paris ",
		"other": "",
		"phone": "0102030405",
		"phone_mobile": "",
		"dni": "",
		"deleted": "0",
		"date_add": "2021-09-03 20:40:16",
		"date_upd": "2021-09-03 20:40:16"
	}
}

As you can see in the example, the value of id_state is "0" but when I call the states resource with the value 0, it returns a 404 NOT FOUND code.

Reading the documentation, the value of id_state is isNullOrUnsignedId so I understand that if that resource does not exist it should return null instead of 0 right?

My question is, how should I interpret the value 0 in this context?

Additionally, it says that the value of id_state should be isNullOrUnsignedId but it actually returns a String with a numeric value. It's not a big problem but I don't understand why it's a String, in fact, the only really numeric value is the first one ("id"), the rest are Strings

I don't know if I'm doing something wrong or I'm misunderstanding something

Any clarification is welcome

Thank you very much and sorry for the inconvenience

Best Regards

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...