Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Unicode C Web API Examples

Primary Categories

ABN AMRO
AWS Translate
Activix CRM
Adyen
Amazon DynamoDB
Amazon MWS
Amazon Rekognition
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bitfinex v2 REST
Bluzone
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
ETrade
Egypt ITIDA
Etsy
Facebook
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
MedTunnel
MercadoLibre

Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Okta OAuth/OIDC
OneLogin OIDC
OneNote
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
Trello
Twilio
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yousign
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Unicode C) Shopify Private Authentication for Private Apps

Shopify private authentication is for interacting with your own store through private applications. It uses HTTP "Basic" authentication with your Shopify private application key and secret key.

This example demonstrates how to send a private authenticated request using Chilkat Http, and then the same using Chilkat Rest.

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Win Mobile 5.0/Pocket PC 2003

Solaris C/C++

FreeBSD C/C++

OpenBSD C/C++

MinGW C/C++

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

void ChilkatSample(void)
    {
    HCkHttpW http;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbJson;
    HCkJsonObjectW json;
    HCkRestW rest;
    BOOL bTls;
    int port;
    BOOL bAutoReconnect;
    BOOL success;

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

    // First demonstrate sending a simple request using Shopify private authentication w/ the Chilkat Http API.
    http = CkHttpW_Create();

    // To use HTTP Basic Authentication with any HTTP request, we simply set the Login, Password, and BasicAuth properties.
    // Important: All HTTP requests using Basic authentication must be over SSL/TLS.
    CkHttpW_putLogin(http,L"SHOPIFY_PRIVATE_API_KEY");
    CkHttpW_putPassword(http,L"SHOPIFY_PRIVATE_API_SECRET_KEY");
    CkHttpW_putBasicAuth(http,TRUE);

    // Make sure to replace "chilkat" with your store name.
    resp = CkHttpW_QuickGetObj(http,L"https://chilkat.myshopify.com/admin/products.json");
    if (CkHttpW_getLastMethodSuccess(http) != TRUE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        return;
    }

    // Examine the response code.
    if (CkHttpResponseW_getStatusCode(resp) != 200) {
        wprintf(L"Received error response code: %d\n",CkHttpResponseW_getStatusCode(resp));
        wprintf(L"Response body:\n");
        wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        return;
    }

    // Success.
    wprintf(L"Success.\n");

    // Examine the JSON response 
    sbJson = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbJson);
    CkHttpResponseW_Dispose(resp);
    json = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(json,sbJson);
    CkJsonObjectW_putEmitCompact(json,FALSE);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));

    // -------------------------------------------------
    // Now let's do the same using the Chilkat Rest API.
    rest = CkRestW_Create();

    // Provide the private app credentials:
    CkRestW_SetAuthBasic(rest,L"SHOPIFY_PRIVATE_API_KEY",L"SHOPIFY_PRIVATE_API_SECRET_KEY");

    // Connect to the shopify server.
    bTls = TRUE;
    port = 443;
    bAutoReconnect = TRUE;
    // Make sure to replace "chilkat" with your store name.
    success = CkRestW_Connect(rest,L"chilkat.myshopify.com",port,bTls,bAutoReconnect);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbJson);
        CkJsonObjectW_Dispose(json);
        CkRestW_Dispose(rest);
        return;
    }

    CkStringBuilderW_Clear(sbJson);
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/admin/products.json",sbJson);
    if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbJson);
        CkJsonObjectW_Dispose(json);
        CkRestW_Dispose(rest);
        return;
    }

    if (CkRestW_getResponseStatusCode(rest) != 200) {
        wprintf(L"Received error response code: %d\n",CkRestW_getResponseStatusCode(rest));
        wprintf(L"Response body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbJson));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sbJson);
        CkJsonObjectW_Dispose(json);
        CkRestW_Dispose(rest);
        return;
    }

    // Success...
    CkJsonObjectW_LoadSb(json,sbJson);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));


    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sbJson);
    CkJsonObjectW_Dispose(json);
    CkRestW_Dispose(rest);

    }

 

© 2000-2021 Chilkat Software, Inc. All Rights Reserved.