Chilkat Online Tools

VB.NET / New FreshBooks / Share PDF

Back to Collection Items

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

Dim http As New Chilkat.Http
Dim success As Boolean

Dim queryParams As New Chilkat.JsonObject
queryParams.UpdateString("share_method","share_link")

' Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = "<access_token>"


Dim resp As Chilkat.HttpResponse = http.QuickRequestParams("GET","https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/invoices/{{invoiceId}}/share_link",queryParams)
If (http.LastMethodSuccess = False) Then
    Debug.WriteLine(http.LastErrorText)
    Exit Sub
End If


Dim sbResponseBody As New Chilkat.StringBuilder
resp.GetBodySb(sbResponseBody)

Dim jResp As New Chilkat.JsonObject
jResp.LoadSb(sbResponseBody)
jResp.EmitCompact = False

Debug.WriteLine("Response Body:")
Debug.WriteLine(jResp.Emit())

Dim respStatusCode As Integer = resp.StatusCode
Debug.WriteLine("Response Status Code = " & respStatusCode)
If (respStatusCode >= 400) Then
    Debug.WriteLine("Response Header:")
    Debug.WriteLine(resp.Header)
    Debug.WriteLine("Failed.")

    Exit Sub
End If



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

' {
'   "response": {
'     "result": {
'       "share_link": {
'         "clientid": 31006,
'         "resource_type": "invoice",
'         "resourceid": "34420",
'         "share_link": "https://my.freshbooks.com/#/link/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzeXN0ZW1pZCI6NDIzNjQxMCwiYWNjb3VudGlkIjoid2tNZDJnIiwidXNlcmlkIjozMTAwNiwidHlwZSI6Imludm9pY2UiLCJvYmplY3RpZCI6IjM0NDIwIiwiZXhwIjoxNTg3NjY3NTYxLCJsZXZlbCI6MH0.RorQ5sE8moYrKtGcW3O5JkQhzDYgK9XKoYUuX8PHJbA?type=secondary&share_method=share_link",
'         "share_method": "share_link"
'       }
'     }
'   }
' }

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




Dim Clientid As Integer = jResp.IntOf("response.result.share_link.clientid")
Dim Resource_type As String = jResp.StringOf("response.result.share_link.resource_type")
Dim Resourceid As String = jResp.StringOf("response.result.share_link.resourceid")
Dim Share_link As String = jResp.StringOf("response.result.share_link.share_link")
Dim Share_method As String = jResp.StringOf("response.result.share_link.share_method")

Curl Command

curl -G -d "share_method=share_link"
	-H "Authorization: Bearer <access_token>"
https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/invoices/{{invoiceId}}/share_link

Postman Collection Item JSON

{
  "name": "Share PDF",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/invoices/{{invoiceId}}/share_link?share_method=share_link",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "accounting",
        "account",
        "{{accountId}}",
        "invoices",
        "invoices",
        "{{invoiceId}}",
        "share_link"
      ],
      "query": [
        {
          "key": "share_method",
          "value": "share_link",
          "description": "`share_link`, `email`, `sms`, `pdf` "
        }
      ]
    }
  },
  "response": [
    {
      "name": "Share Link",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/invoices/{{invoiceId}}/share_link?share_method=share_link",
          "protocol": "https",
          "host": [
            "api",
            "freshbooks",
            "com"
          ],
          "path": [
            "accounting",
            "account",
            "{{accountId}}",
            "invoices",
            "invoices",
            "{{invoiceId}}",
            "share_link"
          ],
          "query": [
            {
              "key": "share_method",
              "value": "share_link",
              "description": "`share_link`, `email`, `sms`, `pdf` "
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "X-NewRelic-App-Data",
          "value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gNX0BcCwUGEQoRUANKXVhbXQ4bTQFNA0xUDwBRV1APAgFdU1sEAwZUXR0bAk5EAFoJAFwBDF5WV1AAAARSWRFOAldbEgM+"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Expires",
          "value": "Tue, 24 Apr 2018 18:46:01 GMT"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Via",
          "value": "1.1 google"
        },
        {
          "key": "Via",
          "value": "1.1 varnish"
        },
        {
          "key": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "key": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "key": "Age",
          "value": "0"
        },
        {
          "key": "Age",
          "value": "0"
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Date",
          "value": "Wed, 24 Apr 2019 18:46:01 GMT"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Served-By",
          "value": "cache-mdw17369-MDW"
        },
        {
          "key": "X-Cache",
          "value": "MISS"
        },
        {
          "key": "X-Cache-Hits",
          "value": "0"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Country",
          "value": "CA"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536000; includeSubDomains; preload"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"response\": {\n        \"result\": {\n            \"share_link\": {\n                \"clientid\": 31006,\n                \"resource_type\": \"invoice\",\n                \"resourceid\": \"34420\",\n                \"share_link\": \"https://my.freshbooks.com/#/link/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzeXN0ZW1pZCI6NDIzNjQxMCwiYWNjb3VudGlkIjoid2tNZDJnIiwidXNlcmlkIjozMTAwNiwidHlwZSI6Imludm9pY2UiLCJvYmplY3RpZCI6IjM0NDIwIiwiZXhwIjoxNTg3NjY3NTYxLCJsZXZlbCI6MH0.RorQ5sE8moYrKtGcW3O5JkQhzDYgK9XKoYUuX8PHJbA?type=secondary&share_method=share_link\",\n                \"share_method\": \"share_link\"\n            }\n        }\n    }\n}"
    }
  ]
}