Failed to parse JSON request content
Hi Guys,
I'm using the below code to Post JSON request to a REST API, but I'm getting "Failed to parse JSON request content." Error,
Set Body = ##class(%ZEN.proxyObject).%New() Set Body.ElectronicMailAddressT = "ElectronicMailAddressT" Set Body.TelephoneMinimalN = "TelephoneMinimalN" Set Body.AustralianBusinessNumberId = "AustralianBusinessNumberId" Set Body.OrganisationDetailsOrganisationBranchC = "OrganisationDetailsOrganisationBranchC" Set Body.DetailsOrganisationalNameT = "DetailsOrganisationalNameT" Set Body.PersonUnstructuredNameFullNameT = "PersonUnstructuredNameFullNameT" Set Body.Line1T = "Line1T" Set Body.Line2T = "Line2T" Set Body.LocalityNameT = "LocalityNameT" Set Body.PostcodeT = "PostcodeT" Set Body.CountryC = "CountryC" Set Body.PayAsYouGoWithholdingTaxWithheldA = 0.1 Set Body.TotalGrossPaymentsWithholdingA = 0.1 Set Body.PaymentRecordTransactionD = "PaymentRecordTransactionD" Set Body1 = ##class(%ZEN.proxyObject).%New() Set Body1.IndividualNonBusinessEmploymentAllowancesA = 0.1 Set Body1.AllowanceTypeTypeC = "AllowanceTypeTypeC" Set Body1.OtherAllowanceTypeDe = "OtherAllowanceTypeDe" Set Body1.DeductionTypeTypeC = "DeductionTypeTypeC" Set Body1.DeductionTypeC = 0.1 Set Body1.EmploymentPayrollNumberId = "EmploymentPayrollNumberId" Set Body1.TaxFileNumberId = "TaxFileNumberId" Set Body1.FamilyNameT = "FamilyNameT" Set Body1.GivenNameT = "GivenNameT" Set Body1.OtherGivenNameT = "OtherGivenNameT" Set Body1.BirthDate = "2014-01-11" Set Body1.Line1T = "Line1T" Set Body1.Line2T = "Line2T" Set Body1.LocalityNameT = "LocalityNameT" Set Body1.StateOrTerritoryC = "StateOrTerritoryC" Set Body1.PostcodeT = "PostcodeT" Set Body1.CountryC = "CountryC" Set Body1.EmploymentStartD = "2014-01-11" Set Body1.EmploymentEndD = "2014-01-11" Set Body1.ElectronicMailAddressT = "ElectronicMailAddressT" Set Body1.TelephoneMinimalN = "TelephoneMinimalN" Set Body1.EmployerReportableA = 0.1 Set Body1.OrdinaryTimeEarningsA = 0.1 Set Body1.EmployerContributionsSuperannuationGuaranteeA = 0.1 Set Body1.LabourHireTaxWithheldA = 0.1 Set Body1.ExemptIncomeFringeBenefitsReportableA = 0.1 Set Body1.TaxableIncomeFringeBenefitsReportableA = 0.1 Set Body1.INBTaxWithheldA = 0.1 Set Body1.INBGrossA = 0.1 Set Body1.ExemptForeignEmploymentIncomeA = 0.1 Set Body1.CommunityDevelopmentEmploymentProjectA = 0.1 Set Body1.LumpSumBA = 0.1 Set Body1.LumpSumDA = 0.1 Set Body1.LumpSumEA = 0.1 Set Body1.WorkingHolidayGrossA = 0.1 Set Body1.WorkingHolidayTaxWithheldA = 0.1 Set Body1.LumpSumAA = 0.1 Set Body1.LumpSumAC = 0.1 Set Body1.WorkingHolidayGrossA = 0.1 Set Body2 = ##class(%ZEN.proxyObject).%New() Set Body2.TaxWithheldA = 0.1 Set Body2.SuperannuationTaxFreeComponentA = 0.1 Set Body2.SuperannuationEmploymentTerminationTaxableComponentTotalA = 0.1 Set Body2.PaymentRecordPaymentEffectiveD = "2014-01-11" Set Body2.EmploymentTerminationPaymentTypeC = "EmploymentTerminationPaymentTypeC" Set TerminationPaymentSummary = ##class(%ListOfDataTypes).%New() Do TerminationPaymentSummary.Insert(Body2) Set Body1.TerminationPaymentSummary = TerminationPaymentSummary Set Payee = ##class( %ListOfDataTypes).%New() Do Payee.Insert(Body1) Set Body.Payee = Payee Set Request= ##class(%Net.HttpRequest).%New() //D Body.%ToJSON() Set Request.Server = "server" Set Request.Location = "location" Set Request.ContentType = "application/json" D Request.SetHeader("Source","Civicview") D Request.SetHeader("PayrollStartDate","2017-01-11") D Request.SetHeader("PayrollEndDate","2017-02-12") Set Request.Https=1 Set Request.SSLConfiguration="TLS" Set Status = ##class(%ZEN.Auxiliary.jsonProvider).%WriteJSONStreamFromObject(Request.EntityBody, Body) Set Status = Request.Post(,2) I Status W !, "Request Sent"
My code is generating this JSON request:
{ "AustralianBusinessNumberId":"AustralianBusinessNumberId", "CountryC":"CountryC", "DetailsOrganisationalNameT":"DetailsOrganisationalNameT", "ElectronicMailAddressT":"ElectronicMailAddressT", "Line1T":"Line1T", "Line2T":"Line2T", "LocalityNameT":"LocalityNameT", "OrganisationDetailsOrganisationBranchC":"OrganisationDetailsOrganisationBranchC", "PayAsYouGoWithholdingTaxWithheldA":0.1, "Payee":[ { "AllowanceTypeTypeC":"AllowanceTypeTypeC", "BirthDate":"2014-01-11", "CommunityDevelopmentEmploymentProjectA":0.1, "CountryC":"CountryC", "DeductionTypeC":0.1, "DeductionTypeTypeC":"DeductionTypeTypeC", "ElectronicMailAddressT":"ElectronicMailAddressT", "EmployerContributionsSuperannuationGuaranteeA":0.1, "EmployerReportableA":0.1, "EmploymentEndD":"2014-01-11", "EmploymentPayrollNumberId":"EmploymentPayrollNumberId", "EmploymentStartD":"2014-01-11", "ExemptForeignEmploymentIncomeA":0.1, "ExemptIncomeFringeBenefitsReportableA":0.1, "FamilyNameT":"FamilyNameT", "GivenNameT":"GivenNameT", "INBGrossA":0.1, "INBTaxWithheldA":0.1, "IndividualNonBusinessEmploymentAllowancesA":0.1, "LabourHireTaxWithheldA":0.1, "Line1T":"Line1T", "Line2T":"Line2T", "LocalityNameT":"LocalityNameT", "LumpSumAA":0.1, "LumpSumAC":0.1, "LumpSumBA":0.1, "LumpSumDA":0.1, "LumpSumEA":0.1, "OrdinaryTimeEarningsA":0.1, "OtherAllowanceTypeDe":"OtherAllowanceTypeDe", "OtherGivenNameT":"OtherGivenNameT", "PostcodeT":"PostcodeT", "StateOrTerritoryC":"StateOrTerritoryC", "TaxFileNumberId":"TaxFileNumberId", "TaxableIncomeFringeBenefitsReportableA":0.1, "TelephoneMinimalN":"TelephoneMinimalN", "TerminationPaymentSummary":[ { "EmploymentTerminationPaymentTypeC":"EmploymentTerminationPaymentTypeC", "PaymentRecordPaymentEffectiveD":"2014-01-11", "SuperannuationEmploymentTerminationTaxableComponentTotalA":0.1, "SuperannuationTaxFreeComponentA":0.1, "TaxWithheldA":0.1 } ], "WorkingHolidayGrossA":0.1, "WorkingHolidayTaxWithheldA":0.1 } ], "PaymentRecordTransactionD":"PaymentRecordTransactionD", "PersonUnstructuredNameFullNameT":"PersonUnstructuredNameFullNameT", "PostcodeT":"PostcodeT", "TelephoneMinimalN":"TelephoneMinimalN", "TotalGrossPaymentsWithholdingA":0.1 }
But the REST API is expecting this JSON request:
{ "ElectronicMailAddressT": "string", "TelephoneMinimalN": "string", "AustralianBusinessNumberId": "string", "OrganisationDetailsOrganisationBranchC": "string", "DetailsOrganisationalNameT": "string", "PersonUnstructuredNameFullNameT": "string", "Line1T": "string", "Line2T": "string", "LocalityNameT": "string", "StateOrTerritoryC": "string", "PostcodeT": "string", "CountryC": "string", "PayAsYouGoWithholdingTaxWithheldA": 0.1, "TotalGrossPaymentsWithholdingA": 0.1, "PaymentRecordTransactionD": "2014-12-31", "Payee": [ { "IndividualNonBusinessEmploymentAllowancesA": 0.1, "AllowanceTypeTypeC": "string", "OtherAllowanceTypeDe": "string", "DeductionTypeTypeC": "string", "DeductionTypeC": 0.1, "EmploymentPayrollNumberId": "string", "TaxFileNumberId": "string", "FamilyNameT": "string", "GivenNameT": "string", "OtherGivenNameT": "string", "BirthDate": "2014-12-31", "Line1T": "string", "Line2T": "string", "LocalityNameT": "string", "StateOrTerritoryC": "string", "PostcodeT": "string", "CountryC": "string", "EmploymentStartD": "2014-12-31", "EmploymentEndD": "2014-12-31", "ElectronicMailAddressT": "string", "TelephoneMinimalN": "string", "EmployerReportableA": 0.1, "OrdinaryTimeEarningsA": 0.1, "EmployerContributionsSuperannuationGuaranteeA": 0.1, "LabourHireTaxWithheldA": 0.1, "ExemptIncomeFringeBenefitsReportableA": 0.1, "TaxableIncomeFringeBenefitsReportableA": 0.1, "INBTaxWithheldA": 0.1, "INBGrossA": 0.1, "ExemptForeignEmploymentIncomeA": 0.1, "CommunityDevelopmentEmploymentProjectA": 0.1, "LumpSumBA": 0.1, "LumpSumDA": 0.1, "LumpSumEA": 0.1, "WorkingHolidayGrossA": 0.1, "WorkingHolidayTaxWithheldA": 0.1, "LumpSumAA": 0.1, "LumpSumAC": "string", "TerminationPaymentSummary": [ { "TaxWithheldA": 0.1, "SuperannuationTaxFreeComponentA": 0.1, "SuperannuationEmploymentTerminationTaxableComponentTotalA": 0.1, "PaymentRecordPaymentEffectiveD": "2014-12-31", "EmploymentTerminationPaymentTypeC": "string" } ] } ] }
I validated both JSON requests and they validate OK
The only difference I can see is the Comma after the array "]," in my request, so i'm not sure if that's the reason and hwo to fix it?
Thanks Guys and sorry for the long message but I wanted to give you the full picture.