setName('import:client') ->setDescription('.') ->setHelp('Client.json shuld be a valid json file, probably looking like the following example: [ {"externalId": "abcdefg","name": "Name of client","address": "Address of client"}, {"externalId": "abcdefg","name": "Name of client","address": "Address of client"}, {"externalId": "abcdefg","name": "Name of client","address": "Address of client"}, {"externalId": "abcdefg","name": "Name of client","address": "Address of client"} ] ') ->addArgument('base_url', InputArgument::REQUIRED, 'The base url of the FD3 Client.') ->addArgument('data_file.json', InputArgument::OPTIONAL, 'The data source from where to get data.', "Client.json") ->addOption('uri', null, InputOption::VALUE_REQUIRED, 'uri after the base_url for the complete URL', '/api/clients.json') ->addOption('user', null, InputOption::VALUE_REQUIRED, 'The FD3 Username.', 'admin') ->addOption('pass', null, InputOption::VALUE_REQUIRED, 'The FD3 Password.', 'adminpass') // ->addOption('source-name', null, InputOption::VALUE_REQUIRED, 'Rename the source to this name.', "upstream") ; } protected function execute(InputInterface $input, OutputInterface $output) { $base_url = $input->getArgument("base_url"); $uri = $input->getOption("uri"); $user = $input->getOption('user'); $pass = $input->getOption('pass'); $file = $input->getArgument("data_file.json"); $url = $base_url.$uri; $parser = new \JsonCollectionParser\Parser(); $parser->parse($file, function($data) use ($url, $user, $pass){ $client = new GuzzClient(); try{ $res = $client->request("POST", $url, [ 'auth' => [$user, $pass], 'body' => json_encode($data) ]); echo $res->getBody(); } catch (RequestException $e) { echo Psr7\str($e->getRequest()); if ($e->hasResponse()) { echo Psr7\str($e->getResponse()); } } } ); } }