Chilkat Online Tools

C# / New FreshBooks / List Items Filtered by SKU

Back to Collection Items

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

Chilkat.Http http = new Chilkat.Http();
bool success;

Chilkat.JsonObject queryParams = new Chilkat.JsonObject();
queryParams.UpdateString("search[sku]","{{sku}}");

// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = "<access_token>";
http.SetRequestHeader("Content-Type","application/json");

Chilkat.HttpResponse resp = http.QuickRequestParams("GET","https://api.freshbooks.com/accounting/account/{{accountId}}/items/items",queryParams);
if (http.LastMethodSuccess == false) {
    Debug.WriteLine(http.LastErrorText);
    return;
}

Debug.WriteLine(Convert.ToString(resp.StatusCode));
Debug.WriteLine(resp.BodyStr);

Curl Command

curl -G -d "search[sku]=%7B%7Bsku%7D%7D"
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
https://api.freshbooks.com/accounting/account/{{accountId}}/items/items

Postman Collection Item JSON

{
  "name": "List Items Filtered by SKU",
  "event": [
    {
      "listen": "test",
      "script": {
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "pm.environment.set(\"itemId\", jsonData.response.result.items[5].id);",
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "protocolProfileBehavior": {
    "disableBodyPruning": true
  },
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "type": "text",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": ""
    },
    "url": {
      "raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/items/items?search%5Bsku%5D={{sku}}",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "accounting",
        "account",
        "{{accountId}}",
        "items",
        "items"
      ],
      "query": [
        {
          "key": "search%5Bsku%5D",
          "value": "{{sku}}"
        }
      ]
    },
    "description": "Returns an exact match of the searched SKU"
  },
  "response": [
  ]
}