MYOBCommunity
Partner Zone
|
|
Partner Zone

This might help a newbie creating contacts via the API

3 REPLIES
Trusted Partner Triboss
44 Posts
Trusted Partner
Triboss
Trusted Partner

44Posts

25Kudos

3Solutions

Re: This might help a newbie creating contacts via the API

Why are you using the v1 of the API instead of v2?

 

If you are using v2, you need to pass the GUID of things like Tax Code and not the old "ID".

Experienced Partner Paul_ONeill
12 Posts
Experienced Partner
Australia
Paul_ONeill
Experienced Partner

12Posts

1Kudos

0Solutions

Re: This might help a newbie creating contacts via the API

I managed to get things working by adding x-myobapi-version: v1 to my header but it doesn't insert my contact's address so I'm looking at v2.(but at least I know how to successfully POST to the API).

 

My posted JSON data looks like this:

 

{
  "CoLastName": "ACME ENGINEERING",
  "Addresses": [
    {
      "Location": 1,
      "Street": "16 Notreal Street",
      "City": "Perth",
      "State": "WA",
      "Postcode": "6000",
      "Country": "Australia",
      "Phone1": null,
      "Fax": null
    }
  ],
  "ABN": null,
  "FirstName": "",
  "LastName": "",
  "IsIndividual": false,
  "TaxCode": {
    "Code": "GST"
  },
  "FreightTaxCode": {
    "Code": "GST"
  },
  "DisplayID": null
}

 

And now I'm back to the ubiquitous 400 Bad Request error.

 

Is there any way to get more information from the failed request?

 

FWIW: I'm using POST requests from a VB app (because I'm using design pattersn not hard coding) and so it "catches" a WebException object but I cant see how to get any more information about the error.

 

Does the API even send back any more data??

 

TIA

Paul

Trusted Partner Triboss
44 Posts
Trusted Partner
Triboss
Trusted Partner

44Posts

25Kudos

3Solutions

Re: This might help a newbie creating contacts via the API

Are you adding:

x-myobapi-version: v2 to your auth header?

 

http://developer.myob.com/api/accountright/api-overview/headers/

Experienced Partner Paul_ONeill
12 Posts
Experienced Partner
Australia
Paul_ONeill
Experienced Partner

12Posts

1Kudos

0Solutions

This might help a newbie creating contacts via the API

Hi all

 

This is not a bug - it is for informational purposes only. If there is a beytter spot then please move it. Smiley Happy

 

I was trying to create a new Customer Card in a local MYOB file (only on the desktop) via the API.

 

My POST request body has the following JSON string in it:

 

{"FirstName":"Aubert","LastName":"Bisco","Street":"21702 Morning Center","City":"Hobart","State":"TAS","PostCode":7803,"Country":"Australia","IsIndividual":true,"TaxCode":"GST","FreightCode":"GST"}

 

I get a status code of  400 - Bad Request and the JSON error text I get back is:

{
  "Errors": [
    {
      "Name": "ValidationError",
      "Message": "CommonRules_StringRequired",
      "AdditionalDetails": "Name",
      "ErrorCode": 1000,
      "Severity": "Error",
      "LearnMore": null
    },
    {
      "Name": "ValidationError",
      "Message": "Card_TaxCodeIsNull",
      "AdditionalDetails": "TaxCodeId",
      "ErrorCode": 2543,
      "Severity": "Error",
      "LearnMore": null
    },
    {
      "Name": "ValidationError",
      "Message": "Card_FreightTaxCodeIsNull",
      "AdditionalDetails": "FreightTaxCodeId",
      "ErrorCode": 2613,
      "Severity": "Error",
      "LearnMore": null
    }
  ],
  "Information": "Warning, error messages have not been finalised in this release and may change"
}

 

Now according to the documentation here http://developer.myob.com/api/accountright/v2/contact/customer/ TaxCode and FreightTaxCode should be GUIDs but I cannot see how to get the GUIDs.

 

 

So it turns out that maybe I'm not using the v2 APIs even though I have just downloaded MYOB 2018.2 in the last few weeks so on a hunch I change FirstName to CoFirstName, TaxCode to TaxCodeId and FreightCode to FreightTaxCodeId and voila - it worked! Status 201!!! Huzzah!

 

And the way I determined this was to go to http://localhost:8080/AccountRight/{{my-file-guid}}/Contact/Customer/ and look at the column headings.

 

As soon as my code matched the column headings it all worked.

 

The only question I have is: what version API am I running if it's not v2 because the documentation and my short experience with this new API do not match...

 

Hope this helps someone else who's "chasing their tail" trying to figure stuff out...

 

Regards

Paul

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