DataFlex
DataFlex
GeoOp - Find Account ID by Name
See more GeoOp Examples
Finds an account ID by name.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Token Handle hoJsonToken
Variant vOauth2
Handle hoOauth2
Handle hoRest
Boolean iBAutoReconnect
String sResponseBody
Handle hoJson
Boolean iCaseSensitive
String sAccountId
String sTemp1
Integer iTemp1
Boolean bTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// This example also assumes an OAuth2 access token was previously fetched.
// and saved in a JSON file.
// First get our previously obtained access token.
// {"access_token":"e6dqdG....mzjpT04w==","token_type":"Bearer","expires_in":2592000,"owner_id":999236}
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken
If (Not(IsComObjectCreated(hoJsonToken))) Begin
Send CreateComObject of hoJsonToken
End
Get ComLoadFile Of hoJsonToken "qa_data/tokens/geoop.json" To iSuccess
// This example assumes we previously obtained an access token
Get Create (RefClass(cComChilkatOAuth2)) To hoOauth2
If (Not(IsComObjectCreated(hoOauth2))) Begin
Send CreateComObject of hoOauth2
End
Get ComStringOf Of hoJsonToken "access_token" To sTemp1
Set ComAccessToken Of hoOauth2 To sTemp1
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
// Connect to GeoOp and send the following GET request:
// GET /users HTTP/1.1
// Host: api.geoop.com
Move True To iBAutoReconnect
Get ComConnect Of hoRest "api.geoop.com" 443 True iBAutoReconnect To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// Provide the authentication credentials (i.e. the access token)
Get pvComObject of hoOauth2 to vOauth2
Get ComSetAuthOAuth2 Of hoRest vOauth2 To iSuccess
// Set the X-Version header.
Get ComAddHeader Of hoRest "X-Version" "1.0" To iSuccess
Get ComFullRequestNoBody Of hoRest "GET" "/accounts" To sResponseBody
Get ComLastMethodSuccess Of hoRest To bTemp1
If (bTemp1 <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// If the response status code did not indicate success, then see what happened..
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 200) Begin
Showln "Request Header: "
Get ComLastRequestHeader Of hoRest To sTemp1
Showln sTemp1
Showln "----"
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "Response StatusCode = " iTemp1
Get ComResponseStatusText Of hoRest To sTemp1
Showln "Response StatusLine: " sTemp1
Showln "Response Header:"
Get ComResponseHeader Of hoRest To sTemp1
Showln sTemp1
Showln sResponseBody
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Set ComEmitCompact Of hoJson To False
Get ComLoad Of hoJson sResponseBody To iSuccess
// Show the full JSON response. (see the sample response at the bottom of this example)
Get ComEmit Of hoJson To sTemp1
Showln sTemp1
// To find the account id for a given company name:
Move False To iCaseSensitive
Get ComFindRecordString Of hoJson "accounts" "companyName" "Chilkat Software, Inc." iCaseSensitive "id" To sAccountId
Get ComLastMethodSuccess Of hoJson To bTemp1
If (bTemp1 <> True) Begin
Showln "Account not found."
End
Else Begin
Showln "The account ID is: " sAccountId
End
// Find the account ID for the 1st company matching "Chilkat*"
Get ComFindRecordString Of hoJson "accounts" "companyName" "Chilkat*" iCaseSensitive "id" To sAccountId
Get ComLastMethodSuccess Of hoJson To bTemp1
If (bTemp1 <> True) Begin
Showln "Account not found."
End
Else Begin
Showln "The account ID is: " sAccountId
End
// The full JSON response for GET /accounts looks like this:
// {
// "result": "success",
// "accounts": [
// {
// "id": 39409,
// "companyName": "Chilkat Software, Inc.",
// "licenses": 999,
// "countryCode": 1
// }
// ],
// "metadata": {
// "page": 1,
// "pagesCount": 1,
// "recordsPerPage": 20,
// "recordsCount": 1
// }
// }
//
End_Procedure