DataFlex
DataFlex
Amazon Cognito - Admin Create User
See more Amazon Cognito Examples
Creates a new user in the specified user pool.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoRest
Variant vAuthAws
Handle hoAuthAws
Boolean iBTls
Integer iPort
Boolean iBAutoReconnect
Handle hoJson
Variant vSbRequestBody
Handle hoSbRequestBody
Variant vSbResponseBody
Handle hoSbResponseBody
Integer iRespStatusCode
Handle hoJsonResponse
String sName
String sValue
Boolean iUserEnabled
String sUserUserCreateDate
String sUserUserLastModifiedDate
String sUserUserStatus
String sUserUsername
Integer i
Integer iCount_i
String sTemp1
Integer iTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
Get Create (RefClass(cComChilkatAuthAws)) To hoAuthAws
If (Not(IsComObjectCreated(hoAuthAws))) Begin
Send CreateComObject of hoAuthAws
End
Set ComAccessKey Of hoAuthAws To "AWS_ACCESS_KEY"
Set ComSecretKey Of hoAuthAws To "AWS_SECRET_KEY"
// Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
Set ComRegion Of hoAuthAws To "us-west-2"
Set ComServiceName Of hoAuthAws To "cognito-idp"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
Get pvComObject of hoAuthAws to vAuthAws
Get ComSetAuthAws Of hoRest vAuthAws To iSuccess
// URL: https://cognito-idp.us-west-2.amazonaws.com/
Move True To iBTls
Move 443 To iPort
Move True To iBAutoReconnect
// Use the same region as specified above.
Get ComConnect Of hoRest "cognito-idp.us-west-2.amazonaws.com" iPort iBTls iBAutoReconnect To iSuccess
If (iSuccess <> True) Begin
Get ComConnectFailReason Of hoRest To iTemp1
Showln "ConnectFailReason: " iTemp1
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "DesiredDeliveryMediums" : [ "SMS", "EMAIL" ],
// "UserAttributes": [
// {
// "Name": "phone_number",
// "Value": "+16302581871"
// },
// {
// "Name": "email",
// "Value": "admin@chilkatsoft.com"
// }
// ],
// "UserPoolId": "us-west-2_yt6WzO3SA",
// "Username": "Matt"
// }
//
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "DesiredDeliveryMediums[0]" "SMS" To iSuccess
Get ComUpdateString Of hoJson "DesiredDeliveryMediums[1]" "EMAIL" To iSuccess
Get ComUpdateString Of hoJson "UserAttributes[0].Name" "phone_number" To iSuccess
Get ComUpdateString Of hoJson "UserAttributes[0].Value" "+16302581871" To iSuccess
Get ComUpdateString Of hoJson "UserAttributes[1].Name" "email" To iSuccess
Get ComUpdateString Of hoJson "UserAttributes[1].Value" "admin@chilkatsoft.com" To iSuccess
Get ComUpdateString Of hoJson "UserPoolId" "us-west-2_yt6WzO3SA" To iSuccess
Get ComUpdateString Of hoJson "Username" "Matt" To iSuccess
Get ComAddHeader Of hoRest "Content-Type" "application/x-amz-json-1.0" To iSuccess
Get ComAddHeader Of hoRest "X-Amz-Target" "AWSCognitoIdentityProviderService.AdminCreateUser" To iSuccess
Get ComAddHeader Of hoRest "Accept-Encoding" "identity" To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
Send CreateComObject of hoSbRequestBody
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComEmitSb Of hoJson vSbRequestBody To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComFullRequestSb Of hoRest "POST" "/" vSbRequestBody vSbResponseBody To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iRespStatusCode
Showln "response status code = " iRespStatusCode
If (iRespStatusCode <> 200) Begin
Showln "Response Status Code = " iRespStatusCode
Showln "Response Header:"
Get ComResponseHeader Of hoRest To sTemp1
Showln sTemp1
Showln "Response Body:"
Get ComGetAsString Of hoSbResponseBody To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse
If (Not(IsComObjectCreated(hoJsonResponse))) Begin
Send CreateComObject of hoJsonResponse
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJsonResponse vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJsonResponse To False
Get ComEmit Of hoJsonResponse To sTemp1
Showln sTemp1
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "User": {
// "Attributes": [
// {
// "Name": "sub",
// "Value": "dcd3db0c-32cf-4a33-a6b2-173653f7c0e7"
// },
// {
// "Name": "phone_number",
// "Value": "+16302581871"
// },
// {
// "Name": "email",
// "Value": "admin@chilkatsoft.com"
// }
// ],
// "Enabled": true,
// "UserCreateDate": 1.636407153801E9,
// "UserLastModifiedDate": 1.636407153801E9,
// "UserStatus": "FORCE_CHANGE_PASSWORD",
// "Username": "matt"
// }
// }
Get ComBoolOf Of hoJsonResponse "User.Enabled" To iUserEnabled
Get ComStringOf Of hoJsonResponse "User.UserCreateDate" To sUserUserCreateDate
Get ComStringOf Of hoJsonResponse "User.UserLastModifiedDate" To sUserUserLastModifiedDate
Get ComStringOf Of hoJsonResponse "User.UserStatus" To sUserUserStatus
Get ComStringOf Of hoJsonResponse "User.Username" To sUserUsername
Move 0 To i
Get ComSizeOfArray Of hoJsonResponse "User.Attributes" To iCount_i
While (i < iCount_i)
Set ComI Of hoJsonResponse To i
Get ComStringOf Of hoJsonResponse "User.Attributes[i].Name" To sName
Get ComStringOf Of hoJsonResponse "User.Attributes[i].Value" To sValue
Move (i + 1) To i
Loop
End_Procedure