Problem creating invoices

Hi,

Currently having some issues with trying to create invoices. The API
doesn’t seem to be receiving my POST data. I have tried posting json and a
urlencoded string, but no avail.

Using the adoy/oauth2 PHP library.

    $params = array(
        'organisation_name' => $firm->name,
        'phone_number'      => $firm->tel,
    );

    printf('%s' . PHP_EOL, 

print_r($this->freeagent->create_contact($params), true));

public function create_contact(Array $params)
{
    return $this->client->fetch($this->base_api_url . '/contacts', 

$params, Client::HTTP_METHOD_POST);
}

However the only response I can get back is this. GET requests seem to be
working fine returning json of contacts, etc.

Array
(
[result] => Array
(
[errors] => Array
(
[0] => Array
(
[message] => first_name can’t be blank
)

                [1] => Array
                    (
                        [message] => last_name can't be blank
                    )

                [2] => Array
                    (
                        [message] => organisation_name can't be blank
                    )

            )

    )

[code] => 422
[content_type] => application/json; charset=utf-8

)

Hi Wade,

There was a similar queryhttps://groups.google.com/forum/#!topic/freeagent_api/-NqbItDXakQa few days ago.

In that case, there were two related issues when using that PHP library:
the first being that resource submissions must be nested, i.e.:

{“contact”: { “organisation_name”: … } };

not just:

{ “organisation_name”: … };

and the second being that older versions of the library had issues when
submitting nested params like this. Have a look at that thread and see if
it helps. If not, let me know and I’ll look into this further for you.

Cheers,

-JOn Monday, 3 March 2014 15:50:21 UTC, wa...@codepotato.co.uk wrote:

Hi,

Currently having some issues with trying to create invoices. The API
doesn’t seem to be receiving my POST data. I have tried posting json and a
urlencoded string, but no avail.

Using the adoy/oauth2 PHP library.

    $params = array(
        'organisation_name' => $firm->name,
        'phone_number'      => $firm->tel,
    );

    printf('%s' . PHP_EOL, 

print_r($this->freeagent->create_contact($params), true));

From my freeagent class as used above.

public function create_contact(Array $params)
{
    return $this->client->fetch($this->base_api_url . '/contacts', 

$params, Client::HTTP_METHOD_POST);
}

However the only response I can get back is this. GET requests seem to be
working fine returning json of contacts, etc.

Array
(
[result] => Array
(
[errors] => Array
(
[0] => Array
(
[message] => first_name can’t be blank
)

                [1] => Array
                    (
                        [message] => last_name can't be blank
                    )

                [2] => Array
                    (
                        [message] => organisation_name can't be blank
                    )

            )

    )

[code] => 422
[content_type] => application/json; charset=utf-8

)