MYOBCommunity
Partner Zone
|
|
Partner Zone

Invoice Creation Error - Essentials API

2 REPLIES
Partner chinzy
2 Posts
Partner
chinzy
Partner

2Posts

0Kudos

0Solutions

Re: Invoice Creation Error - Essentials API

HI,

 

Thank you for the response, but no its, not the issue, I use the exact code but I'm still getting the same error.

 Smiley Sad

 

MYOB Staff Post DeveloperJack
131 Posts
MYOB Staff Post
Australia
DeveloperJack
MYOB Staff Post

131Posts

28Kudos

17Solutions

Re: Invoice Creation Error - Essentials API

Hi there @chinzy,

This might be to do with the lines field; it should be an array of objects but the code below appears to be a single array.

 

The best way to debug this is to run the code through your json encoder (I'm guessing you're using json_encode()? ) and compare the output with your expected tests. You could also put this JSON into a tool like Postman to test API calls and then match the JSON back to your array structure.

 

My guess is that your code might need to look like:

 

"lines": [

  [

    "account": []
    ...

  ],

]

 

But you'll need to test this with your code to make sure.

 

Hope this helps!

 

Jack Skinner
MYOBapi Evangelist

Are you a developer? Check out http://developer.myob.com
Looking for an Add-on? Check out http://myob.com/addons/
Partner chinzy
2 Posts
Partner
chinzy
Partner

2Posts

0Kudos

0Solutions

Invoice Creation Error - Essentials API

Hi guys,

 

I'm getting an error while I try to create an invoice.

 

Error : {"errors":[{"field":"","message":"Invalid JSON format","code":"1000"}

 

The headers I use :

 

$headers = array(
'Authorization: Bearer '.$_SESSION['access_token'],
'x-myobapi-key: '.$api_key,
'x-myobapi-version: v0',
'Content-Type: application/json'
);

 

The Params I use(array format before making a json)

 

$invarr = array(

"contact" => array(
"uid" => "19320539",
"uri" => "https://api.myob.com/au/essentials/businesses/xxxxx/contacts/19320539",
"name" => "Sample Chinzy"
),
"invoiceNumber" => "IV00000000002",
"issueDate" => "2018-05-08",
"dueDate" => "2018-05-56",
"gstInclusive" => true,
"lines" => array(

"account" => array(
"uid" => "9",
),
"item" => array(
"uid" => "4585951",
),
"taxType" => array(
"uid" => "10",
),
"unitOfMeasure" => "Qty",
"quantity" => 2,
"unitPrice" => 5.50,

),
"notes" => "An invoice note",
"total" => 11.00,
"gst" => 1.00,
"amountPaid" => 0,
"amountDue" => 12.00,
"status" => "Open",
"displayStatus" => "Not Paid"
);

 

The URL : $url = 'https://api.myob.com/au/essentials/businesses/xxxxxx/sale/invoices';

 

I can create an item, contact and retrieve them without any issues at all so I know the process I follow is correct, would someone be able to assist me to spot what I'm doing wrong?

I added the required fields as instructed: http://developer.myob.com/api/essentials-accounting/endpoints/sale/invoices/

 

Thank you in advance,

Didn't find your answer here?
Try using advanced search to find a post more easily Advanced Search
or
Get the conversation started and make a new post Start a Post