Chilkat Online Tools

Android / New FreshBooks / Share PDF

Back to Collection Items

// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    CkHttp http = new CkHttp();
    boolean success;

    CkJsonObject queryParams = new CkJsonObject();
    queryParams.UpdateString("share_method","share_link");

    // Adds the "Authorization: Bearer <access_token>" header.
    http.put_AuthToken("<access_token>");

    CkHttpResponse resp = http.QuickRequestParams("GET","https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/invoices/{{invoiceId}}/share_link",queryParams);
    if (http.get_LastMethodSuccess() == false) {
        Log.i(TAG, http.lastErrorText());
        return;
        }

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    resp.GetBodySb(sbResponseBody);

    CkJsonObject jResp = new CkJsonObject();
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    Log.i(TAG, "Response Body:");
    Log.i(TAG, jResp.emit());

    int respStatusCode = resp.get_StatusCode();
    Log.i(TAG, "Response Status Code = " + String.valueOf(respStatusCode));
    if (respStatusCode >= 400) {
        Log.i(TAG, "Response Header:");
        Log.i(TAG, resp.header());
        Log.i(TAG, "Failed.");

        return;
        }

    // 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

    int Clientid = jResp.IntOf("response.result.share_link.clientid");
    String Resource_type = jResp.stringOf("response.result.share_link.resource_type");
    String Resourceid = jResp.stringOf("response.result.share_link.resourceid");
    String Share_link = jResp.stringOf("response.result.share_link.share_link");
    String Share_method = jResp.stringOf("response.result.share_link.share_method");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

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