Chilkat Online Tools

unicodeC / New FreshBooks / Modify existing application

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;

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

    http = CkHttpW_Create();

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

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

    // {
    //   "name": "<app_name>",
    //   "client_secret": "<app client secret>",
    //   "redirect_uri": "<app redirect uri>",
    //   "description": "<app descripttion>",
    //   "website_url": "<link to app website>",
    //   "settings_url": "<link to app settings>",
    //   "logo_public_id": "<jwt returned from post https://api.freshbooks.com/uploads/images>"
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"name",L"<app_name>");
    CkJsonObjectW_UpdateString(json,L"client_secret",L"<app client secret>");
    CkJsonObjectW_UpdateString(json,L"redirect_uri",L"<app redirect uri>");
    CkJsonObjectW_UpdateString(json,L"description",L"<app descripttion>");
    CkJsonObjectW_UpdateString(json,L"website_url",L"<link to app website>");
    CkJsonObjectW_UpdateString(json,L"settings_url",L"<link to app settings>");
    CkJsonObjectW_UpdateString(json,L"logo_public_id",L"<jwt returned from post https://api.freshbooks.com/uploads/images>");

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");
    CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PUT",L"https://api.freshbooks.com/auth/api/v1/partners/applications/<app_client_id>",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);

    }

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{ 
   "name": "<app_name>",
   "client_secret":"<app client secret>",
   "redirect_uri":"<app redirect uri>",
   "description":"<app descripttion>",
   "website_url":"<link to app website>",
   "settings_url":"<link to app settings>",
   "logo_public_id":"<jwt returned from post https://api.freshbooks.com/uploads/images>"
}'
https://api.freshbooks.com/auth/api/v1/partners/applications/<app_client_id>

Postman Collection Item JSON

{
  "name": "Modify existing application",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{ \n   \"name\": \"<app_name>\",\n   \"client_secret\":\"<app client secret>\",\n   \"redirect_uri\":\"<app redirect uri>\",\n   \"description\":\"<app descripttion>\",\n   \"website_url\":\"<link to app website>\",\n   \"settings_url\":\"<link to app settings>\",\n   \"logo_public_id\":\"<jwt returned from post https://api.freshbooks.com/uploads/images>\"\n}"
    },
    "url": {
      "raw": "https://api.freshbooks.com/auth/api/v1/partners/applications/<app_client_id>",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "auth",
        "api",
        "v1",
        "partners",
        "applications",
        "<app_client_id>"
      ]
    }
  },
  "response": [
  ]
}