Forum Discussion

Mo_JM's avatar
Mo_JM
Contributing User
4 months ago

Help with POST

Hi all. I'm new to APIs. I've got my keys and access to a Sandbox, and can now successfully GET information. I'm using Thunder client on VS Code. Now it's time for me to try to POST something. I'm trying to add an Invoice for Services Rendered to Acme Dynamite Co. for $50.00 on 1/9/24. However, because I don't yet know the correct syntax in the Body, I'm getting error 400 Bad Request, and I don't know what part is Bad, so I don't know what to fix. Would it be possible for someone to show me the correct syntax in the Body for this request to be successful?

  • Mike_James's avatar
    Mike_James
    Ultimate Cover User

    Hi Mo_JM , have a look at the endpoint documentation here: Service (myob.com) - (I'm assuming you are posting a service invoice) there are a number of mandatory fields.

  • Mo_JM's avatar
    Mo_JM
    Contributing User

    Edit: I looked at the Postman Collection to see if I could glean anything. I'm using the following code in Body:

    {
      "Number":"SC0007",
      "Date":"2024-09-01",
      "Status":"Open",
      "Customer":{
        "UID":"{{Acme_UID}}"
    },
    "Total":50,
        "Description":"For Services Rendered",
        "Account":{
          "UID":"{{Sandbox_TaxCodeURI_GST}}"
     }
    }

    I can successfully POST the request, and it is in my Sandbox. However, the amount is nil, there is no sales account, and it shows as closed. Would someone be kind enough to show me what else I need?

    • Will_H's avatar
      Will_H
      MYOB Moderator

      Hi Mo_JM ,

      I'm not from that part of the company, but incase it helps the specific part of the postman collection relating to this is here:
      https://accountrightapi.myob.cloud/?version=latest#148bd100-5918-46df-8656-2fbfa7b29cb8

      The example there is:

      {
          "Number": "PSMN0001",
          "Date": "2018-09-02T00:00:00",
          "SupplierInvoiceNumber": null,
          "Customer": {
      		"UID": "dde4659b-7bb3-4ef7-9312-c13b2fa02f58"
      	},
          "ShipToAddress": "Somewhere Over, The Rainbow",
          "Terms": {
              "PaymentIsDue": "DayOfMonthAfterEOM",
              "DiscountDate": 1,
              "BalanceDueDate": 30,
              "DiscountForEarlyPayment": 0,
              "MonthlyChargeForLatePayment": 0,
              "DiscountExpiryDate": "2018-03-01T00:00:00",
              "Discount": 0,
              "DueDate": "2018-03-30T00:00:00"
          },
          "IsTaxInclusive": true,
          "IsReportable": false,
          "Lines": [
              {
                  "Type": "Transaction",
                  "Description": "Postman Sample Update",
                  "Account": {
                      "UID": "ce84af88-225a-4e85-9674-8c269d78d6ca"
                  },
                  "Total": -1200256,
                  "Job": null,
                  "TaxCode": {
                      "UID": "56dd406b-0dcc-4110-bedf-b8a7f778450f"
                  }
              }
          ],
          "Subtotal": -1200256,
          "Freight": 0,
          "FreightTaxCode": {
              "UID": "e4b03cbc-a1aa-4fe0-92a2-bc34530e1fc3"
          },
          "TotalTax": -109114.18,
          "TotalAmount": -1200256,
          "Category": null,
          "Comment": "",
          "ShippingMethod": null,
          "PromisedDate": "2018-10-02T00:00:00",
          "JournalMemo": "Postman sample service",
          "BillDeliveryStatus": "Print",
          "AppliedToDate": 0,
          "BalanceDueAmount": -1200256,
          "Status": "Open",
          "LastPaymentDate": null,
          "Order": null,
          "ForeignCurrency": null
      }

       

      I would expect that you need to enter the following:

      • TotalAmount
      • Subtotal
      • TotalTax
      • BalanceDueAmount
      • Status
      • AppliedToDate
      • At least 1 Line