Forum Discussion

Viital's avatar
Viital
Contributing User
5 years ago

Attaching PDF to bill API

Hi I have had the below working for several months but about a week ago this stopped working. Did the API receive an update?

 

{
  "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"
}

 

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://ar2.api.myob.com/accountright/cf....fd/Purchase/Bill/Service/bf7....68/Attachment',
  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": "me.pdf",

"FileBase64Content": "JVBER.....=="

}

}',
  CURLOPT_HTTPHEADER => array(
    'x-myobapi-key: secretkey',
    'x-myobapi-version: v2',
    'Accept-Encoding: gzip,deflate',
    'Content-Type: application/json',
    'Authorization: Bearer AAE.......uw'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

2 Replies

Replies have been turned off for this discussion
  • Han-Solo's avatar
    Han-Solo
    MYOB Moderator
    5 years ago

    Hi Viital

     

    Thank you for reaching out, Please ensure that you are POSTing the correct body request with all of the required fields. You can view our support note HERE which has examples of the mandatory fields for the Bills Attachment endpoint.

  • Viital's avatar
    Viital
    Contributing User
    5 years ago

    Hi Hannah,

     

    I have tried both ways as provided in your link below. Both return the same error.

     

    The first example is what I have been using previously and this has been working fine.

     

    AttachmentArray
      OriginalFileNameString
      FileBase64ContentString

     

    and

     

    {
    "Attachments": [
    {
    "OriginalFileName": "Reece.pdf",
    "FileBase64Content": "J..KJH"
    }
    ]
    }