Chilkat Online Tools

TCL / New FreshBooks / Add Vendor

Back to Collection Items

load ./chilkat.dll

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

set http [new_CkHttp]

# 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": [
#     ]
#   }
# }

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "bill_vendor.vendor_name" "IKEA"
CkJsonObject_UpdateString $json "bill_vendor.primary_contact_first_name" "Jimmy"
CkJsonObject_UpdateString $json "bill_vendor.primary_contact_last_name" "McNamara"
CkJsonObject_UpdateString $json "bill_vendor.primary_contact_email" "jmcnamara@ikea.com"
CkJsonObject_UpdateNull $json "bill_vendor.primary_contact"
CkJsonObject_UpdateString $json "bill_vendor.street" "332 Carlton Ave."
CkJsonObject_UpdateNull $json "bill_vendor.street2"
CkJsonObject_UpdateString $json "bill_vendor.city" "San Francisco"
CkJsonObject_UpdateString $json "bill_vendor.province" "California"
CkJsonObject_UpdateNull $json "bill_vendor.postal_code"
CkJsonObject_UpdateString $json "bill_vendor.country" "United States"
CkJsonObject_UpdateString $json "bill_vendor.account_number" "45454545"
CkJsonObject_UpdateString $json "bill_vendor.phone" "4158859378"
CkJsonObject_UpdateString $json "bill_vendor.website" "ikea.com"
CkJsonObject_UpdateString $json "bill_vendor.currency_code" "USD"
CkJsonObject_UpdateString $json "bill_vendor.language" "en"
CkJsonObject_UpdateBool $json "bill_vendor.is_1099" 0
CkJsonObject_UpdateNewArray $json "bill_vendor.tax_defaults"

# Adds the "Authorization: Bearer <access_token>" header.
CkHttp_put_AuthToken $http "<access_token>"

# resp is a CkHttpResponse
set resp [CkHttp_PostJson3 $http "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors" "application/json" $json]
if {[CkHttp_get_LastMethodSuccess $http] == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $json
    exit
}

set sbResponseBody [new_CkStringBuilder]

CkHttpResponse_GetBodySb $resp $sbResponseBody

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttpResponse_header $resp]
    puts "Failed."
    delete_CkHttpResponse $resp

    delete_CkHttp $http
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

delete_CkHttpResponse $resp

# 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

set Account_number [CkJsonObject_stringOf $jResp "response.result.bill_vendor.account_number"]
set City [CkJsonObject_stringOf $jResp "response.result.bill_vendor.city"]
set Country [CkJsonObject_stringOf $jResp "response.result.bill_vendor.country"]
set Created_at [CkJsonObject_stringOf $jResp "response.result.bill_vendor.created_at"]
set Currency_code [CkJsonObject_stringOf $jResp "response.result.bill_vendor.currency_code"]
set Is_1099 [CkJsonObject_BoolOf $jResp "response.result.bill_vendor.is_1099"]
set Language [CkJsonObject_stringOf $jResp "response.result.bill_vendor.language"]
set Phone [CkJsonObject_stringOf $jResp "response.result.bill_vendor.phone"]
set Postal_code [CkJsonObject_stringOf $jResp "response.result.bill_vendor.postal_code"]
set Primary_contact_email [CkJsonObject_stringOf $jResp "response.result.bill_vendor.primary_contact_email"]
set Primary_contact_first_name [CkJsonObject_stringOf $jResp "response.result.bill_vendor.primary_contact_first_name"]
set Primary_contact_last_name [CkJsonObject_stringOf $jResp "response.result.bill_vendor.primary_contact_last_name"]
set Province [CkJsonObject_stringOf $jResp "response.result.bill_vendor.province"]
set Street [CkJsonObject_stringOf $jResp "response.result.bill_vendor.street"]
set Street2 [CkJsonObject_stringOf $jResp "response.result.bill_vendor.street2"]
set Updated_at [CkJsonObject_stringOf $jResp "response.result.bill_vendor.updated_at"]
set Vendor_name [CkJsonObject_stringOf $jResp "response.result.bill_vendor.vendor_name"]
set Vendorid [CkJsonObject_IntOf $jResp "response.result.bill_vendor.vendorid"]
set Vis_state [CkJsonObject_IntOf $jResp "response.result.bill_vendor.vis_state"]
set Website [CkJsonObject_stringOf $jResp "response.result.bill_vendor.website"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "response.result.bill_vendor.outstanding_balance"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "response.result.bill_vendor.overdue_balance"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "response.result.bill_vendor.tax_defaults"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}

delete_CkHttp $http
delete_CkJsonObject $json
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp

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}"
    }
  ]
}