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

PowerBuilder 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
Jira
Lightspeed
MYOB
Magento
Mailgun

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
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
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

 

 

 

(PowerBuilder) Create Restricted Data Token (RDT)

See more Amazon SP-API Examples

Returns a Restricted Data Token (RDT) for one or more restricted resources that you specify.

For more information, see https://developer-docs.amazon.com/sp-api/docs/tokens-api-v2021-03-01-reference#post-tokens2021-03-01restricteddatatoken

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
oleobject loo_AuthAws
oleobject loo_Rest
integer li_BTls
integer li_Port
integer li_BAutoReconnect
integer li_Success
oleobject loo_JsonToken
string ls_Lwa_token
oleobject loo_Json
oleobject loo_SbRequest
oleobject loo_SbResponse
string ls_Uri
integer li_StatusCode
oleobject loo_JsonResp
integer li_ExpiresIn
string ls_RestrictedDataToken

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

loo_AuthAws = create oleobject
li_rc = loo_AuthAws.ConnectToNewObject("Chilkat_9_5_0.AuthAws")
if li_rc < 0 then
    destroy loo_AuthAws
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_AuthAws.AccessKey = "AWS_ACCESS_KEY"
loo_AuthAws.SecretKey = "AWS_SECRET_KEY"
loo_AuthAws.ServiceName = "execute-api"
// Use the region that is correct for your needs.
loo_AuthAws.Region = "eu-west-1"

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")

li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
// The sandbox endpoint (sandbox.sellingpartnerapi-eu.amazon.com) fails.
// Use the production endpoint and see the note below.
li_Success = loo_Rest.Connect("sellingpartnerapi-eu.amazon.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_AuthAws
    destroy loo_Rest
    return
end if

li_Success = loo_Rest.SetAuthAws(loo_AuthAws)

// Load the previously obtained LWA access token.
// See Fetch SP-API LWA Access Token
loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

li_Success = loo_JsonToken.LoadFile("qa_data/tokens/sp_api_lwa_token.json")
if li_Success = 0 then
    Write-Debug "Failed to load LWA access token."
    destroy loo_AuthAws
    destroy loo_Rest
    destroy loo_JsonToken
    return
end if

// Add the x-amz-access-token request header.
ls_Lwa_token = loo_JsonToken.StringOf("access_token")
loo_Rest.ClearAllHeaders()
loo_Rest.AddHeader("x-amz-access-token",ls_Lwa_token)

// We're going to send a POST with the following JSON body:

// {
//   "restrictedResources": [
//     {
//       "method": "GET",
//       "path": "/orders/v0/orders",
//       "dataElements": ["buyerInfo", "shippingAddress"]
//     }
//   ]
// }

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

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateString("restrictedResources[0].method","GET")
loo_Json.UpdateString("restrictedResources[0].path","/orders/v0/orders")
loo_Json.UpdateString("restrictedResources[0].dataElements[0]","buyerInfo")
loo_Json.UpdateString("restrictedResources[0].dataElements[1]","shippingAddress")

loo_SbRequest = create oleobject
li_rc = loo_SbRequest.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Json.EmitSb(loo_SbRequest)

loo_SbResponse = create oleobject
li_rc = loo_SbResponse.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

ls_Uri = "/tokens/2021-03-01/restrictedDataToken"
li_Success = loo_Rest.FullRequestSb("POST",ls_Uri,loo_SbRequest,loo_SbResponse)
if li_Success = 0 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_AuthAws
    destroy loo_Rest
    destroy loo_JsonToken
    destroy loo_Json
    destroy loo_SbRequest
    destroy loo_SbResponse
    return
end if

// ------------------------------------------------------------------------------------
// Note: Using the sandbox endpoint, such as sandbox.sellingpartnerapi-eu.amazon.com
// results in a response status code of 400 with the following error:
// [{"code":"InvalidInput","message":"Could not match input arguments"}]
// Getting a restricted data token seems to only work with the production endpoint.
// ------------------------------------------------------------------------------------

// Examine the response status.
li_StatusCode = loo_Rest.ResponseStatusCode
if li_StatusCode <> 200 then
    Write-Debug "Response status code: " + string(li_StatusCode)
    Write-Debug "Response status text: " + loo_Rest.ResponseStatusText
    Write-Debug "Response body: "
    Write-Debug loo_SbResponse.GetAsString()
    Write-Debug "Failed."
    destroy loo_AuthAws
    destroy loo_Rest
    destroy loo_JsonToken
    destroy loo_Json
    destroy loo_SbRequest
    destroy loo_SbResponse
    return
end if

Write-Debug loo_SbResponse.GetAsString()

// If successful, gets a JSON response such as the following:

// {
//   "expiresIn": 3600,
//   "restrictedDataToken": "Atz.sprdt|AYAB.....TQ="
// }

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

loo_JsonResp = create oleobject
li_rc = loo_JsonResp.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_JsonResp.LoadSb(loo_SbResponse)

li_ExpiresIn = loo_JsonResp.IntOf("expiresIn")
ls_RestrictedDataToken = loo_JsonResp.StringOf("restrictedDataToken")

// Save the RDT for subsequent use..
li_Success = loo_JsonResp.WriteFile("qa_data/tokens/sp_api_rdt_token.json")

Write-Debug "Success!"


destroy loo_AuthAws
destroy loo_Rest
destroy loo_JsonToken
destroy loo_Json
destroy loo_SbRequest
destroy loo_SbResponse
destroy loo_JsonResp

 

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