Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Objective-C Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
JCC Cyprus
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois

Mastercard
MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(Objective-C) Egyptian eReceipt OAuth2 Client Credentials

See more Egypt eReceipt Examples

Get an OAuth2 access token for the Egyptian eReceipt REST API using client credentials (no interactivity with a web browser required).

For more information, see https://sdk.invoicing.eta.gov.eg/ereceiptapi/01-authenticate-pos/

Chilkat Objective-C Library Downloads

MAC OS X (Cocoa) Libs

iOS Libs

#import <CkoHttp.h>
#import <CkoHttpRequest.h>
#import <CkoHttpResponse.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>

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

CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;

// Note: Any provider of a REST API, such as the Egyptian government in this case, can make life 
// much easier for developers by providing one or more of the following in the API documentation:
// 
// 1) A sample CURL statement for each API call.
// 2) A Postman collection, or Swagger/OpenAPI specification file.
// 3) A sample of a raw HTTP request and response for each API call.
// 
// The sample CURL statements or raw HTTP request/responses do not need to comprehensively show all 
// possible options.  Providing a sample allows one to quickly make a successful API call.
// It also allows for code generation directly from the CURL, Postman collection, or raw request/response,
// and it tends to answer all questions about the format/structure of a request that, suprisingly,
// remain ambiguous or not obvious in other forms of documentation.

CkoHttpRequest *req = [[CkoHttpRequest alloc] init];
[req AddParam: @"grant_type" value: @"client_credentials"];
// Use your actual client ID and client secret...
[req AddParam: @"client_id" value: @"d0394a9f-0607-40de-a978-2d3eb8375b04"];
[req AddParam: @"client_secret" value: @"6d62315e-d65a-4e41-9112-4195ea834edf"];

[req AddHeader: @"posserial" value: @"1234567899"];
[req AddHeader: @"pososversion" value: @"os"];
[req AddHeader: @"posmodelframework" value: @"1"];
[req AddHeader: @"presharedkey" value: @"03ac674216f3e1..."];

// When writing this example, the documentation at https://sdk.invoicing.eta.gov.eg/ereceiptapi/01-authenticate-pos/
// shows us the HTTP verb and path (POST /connect/token), however,
// we don't see the actual domain where the request is to be sent.
// What are the endpoints???
// It took some searching, but we found some endpoints here:  https://sdk.invoicing.eta.gov.eg/faq/
// It's not immediately apparent which endpoint is to be used with a given API call.
// Why not just include the endpoint in the documentation for each REST API call?
// Endpoints are literally the #1 thing that needs to be known.
// They can't just be buried in a FAQ.  They should be up-front and obvious.
// 
// So.. we're guessing the endpoint is likely "https://invoicing.eta.gov.eg/connect/token"
CkoHttpResponse *resp = [http PostUrlEncoded: @"https://invoicing.eta.gov.eg/connect/token" req: req];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
[resp GetBodySb: sbResponseBody];

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[jResp LoadSb: sbResponseBody];
jResp.EmitCompact = NO;

NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[jResp Emit]);

int respStatusCode = [resp.StatusCode intValue];
NSLog(@"%@%d",@"Response Status Code = ",respStatusCode);
if (respStatusCode >= 400) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",resp.Header);
    NSLog(@"%@",@"Failed.");

    return;
}

// If successful, the OAuth2 access token JSON looks like this:

// {
//   "token_type": "Bearer",
//   "access_token": "eyJraW......R2sbqrY",
//   "expires_in": "3600",
//   "scope": "..."
// }

NSString *token_type = [jResp StringOf: @"token_type"];
NSString *access_token = [jResp StringOf: @"access_token"];
NSString *expires_in = [jResp StringOf: @"expires_in"];
NSString *scope = [jResp StringOf: @"scope"];
 

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