Closed Spreeuw closed 7 years ago
And here I thought I was missing something, because after setting the administrationId listing the administrations didn't work anymore. Good to know I was not.
Looks like the API doesn't support looking up an administration based on ID such as other Entities do: https://developer.moneybird.com/api/administration/.
I don't see any ways to make this work unless there is an extra call in Picqer\Financials\Moneybird\MoneyBird
that saves the list of administrations on each request. But that would add a single request each time you use the API while fetching that data is not needed in every request. I think you're best off by caching the $moneybird->administration()->getAll()
response with the administration id as key and make your own implementation to fetch the details afterwards.
The solution is to give Administration a different Connection object than other models:
Here is what I currently have locally:
class Administration extends Model {
[..]
/**
* @param \Picqer\Financials\Moneybird\Connection $connection
* @param array $attributes
*/
public function __construct(Connection $connection, array $attributes = [])
{
parent::__construct($connection->withoutAdministrationId(), $attributes);
}
}
What I changed:
Looks like the API doesn't support looking up an administration based on ID such as other Entities do: > https://developer.moneybird.com/api/administration/.
$moneybird->administration()->get()
works for me to fetch all administrations, after the change explained above.
Since this is a global function, in my opinion this should also work when administrationId is set. I'm not sure about the best approach around this with $connection->formatUrl() here, since this always sets the id when it's available. I'm open to suggestions!