Jump to content

Recommended Posts

Posted

Thank you in advance for your help with this!

Hi we have just started using the Sage API and were able to create a customer. However, when we attempt to populate the address and contact info we get a "MalformedRequestBody" error. I think the syntax is correct and all of the PHP variables contain the appropriate data, so I'm thinking there must be a required field that is missing such as "type ID" or some other required field. here is the block of code that is causing the error:

                CURLOPT_POSTFIELDS => '{
              "contact": {
                "name": "' . $company . '",
                "contact_type_ids": [
                  "Customer"
                ],
                "main_address": {
                  "address_line_1": "' . $street1 . '",
                  "address_line_2": "' . $street2 . '",
                  "city": "' . $city . '",
                  "postal_code": "' . $zip . '",
                  "region": "' . $state . '",
                  "is_main_address": true
                },
                "delivery_address": {
                  "address_line_1": "' . $street1 . '",
                  "address_line_2": "' . $street2 . '",
                  "city": "' . $city . '",
                  "postal_code": "' . $zip . '",
                  "region": "' . $state . '",
                  "is_main_address": false
                },
                "main_contact_person": {
                  "name": "' . $firstname . ' ' . $lastname . '",
                  "job_title": "' . $title . '",
                  "telephone": "' . $phone . '",
                  "mobile": "' . $mobile . '",
                  "email": "' . $email . '",
                  "is_preferred_contact": true
              }
            }',

Posted

i added country_group_id with a value of "US" to the two address blocks.. not sure if this was required or correct.. but still no luck

(example below)

 

                "main_address": {
                  "contact_id": "' . $custObj->contact_id . '",
                  "address_line_1": "' . $street1 . '",
                  "address_line_2": "' . $street2 . '",
                  "city": "' . $city . '",
                  "postal_code": "' . $zip . '",
                  "region": "' . $state . '",
                  "country_group_id": "' . 'US' . '",
                  "is_main_address": true
                },

Posted

any advice from anyone?  the syntax seems great and the variables are all properly filled with correct data and data types. it has to be a required field or some other technicality i think...  anyone?

Posted

PROBLEM SOLVED!  -- Thank you everyone who spent any time reviewing turns out I was (ugh) missing a closing bracket on an array element, and also missing TWO required fields as part of each address:

                "address_type_id": "ACCOUNTS",
                "name": "Main Address",

Ok, live and learn...  closing this topic...  thanks again.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...