Chilkat Online Tools

DataFlex / ForgeRock Identity Cloud Collection / Step 1: Create or update assetlinks.json

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Handle hoJarr
    Variant vJsonObj_1
    Handle hoJsonObj_1
    Variant vSbRequestBody
    Handle hoSbRequestBody
    Variant vResp
    Handle hoResp
    String sTemp1
    Integer iTemp1
    Boolean bTemp1

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

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    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.

    // [
    //   {
    //     "relation": [
    //       "delegate_permission/common.handle_all_urls",
    //       "delegate_permission/common.get_login_creds"
    //     ],
    //     "target": {
    //       "namespace": "web",
    //       "site": "https://id.mycompany.com"
    //     }
    //   }
    // ]

    Get Create (RefClass(cComChilkatJsonArray)) To hoJarr
    If (Not(IsComObjectCreated(hoJarr))) Begin
        Send CreateComObject of hoJarr
    End

    Get ComAddObjectAt Of hoJarr -1 To iSuccess
    Get ComSize Of hoJarr To iTemp1
    Get ComObjectAt Of hoJarr (iTemp1 - 1) To vJsonObj_1
    If (IsComObject(vJsonObj_1)) Begin
        Get Create (RefClass(cComChilkatJsonObject)) To hoJsonObj_1
        Set pvComObject Of hoJsonObj_1 To vJsonObj_1
    End
    Get ComUpdateString Of hoJsonObj_1 "relation[0]" "delegate_permission/common.handle_all_urls" To iSuccess
    Get ComUpdateString Of hoJsonObj_1 "relation[1]" "delegate_permission/common.get_login_creds" To iSuccess
    Get ComUpdateString Of hoJsonObj_1 "target.namespace" "web" To iSuccess
    Get ComUpdateString Of hoJsonObj_1 "target.site" "https://id.mycompany.com" To iSuccess
    Send Destroy of hoJsonObj_1

    // Adds the "Authorization: Bearer <access_token>" header.
    Set ComAuthToken Of hoHttp To "<access_token>"

    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 hoJarr vSbRequestBody To iSuccess

    Get pvComObject of hoSbRequestBody to vSbRequestBody
    Get ComPTextSb Of hoHttp "PUT" "https://id.mycompany.com/.well-known/assetlinks.json" vSbRequestBody "utf-8" "application/json" False False To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComStatusCode Of hoResp To iTemp1
    Showln iTemp1
    Get ComBodyStr Of hoResp To sTemp1
    Showln sTemp1
    Send Destroy of hoResp


End_Procedure

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-d '[
  {
    "relation": [
      "delegate_permission/common.handle_all_urls",
      "delegate_permission/common.get_login_creds"
    ],
    "target": {
      "namespace": "web",
      "site": "https://id.mycompany.com"
    }
  }
]'
https://id.mycompany.com/.well-known/assetlinks.json

Postman Collection Item JSON

{
  "name": "Step 1: Create or update assetlinks.json",
  "request": {
    "method": "PUT",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "[\n  {\n    \"relation\": [\n      \"delegate_permission/common.handle_all_urls\",\n      \"delegate_permission/common.get_login_creds\"\n    ],\n    \"target\": {\n      \"namespace\": \"web\",\n      \"site\": \"https://id.mycompany.com\"\n    }\n  }\n]",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{customDomainUrl}}/.well-known/assetlinks.json",
      "host": [
        "{{customDomainUrl}}"
      ],
      "path": [
        ".well-known",
        "assetlinks.json"
      ]
    }
  },
  "response": [
  ]
}