I installed the following vendor: https://github.com/BlueFeatherGroup/eloquent-filemaker
and I'm trying to sync data from FileMaker to mysql via the API.
And my function when called the first time throws out this error, while the second time it passes properly.
This is my mistake:
BlueFeather\EloquentFileMaker\Exceptions\FileMakerDataApiException
Authorization header 'Basic' invalid.
at vendor/bluefeather/eloquent-filemaker/src/Services/FileMakerConnection.php:167
163▕ // API token is expired. We should expire it in the cache so it isn't used again.
164▕ $this->forgetSessionToken();
165▕ return;
166▕ default:
167▕ throw new FileMakerDataApiException($message['message'], $code);
168▕ }
169▕ }
170▕ }
171▕ } else{
+7 vendor frames
8 app/Console/Commands/SyncFileMakerDB.php:93
Illuminate\Database\Eloquent\Model::__callStatic("count", [])
This is the connection in the .env file:
FM_DB_HOST = filemaker01.server
FM_DB_USERNAME = apirest
FM_DB_PASSWORD = vkjfkdjskfs
this is the database connection in database.php
'DATABASENAME' => [
'driver' => 'filemaker',
'host' => env ('FM_DB_HOST', ''),
'database' => 'DATABASENAME',
'username' => env ('FM_DB_USERNAME', ''),
'password' => env ('FM_DB_PASSWORD', ''),
'prefix' => env ('FM_DB_PREFIX', ''),
'version' => env ('FM_DB_VERSION', 'vLatest'),
'protocol' => env ('FM_DB_PROTOCOL', 'https'),
],
DATABASENAME class
<? php
namespace App \ Models \ FileMaker \ DATABASENAME;
use App \ Traits \ FormatsAttributeNames;
use BlueFeather \ EloquentFileMaker \ Database \ Eloquent \ FMModel;
use Illuminate \ Database \ Eloquent \ Factories \ HasFactory;
class DATABASENAME extends FMModel
{
use HasFactory;
use FormatsAttributeNames;
protected $ connection = 'DATABASENAME';
protected $ layout = 'ApiLayout';
protected $ fieldMapping = [
'Article (1)' => 'Article',
'Article2' => 'Article2',
'BestellNr2' => 'Bestellnr_2',
];
}
and I have now created a command that synchronizes data from FileMaker to Mysql DB
protected $ signature = 'sync-filemaker-db {db}';
public function handle ()
{
switch ($ this-> argument ('db')) {
case 'DATABASENAME':
$ this-> handleDATABASE ();
break;
default:
$ this-> error ('No valid database provided');
return 1;
}
return 0;
}
public static function> handleDATABASE ()
{
$ offset = 0;
$ count = DATABASENAME :: count ();
while ($ offset <$ count) {
DATABASENAME :: offset ($ offset) -> get () -> each (function (DATABASENAME $ item) use (& $ offset) {
$ recordId = (int) $ item-> getRecordId ();
MYSQLTABLENAME :: updateOrCreate ([
'record_id' => $ recordId,
], DATABASENAME :: formatAttributeNames ($ item-> getAttributes ()));
$ offset ++;
});
}
dump ($ offset);
}
and then I call my command:
php artisan sync-filemaker-db DATABASENAME
and then every time I first call the command php artisan sync-filemaker-db DATABASENAME this error pops up:
BlueFeather\EloquentFileMaker\Exceptions\FileMakerDataApiException
Authorization header 'Basic' invalid.
at C:\xampp\htdocs\enterprise-service-bus\vendor\bluefeather\eloquent-filemaker\src\Services\FileMakerConnection.php:167
163▕ // API token is expired. We should expire it in the cache so it isn't used again. 164▕ $this->forgetSessionToken(); 165▕ return; 166▕ default: "https://filemaker01.server/fmi/data/vLatest/databases/DATABASENAME/layouts/ApiLayout/records/", []) And the second time I call her again, and so every next time she does everything.
Does the library take the Token and then use it, but the old one stays with her, I don't know what else could be the problem?
Thanks a lot.