Attaching a pdf to an existing Bill in MYOB using API

This thread is now closed to new comments.
Some of the links and information provided in this thread may no longer be available or relevant.
If you have a question please start a new post.
DeanFX
Partner
4 Posts
Partner
Partner

4Posts

1Kudos

0Solutions

Attaching a pdf to an existing Bill in MYOB using API

Hello all,

 

I am attempting to follow the directions listed here: https://apisupport.myob.com/hc/en-us/articles/360001652376-Base64-Encoded-Bill-Attachement to upload a pdf of an invoice to a bill.

 

I am testing with Postman and am able to successfully connect to the CompanyFile just fine and access any of the required URI's with no issues. Just when i try to upload a file.

 

If i se the BODY value in Postman to 'form-data' i get the below error every time:

{
"Errors": [
{
"Name": "SerializationError",
"Message": null,
"AdditionalDetails": "Unexpected character encountered while parsing number: W. Path '', line 1, position 6.",
"ErrorCode": 50,
"Severity": "Error",
"LearnMore": null
}
],
"Information": "Warning, error messages have not been finalised in this release and may change"
}

 

Is there any further information or sample code to show HOW the body syntax should look??

 

Hoping someone can help point me in the right direction.

6 REPLIES 6
Emile
2,626 Posts
Former Staff
Australia
Former Staff

2,626Posts

0Kudos

310Solutions

Re: Attaching a pdf to an existing Bill in MYOB using API

Hey @DeanFX 

 

Welcome to the forum.

 

I believe it's just a JSON body instead of using form-data.

eg.

{

  "OriginalFileName": "Name",

  "FileBase64Content": "Content"

}

Kind Regards,

Emile
DeanFX
Partner
4 Posts
Partner
Partner

4Posts

1Kudos

0Solutions

Re: Attaching a pdf to an existing Bill in MYOB using API

Thank you Emile,

 

I had tried that, just forgot to put it in the original post, but i get the following error when doing it that way:

{
"Errors": [
{
"Name": "InternalError",
"Message": "An exception was thrown that was not handled correctly. If this situation persists please contact developers@myob.com for further assistance.",
"AdditionalDetails": null,
"ErrorCode": 20,
"Severity": "Error",
"LearnMore": null
}
],
"Information": "Warning, error messages have not been finalised in this release and may change"

 

I do get different messages if i play with the JSON layout, but still no joy getting it to work.

 

EDIT:

Sorry, thought i had better put all my workings in here as well.

 

If i set the BODY to be JSON like:

{

"OriginalFileName": "Invoice.pdf",

"FileBase64Content": "JVBERi0{{truncated for ease}}YNCg++"

}

 

I always get the InternalError as shown above.

 

I thought about playing with the JSON layout and tried:

{

"Attachment": [

{

"OriginalFileName": "Invoice.pdf",

"FileBase64Content": "JVBERi0{{truncated for ease}}YNCg++"

}

]

}

 

But then i get the below error (which may be a valid error as i dont know how MYOB wants the BODY laid out)

{
"Errors": [
{
"Name": "SerializationError",
"Message": null,
"AdditionalDetails": "Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'MYOB.AccountRight.API.Version2.Contracts.BillAttachmentData' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath 'Attachment', line 2, position 16.",
"ErrorCode": 50,
"Severity": "Error",
"LearnMore": null
}
],
"Information": "Warning, error messages have not been finalised in this release and may change"
}

 

Hoping the above helps.

DeanFX
Partner
4 Posts
Partner
Partner

4Posts

1Kudos

0Solutions

Re: Attaching a pdf to an existing Bill in MYOB using API

Followup for anybody looking, i worked out the correct syntax for attaching a pdf file to a bill.

 

The JSON Body should be:

 

{

"Attachment":

{

"OriginalFileName": "{{filename_required}}",

"FileBase64Content": "{{base64_encoded_file_string}}"

}

}

Viital
Contributing User
5 Posts
Contributing User
Contributing User

5Posts

0Kudos

0Solutions

Re: Attaching a pdf to an existing Bill in MYOB using API

Sorry to hijack this thread but I am receiving the error below and the link posted below is now broken.

 

{ "Errors": [ { "Name": "FileExtensionRequired", "Message": "Original file type must be .pdf .tiff .jpg .jpeg .x-ms-png or .png and must be consistent in decoded file base64 content", "AdditionalDetails": "", "ErrorCode": 80000, "Severity": "Error", "LearnMore": null } ], "Information": "Warning, error messages have not been finalised in this release and may change" }

 

My Code Snippet

 

	$curl = curl_init();

		curl_setopt_array($curl, array(
		  CURLOPT_URL => $url,
		  CURLOPT_RETURNTRANSFER => true,
		  CURLOPT_ENCODING => "",
		  CURLOPT_MAXREDIRS => 10,
		  CURLOPT_TIMEOUT => 0,
		  CURLOPT_FOLLOWLOCATION => true,
		  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		  CURLOPT_CUSTOMREQUEST => "POST",
		  CURLOPT_POSTFIELDS =>'{
		  						"Attachment":
								{
								"OriginalFileName": "{{test.jpg}}",
								"FileBase64Content": "{{.$postdata.}}"
								}
								}',
		  CURLOPT_HTTPHEADER => $this->header,
		));

		$response = curl_exec($curl);

		curl_close($curl);
		echo $response;

thank you for any help..

 

Ben

DeanFX
Partner
4 Posts
Partner
Partner

4Posts

1Kudos

0Solutions

Re: Attaching a pdf to an existing Bill in MYOB using API

Hi Ben,

 

I just noticed my synatx may be a bit misleading in the sample i showed. I wrapped the fields with {{ & }} as they appear as a placeholder in the MYOB dev documentation.

However, the actual syntax should be:

{
	"Attachment":
	{
	"OriginalFileName": "test.jpg",
	"FileBase64Content": "base64.encoded_file_string"
	}
}

I'm by no means a CURL programmer, but the above is the syntax i use with no issues.

 

Hope this helps.

Viital
Contributing User
5 Posts
Contributing User
Contributing User

5Posts

0Kudos

0Solutions

Re: Attaching a pdf to an existing Bill in MYOB using API

Thanks Dean. I really appreciated.

 

I have managed to get the upload working perfectly.

 

 

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