Importing invoices from Magento automatically

Hi , I would like to import all the invoices from magento to quickfile but not manually !
I want this to be an automatic process ! Once the invoice is created in magento backend , to send it automatically on the quickfile account !
Can anyone give me some advice to achieve that ?
Thank you

Hi @alecx15

There isn’t a built in automatic way of doing this, but that doesn’t mean it’s not possible.

There are 2 main ways I can think of. The first one being Zapier. Zapier allows you to set up an action when something happens elsewhere. A perfect example in this case would be to create a new invoice on QuickFile when there’s a new order placed on Magento. There’s more information on this here:

The other way is to build a custom solution. This one takes quite a bit more technical knowledge, but if you’re familiar with something like PHP, then it’s certainly possible with our API.

Thank you for your quick answer ! I know PHP , actually i tried with you API , i created the app on quickfile backend and after that i created the SOAP communication in Magento backend but didn’t work ! :frowning:
Any advice please ?
Thanks

I’m not familiar with Magento, so it may be best to raise that query on a support forum for their software directly.

A simple HTTP POST call to the relevant endpoint however should do the trick (rather than SOAP). The end point depends on whether you’re using XML, JSON and it depends on the API version and function (all outlined in the API docs).

There’s a PHP example here with the XML output, or I recently posted a PHP example with JSON for another user, here

Thank you very much for your answer ! I tried with zapier also and i got this error message !
"We hit an error adding your new account
authentication failed: quickfile.co.uk returned (406) Not Acceptable and said “No active Power User Subscription”

Can you tell me more about this error ? Thanks

To use Zapier, a Power User Subscription would be required. These are optional for XS, S and M graded accounts, and a requirement for L and XL accounts.

There’s more on the subscription and other features it adds here:

Thank you for your answer ! I have another question , every time when i’m running the php file to send the data , "Current Count " in my quick file account is incremented but i didn’t receive the invoice on my sales !
Can you help me with this please ?

<?php

$accountNumber		= '####';		// QuickFile account number
$applicationID		= '####';	// Application ID
$apiKey				= '####';	// Account API Key
$submissionCode  	= uniqid();			// Randomly generated submission number, but this can be anything unique

$endPoint         	= 'https://api.quickfile.co.uk/1_2/invoice/create';

$data 	= [
	'payload'		=> [
		'Header'		=> [
			'MessageType'       => 'Request',
			'SubmissionNumber'  => $submissionCode,
			'Authentication'    => [
				'AccNumber'         => $accountNumber,
				'MD5Value'          => md5($accountNumber . $apiKey . $submissionCode),
				'ApplicationID'     => $applicationID
			]
		],
		'Body'			=> [
			'InvoiceData'	=> [
				'InvoiceType'	=> 'INVOICE',
				'ClientID'		=> 12345,
				'ClientAddress'	=> [
					'Address'		=> '123 High Street<br>London<br>AA1 1AA<br>United Kingdom',
					'CountryISO'	=> 'GB'
				],
				'Currency'		=> 'GBP',
				'TermDays'		=> 14,
				'Language'		=> 'en',
				'InvoiceLines'	=> [
					'ItemLines'		=> [
						'ItemLine'		=> [
							'ItemID'			=> 0,
							'ItemName'		 	=> 'USB Cable',
							'ItemDescription'	=> '2.5m USD Cable (Blue)',
							'ItemNominalCode'	=>	4000,
							'Tax1'		=> [
								'TaxName'	 	=> 'VAT',
								'TaxPercentage'	=> '20.00',
								'TaxAmount'		=> '2'
							],
							'UnitCost'	=> '10.00',
							'Qty'		=> 1
						]
					]
				],
				'Scheduling'	=> [
					'SingleInvoiceData'	=> [
						'IssueDate'			=> '2018-01-25'
					]
				]
			]
		]		
	]
];

$ch = curl_init($endPoint);

curl_setopt_array($ch, array(
	CURLOPT_POST                => TRUE,
	CURLOPT_RETURNTRANSFER      => TRUE,
	CURLOPT_HTTPHEADER          => array('Content-Type: text/json'),
	CURLINFO_HEADER_OUT         => TRUE,            
	CURLOPT_POSTFIELDS          => json_encode($data),
	CURLOPT_SSL_VERIFYPEER      => TRUE // This may need to be false if testing from localhost
));

$response               = curl_exec($ch);

$httpCode               = curl_getinfo($ch, CURLINFO_HTTP_CODE);

$return                 = json_decode($response);

if($httpCode != 200)
{
        echo 'Curl bad!';
}
else
{

        echo 'Curl successful!';
}

What is the value of $return or $response?

Do you see ‘Curl bad’ or ‘Curl successful’?

I see “Curl Bad” when i’m running the file !

What’s the value of the $return and/or $response variable? It’s likely that will contain an error message.

At a guess, the first thing that stands out to me is the ClientID is still set at 12345. This should match a ClientID from your account.

But if there are errors being returned, this will explain it more accurately than what I can.

There are no errors displayed on the browser console ! All i can see is Curl Bad

PHP is a server based coding language, so nothing will be displayed browser end unless the script outputs it.

If you were to put, for example:

if($httpCode != 200)
{
        print_r($return);
}
else
{
        echo 'Curl successful!';
}

this will output the complete value of $return for you. However, view the source of the page to get a “pretty” looking output.

Yah i got the error message :

stdClass Object ( [Errors] => stdClass Object ( [Error] => Array ( [0] => Client was not found (12345) ) ) )

As suspected, the ClientID being supplied to the API is 12345, which isn’t a client on your account.

This should be a ClientID of an existing client. For example, see this post from my colleague:

But this value can also be pulled from another API function and stored if needed. It depends on your setup with the API and your clients.

What i want to achieve is to pull the invoice from my magento store and post it to quickfile !

The above script will create an invoice in QuickFile, providing the correct values are supplied (e.g. the correct ClientID and account details).

If you’re using one client (let’s say “Daily Sales”), then it would be the same ClientID - my colleague’s post above will help identify their ID. If you’re using a new client per Magento client, then the ID will be different each time.

As I mentioned above, I’m not familiar with Magento, so I’m unable to comment on how to get the magento data to put into the QuickFile API call. There may be another user on here who would know better than I do, or you may find it easier to post to somewhere like a Magento forum, or Stack Overflow.

We’re more than happy to help with the QuickFile side of things however.

Thank you very much , i will ask on Stack Overflow as well !
Have a nice day