Chilkat Online Tools

DataFlex / New FreshBooks / Add Vendor

Back to Collection Items

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vJson
    Handle hoJson
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sAccount_number
    String sCity
    String sCountry
    String sCreated_at
    String sCurrency_code
    Boolean iIs_1099
    String sLanguage
    String sPhone
    String sPostal_code
    String sPrimary_contact_email
    String sPrimary_contact_first_name
    String sPrimary_contact_last_name
    String sProvince
    String sStreet
    String sStreet2
    String sUpdated_at
    String sVendor_name
    Integer iVendorid
    Integer iVis_state
    String sWebsite
    Integer i
    Integer iCount_i
    String sTemp1
    Boolean bTemp1

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "bill_vendor": {
    //     "vendor_name": "IKEA",
    //     "primary_contact_first_name": "Jimmy",
    //     "primary_contact_last_name": "McNamara",
    //     "primary_contact_email": "jmcnamara@ikea.com",
    //     "primary_contact": null,
    //     "street": "332 Carlton Ave.",
    //     "street2": null,
    //     "city": "San Francisco",
    //     "province": "California",
    //     "postal_code": null,
    //     "country": "United States",
    //     "account_number": "45454545",
    //     "phone": "4158859378",
    //     "website": "ikea.com",
    //     "currency_code": "USD",
    //     "language": "en",
    //     "is_1099": false,
    //     "tax_defaults": [
    //     ]
    //   }
    // }

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get ComUpdateString Of hoJson "bill_vendor.vendor_name" "IKEA" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.primary_contact_first_name" "Jimmy" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.primary_contact_last_name" "McNamara" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.primary_contact_email" "jmcnamara@ikea.com" To iSuccess
    Get ComUpdateNull Of hoJson "bill_vendor.primary_contact" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.street" "332 Carlton Ave." To iSuccess
    Get ComUpdateNull Of hoJson "bill_vendor.street2" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.city" "San Francisco" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.province" "California" To iSuccess
    Get ComUpdateNull Of hoJson "bill_vendor.postal_code" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.country" "United States" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.account_number" "45454545" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.phone" "4158859378" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.website" "ikea.com" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.currency_code" "USD" To iSuccess
    Get ComUpdateString Of hoJson "bill_vendor.language" "en" To iSuccess
    Get ComUpdateBool Of hoJson "bill_vendor.is_1099" False To iSuccess
    Get ComUpdateNewArray Of hoJson "bill_vendor.tax_defaults" To iSuccess

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"

    Get pvComObject of hoJson to vJson
    Get ComPostJson3 Of hoHttp "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors" "application/json" vJson To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "response": {
    //     "result": {
    //       "bill_vendor": {
    //         "account_number": "45454545",
    //         "city": "San Francisco",
    //         "country": "United States",
    //         "created_at": "2020-10-09 15:25:05",
    //         "currency_code": "USD",
    //         "is_1099": false,
    //         "language": "en",
    //         "outstanding_balance": [
    //         ],
    //         "overdue_balance": [
    //         ],
    //         "phone": "4158859378",
    //         "postal_code": null,
    //         "primary_contact_email": "jmcnamara@ikea.com",
    //         "primary_contact_first_name": "Jimmy",
    //         "primary_contact_last_name": "McNamara",
    //         "province": "California",
    //         "street": "332 Carlton Ave.",
    //         "street2": null,
    //         "tax_defaults": [
    //         ],
    //         "updated_at": "2020-10-09 15:25:05",
    //         "vendor_name": "IKEA",
    //         "vendorid": 5,
    //         "vis_state": 0,
    //         "website": "ikea.com"
    //       }
    //     }
    //   }
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    Get ComStringOf Of hoJResp "response.result.bill_vendor.account_number" To sAccount_number
    Get ComStringOf Of hoJResp "response.result.bill_vendor.city" To sCity
    Get ComStringOf Of hoJResp "response.result.bill_vendor.country" To sCountry
    Get ComStringOf Of hoJResp "response.result.bill_vendor.created_at" To sCreated_at
    Get ComStringOf Of hoJResp "response.result.bill_vendor.currency_code" To sCurrency_code
    Get ComBoolOf Of hoJResp "response.result.bill_vendor.is_1099" To iIs_1099
    Get ComStringOf Of hoJResp "response.result.bill_vendor.language" To sLanguage
    Get ComStringOf Of hoJResp "response.result.bill_vendor.phone" To sPhone
    Get ComStringOf Of hoJResp "response.result.bill_vendor.postal_code" To sPostal_code
    Get ComStringOf Of hoJResp "response.result.bill_vendor.primary_contact_email" To sPrimary_contact_email
    Get ComStringOf Of hoJResp "response.result.bill_vendor.primary_contact_first_name" To sPrimary_contact_first_name
    Get ComStringOf Of hoJResp "response.result.bill_vendor.primary_contact_last_name" To sPrimary_contact_last_name
    Get ComStringOf Of hoJResp "response.result.bill_vendor.province" To sProvince
    Get ComStringOf Of hoJResp "response.result.bill_vendor.street" To sStreet
    Get ComStringOf Of hoJResp "response.result.bill_vendor.street2" To sStreet2
    Get ComStringOf Of hoJResp "response.result.bill_vendor.updated_at" To sUpdated_at
    Get ComStringOf Of hoJResp "response.result.bill_vendor.vendor_name" To sVendor_name
    Get ComIntOf Of hoJResp "response.result.bill_vendor.vendorid" To iVendorid
    Get ComIntOf Of hoJResp "response.result.bill_vendor.vis_state" To iVis_state
    Get ComStringOf Of hoJResp "response.result.bill_vendor.website" To sWebsite
    Move 0 To i
    Get ComSizeOfArray Of hoJResp "response.result.bill_vendor.outstanding_balance" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "response.result.bill_vendor.overdue_balance" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Move (i + 1) To i
    Loop

    Move 0 To i
    Get ComSizeOfArray Of hoJResp "response.result.bill_vendor.tax_defaults" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJResp To i
        Move (i + 1) To i
    Loop



End_Procedure

Curl Command

curl -X POST
	-H "Authorization: Bearer <access_token>"
	-d '{
    "bill_vendor": {
        "vendor_name": "IKEA",
        "primary_contact_first_name": "Jimmy",
        "primary_contact_last_name": "McNamara",
        "primary_contact_email": "jmcnamara@ikea.com",
        "primary_contact": null,
        "street": "332 Carlton Ave.",
        "street2": null,
        "city": "San Francisco",
        "province": "California",
        "postal_code": null,
        "country": "United States",
        "account_number": "45454545",
        "phone": "4158859378",
        "website": "ikea.com",
        "currency_code": "USD",
        "language": "en",
        "is_1099": false,
        "tax_defaults": []
    }
}'
https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors

Postman Collection Item JSON

{
  "name": "Add Vendor",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"bill_vendor\": {\n        \"vendor_name\": \"IKEA\",\n        \"primary_contact_first_name\": \"Jimmy\",\n        \"primary_contact_last_name\": \"McNamara\",\n        \"primary_contact_email\": \"jmcnamara@ikea.com\",\n        \"primary_contact\": null,\n        \"street\": \"332 Carlton Ave.\",\n        \"street2\": null,\n        \"city\": \"San Francisco\",\n        \"province\": \"California\",\n        \"postal_code\": null,\n        \"country\": \"United States\",\n        \"account_number\": \"45454545\",\n        \"phone\": \"4158859378\",\n        \"website\": \"ikea.com\",\n        \"currency_code\": \"USD\",\n        \"language\": \"en\",\n        \"is_1099\": false,\n        \"tax_defaults\": []\n    }\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "accounting",
        "account",
        "{{accountId}}",
        "bill_vendors",
        "bill_vendors"
      ]
    }
  },
  "response": [
    {
      "name": "Add Vendor",
      "originalRequest": {
        "method": "POST",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"bill_vendor\": {\n        \"vendor_name\": \"IKEA\",\n        \"primary_contact_first_name\": \"Jimmy\",\n        \"primary_contact_last_name\": \"McNamara\",\n        \"primary_contact_email\": \"jmcnamara@ikea.com\",\n        \"primary_contact\": null,\n        \"street\": \"332 Carlton Ave.\",\n        \"street2\": null,\n        \"city\": \"San Francisco\",\n        \"province\": \"California\",\n        \"postal_code\": null,\n        \"country\": \"United States\",\n        \"account_number\": \"45454545\",\n        \"phone\": \"4158859378\",\n        \"website\": \"ikea.com\",\n        \"currency_code\": \"USD\",\n        \"language\": \"en\",\n        \"is_1099\": false,\n        \"tax_defaults\": []\n    }\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors",
          "protocol": "https",
          "host": [
            "api",
            "freshbooks",
            "com"
          ],
          "path": [
            "accounting",
            "account",
            "{{accountId}}",
            "bill_vendors",
            "bill_vendors"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx"
        },
        {
          "key": "Date",
          "value": "Fri, 09 Oct 2020 15:25:05 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "X-NewRelic-App-Data",
          "value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gGWFpfPRAGDFQNShECWl1eXxNcD1UOQRFGGgdNVk0LBwVTVVUOBQBQXQMOBFNXT1QFUxRACl5RBQRRDwMAVwRbVFJSVkRPXlJcFwQ/"
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "Content-Security-Policy",
          "value": "default-src 'self'"
        },
        {
          "key": "X-Content-Security-Policy",
          "value": "default-src 'self'"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31556926; includeSubDomains; preload"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin-when-cross-origin"
        },
        {
          "key": "X-RateLimit-Limit",
          "value": "600"
        },
        {
          "key": "X-RateLimit-Remaining",
          "value": "599"
        },
        {
          "key": "X-RateLimit-Reset",
          "value": "1602257165"
        },
        {
          "key": "Retry-After",
          "value": "59"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Via",
          "value": "1.1 google"
        },
        {
          "key": "Alt-Svc",
          "value": "h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"response\": {\n        \"result\": {\n            \"bill_vendor\": {\n                \"account_number\": \"45454545\",\n                \"city\": \"San Francisco\",\n                \"country\": \"United States\",\n                \"created_at\": \"2020-10-09 15:25:05\",\n                \"currency_code\": \"USD\",\n                \"is_1099\": false,\n                \"language\": \"en\",\n                \"outstanding_balance\": [],\n                \"overdue_balance\": [],\n                \"phone\": \"4158859378\",\n                \"postal_code\": null,\n                \"primary_contact_email\": \"jmcnamara@ikea.com\",\n                \"primary_contact_first_name\": \"Jimmy\",\n                \"primary_contact_last_name\": \"McNamara\",\n                \"province\": \"California\",\n                \"street\": \"332 Carlton Ave.\",\n                \"street2\": null,\n                \"tax_defaults\": [],\n                \"updated_at\": \"2020-10-09 15:25:05\",\n                \"vendor_name\": \"IKEA\",\n                \"vendorid\": 5,\n                \"vis_state\": 0,\n                \"website\": \"ikea.com\"\n            }\n        }\n    }\n}"
    }
  ]
}