invoiceninja / sdk-php

PHP wrapper for Invoice Ninja's REST API
https://www.invoiceninja.com
83 stars 42 forks source link

Examples please #97

Closed 88kbbq closed 1 year ago

88kbbq commented 1 year ago

I've searched everywhere for how to use this API, and the PHP wrapper didn't make it work. There is a serious lack of official documentation for actual working examples, like a boilerplate. If you have it posted here, it doesn't work. Please add a simple form with post or get on a self-hosted version. This has taken way to much time to debug.

turbo124 commented 1 year ago

Have a look in the tests folder

88kbbq commented 1 year ago

I looked in the test folder but couldn't find anything to help me. The read me and the git are different and conflicting. I'm likely running into issues with AMP HTML too, header responses and CORS endpoints.

On Mon, Jan 2, 2023 at 7:07 PM David Bomba @.***> wrote:

Have a look in the tests folder

— Reply to this email directly, view it on GitHub https://github.com/invoiceninja/sdk-php/issues/97#issuecomment-1368848345, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEIR7NHGMFWA4ICTD55VNTWQKZGHANCNFSM6AAAAAATOW7YS4 . You are receiving this because you authored the thread.Message ID: @.***>

88kbbq commented 1 year ago

What is wrong with this part?

use InvoiceNinja\Sdk\InvoiceNinja; $ninja = new InvoiceNinja("xxxxxx"); $ninja->setUrl("https://mysite.com/api/v1"); $invoices = $ninja->invoices->all(); $clients = $ninja->clients->create([ 'name' => '$company', 'vat_number' => '$vat', 'contacts' => [ [ 'first_name' => '$name', 'last_name' => '$name', 'send_email' => false, 'phone' => '$telephone', 'email' => '$email', ],

    ]
]);

On Mon, Jan 2, 2023 at 7:07 PM David Bomba @.***> wrote:

Have a look in the tests folder

— Reply to this email directly, view it on GitHub https://github.com/invoiceninja/sdk-php/issues/97#issuecomment-1368848345, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEIR7NHGMFWA4ICTD55VNTWQKZGHANCNFSM6AAAAAATOW7YS4 . You are receiving this because you authored the thread.Message ID: @.***>

turbo124 commented 1 year ago

What response are you getting back?

It looks like the URL you are using is the issue, you don't need to append /api/v1

    protected string $token = "company-token-test";
    protected string $url = "http://ninja.test:8000";
88kbbq commented 1 year ago

Thank you for your help David. Still not working. The tests files and the readme files in both the composer install and github are all different, so there's no Northstar for me. I've coded this whole site in AMP HTML and had relatively few issues, but working with this API is much more difficult.

I get:

Failed to load resource: the server responded with a status of 500 () log.js:232 [amp-form] Form submission failed: Error: HTTP error 500

2023/01/02 20:26:12 [error] 26312#26312: *91412 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Class 'InvoiceNinja\Sdk\InvoiceNinja' not found in /var/www/html/test.php:39

Stack trace:

0 {main}

thrown in /var/www/html/test.php on line 39" while reading response header from upstream, client: 162.158.163.9, server: www.88k.com.tw, request: "POST /test.php?__amp_source_origin=https%3A%2F%2Fwww.88k.com.tw HTTP/2.0", upstream: "fastcgi://unix:/run/php/php7.2-fpm.sock:", host: " www.88k.com.tw", referrer: "https://www.88k.com.tw/catering"

On Mon, Jan 2, 2023 at 8:17 PM David Bomba @.***> wrote:

What response are you getting back?

It looks like the URL you are using is the issue, you don't need to append /api/v1

protected string $token = "company-token-test";
protected string $url = "http://ninja.test:8000";

— Reply to this email directly, view it on GitHub https://github.com/invoiceninja/sdk-php/issues/97#issuecomment-1368899263, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEIR7MM22NLY3LWQNVVP2TWQLBL7ANCNFSM6AAAAAATOW7YS4 . You are receiving this because you authored the thread.Message ID: @.***>

turbo124 commented 1 year ago

Not sure how your app is built, but the error

Uncaught Error: Class'InvoiceNinja\Sdk\InvoiceNinja' not found

Indicates that the script cannot find the Invoice Ninja class.

88kbbq commented 1 year ago

To my point, I've followed all instructions where I found them, each one at a time to no avail. There are many others also asking for better documentation.

On Mon, Jan 2, 2023 at 8:59 PM David Bomba @.***> wrote:

Not sure how your app is built, but the error

Uncaught Error: Class'InvoiceNinja\Sdk\InvoiceNinja' not found

Indicates that the script cannot find the Invoice Ninja class.

— Reply to this email directly, view it on GitHub https://github.com/invoiceninja/sdk-php/issues/97#issuecomment-1368924598, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACEIR7M2HMJ7YSD4NQMDV4LWQLGJXANCNFSM6AAAAAATOW7YS4 . You are receiving this because you authored the thread.Message ID: @.***>