Have been trying to figure this out for a day now. I am trying to use fiken.no`s API to retrieve customernumbers. The API is HAL+JSON based and i want to access the data with PHP.
When creating a new account you receive no response, but only HTTP 201, so to get the generated customernumber i need to use the search endpoint.
That endpoint only returns all users like this:
{
"_links": {
"self": {
"href": "https://fiken.no/api/v1/companies/fiken-demo-personlig-gnist-enk/contacts"
}
},
"_embedded": {
"https://fiken.no/api/v1/rel/contacts": [
{
"_links": {
"self": {
"href": "https://fiken.no/api/v1/companies/fiken-demo-personlig-gnist-enk/contacts/757941482"
}
},
"name": "Ola Nordmann 2",
"email": "mail@mail.com",
"address": {
"country": "Norge"
},
"customerNumber": 10003
},
{
"_links": {
"self": {
"href": "https://fiken.no/api/v1/companies/fiken-demo-personlig-gnist-enk/contacts/757941171"
}
},
"name": "Ola Nordmann 1",
"email": "findthis@example.com",
"address": {
"country": "Norge"
},
"customerNumber": 10002
},
{
"_links": {
"self": {
"href": "https://fiken.no/api/v1/companies/fiken-demo-personlig-gnist-enk/contacts/756867201"
}
},
"name": "Demoleverandør",
"address": {
"address1": "Demoveien 44",
"address2": "",
"postalPlace": "Oslo",
"postalCode": "0190",
"country": "Norge"
},
"supplierNumber": 20001
},
{
"_links": {
"self": {
"href": "https://fiken.no/api/v1/companies/fiken-demo-personlig-gnist-enk/contacts/756867200"
}
},
"name": "Demokunde",
"address": {
"address1": "Demoveien 22",
"address2": "",
"postalPlace": "Oslo",
"postalCode": "0190",
"country": "Norge"
},
"customerNumber": 10001
}
]
}}
From this response i need to query for f.ex the email findthis@example.com and get the whole user object from that. That includes the address data and especially the customernumber. How would i go ahead to do that?
I have found this: Search a key in a Json (nested array) PHP that looks like my issues but here the key is constant in the json array. Here it is from 0 and out to infinity.
Is there any better way to process this using PHP than normal JSON practices? Thanks for any help!