Consultez les connecteurs compatibles avec Application Integration.

Résoudre une référence JSON

À l'aide de la tâche de mappage des données, résolvez une référence JSON dans un modèle JSON contenant une référence $variable$. Stockez la sortie dans une nouvelle variable JSON.

Exemple de code

{
  "triggerConfigs": [{
    "label": "API Trigger",
    "startTasks": [{
      "taskId": "1"
    }],
    "properties": {
      "Trigger name": "json_structure_mapping_API_1"
    },
    "triggerType": "API",
    "triggerNumber": "1",
    "triggerId": "api_trigger/json_structure_mapping_API_1"
  }],
  "taskConfigs": [{
    "task": "FieldMappingTask",
    "taskId": "1",
    "parameters": {
      "FieldMappingConfigTaskParameterKey": {
        "key": "FieldMappingConfigTaskParameterKey",
        "value": {
          "jsonValue": "{\n  \"@type\": \"type.googleapis.com/enterprise.crm.eventbus.proto.FieldMappingConfig\",\n  \"mappedFields\": [{\n    \"inputField\": {\n      \"fieldType\": \"JSON_VALUE\",\n      \"transformExpression\": {\n        \"initialValue\": {\n          \"referenceValue\": \"$new_structure_json_template$\"\n        },\n        \"transformationFunctions\": [{\n          \"functionType\": {\n            \"stringFunction\": {\n              \"functionName\": \"RESOLVE_TEMPLATE\"\n            }\n          }\n        }, {\n          \"functionType\": {\n            \"stringFunction\": {\n              \"functionName\": \"TO_JSON\"\n            }\n          }\n        }]\n      }\n    },\n    \"outputField\": {\n      \"referenceKey\": \"$output_order_json$\",\n      \"fieldType\": \"JSON_VALUE\",\n      \"cardinality\": \"OPTIONAL\"\n    }\n  }]\n}"
        }
      }
    },
    "taskExecutionStrategy": "WHEN_ALL_SUCCEED",
    "displayName": "Data Mapping"
  }],
  "integrationParameters": [{
    "key": "output_order_json",
    "dataType": "JSON_VALUE",
    "displayName": "output_order_json",
    "inputOutputType": "OUT"
  }, {
    "key": "new_structure_json_template",
    "dataType": "STRING_VALUE",
    "defaultValue": {
      "stringValue": "{\n\t\"order\": {\n\t\t\"ordDate\": \"$input_order_json.orderDate$\",\n\t\t\"orderID\": \"$input_order_json.orderNum$\",\n\t\t\"btAddr\": {\n\t\t\t\"btAddr\": \"$input_order_json.billTo.street$ $input_order_json.billTo.city$ $input_order_json.billTo.state$ $input_order_json.billTo.zipCode$\",\n\t\t\t\"btCode\": \"$input_order_json.billTo.billToCode$\"\n\t\t},\n\"stAddr\": {\n\t\t\t\"stAddress\": \"$input_order_json.shipTo.street$ $input_order_json.shipTo.city$ $input_order_json.shipTo.state$ $input_order_json.shipTo.zipCode$\",\n\t\t\t\"stCode\": \"$input_order_json.shipTo.shipToCode$\"\n\t\t}\n\t}\n}"
    },
    "displayName": "new_structure_json_template"
  }, {
    "key": "input_order_json",
    "dataType": "JSON_VALUE",
    "defaultValue": {
      "jsonValue": "{\n  \"orderNum\": \"123\",\n  \"orderDate\": \"29/5/2022\",\n  \"shipTo\": {\n    \"shipToCode\": \"CX3H-XC Sunnyvale, California\",\n    \"street\": \"1155 Borregas Ave\",\n    \"city\": \"Sunnyvale\",\n    \"state\": \"CA\",\n    \"zipCode\": \"94089\"\n  },\n  \"billTo\": {\n    \"billToCode\": \"CX3H+XC Sunnyvale, California\",\n    \"street\": \"1155 Borregas Ave\",\n    \"city\": \"Sunnyvale\",\n    \"state\": \"CA\",\n    \"zipCode\": \"94089\"\n  }\n}"
    },
    "displayName": "input_order_json",
    "jsonSchema": "{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"billTo\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"zipCode\": {\n          \"type\": \"string\"\n        },\n        \"city\": {\n          \"type\": \"string\"\n        },\n        \"street\": {\n          \"type\": \"string\"\n        },\n        \"state\": {\n          \"type\": \"string\"\n        },\n        \"billToCode\": {\n          \"type\": \"string\"\n        }\n      }\n    },\n    \"orderNum\": {\n      \"type\": \"string\"\n    },\n    \"orderDate\": {\n      \"type\": \"string\"\n    },\n    \"shipTo\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"zipCode\": {\n          \"type\": \"string\"\n        },\n        \"city\": {\n          \"type\": \"string\"\n        },\n        \"street\": {\n          \"type\": \"string\"\n        },\n        \"shipToCode\": {\n          \"type\": \"string\"\n        },\n        \"state\": {\n          \"type\": \"string\"\n        }\n      }\n    }\n  }\n}"
  }]
}

Exemple de flux d'intégration

L'image suivante présente un exemple de mise en page de l'éditeur d'intégration pour cet exemple de code d'intégration.

Image montrant l'exemple de flux d'intégration Image montrant l'exemple de flux d'intégration

Importer et exécuter l'exemple d'intégration

Pour importer et exécuter l'exemple d'intégration, procédez comme suit:

  1. Enregistrez l'exemple d'intégration en tant que fichier .json sur votre système.
  2. Dans la console Google Cloud, accédez à la page Application Integration.

    Accéder à Application Integration

  3. Dans le menu de navigation, cliquez sur Intégrations. La page Integrations s'affiche.
  4. Sélectionnez une intégration existante ou créez-en une en cliquant sur Créer une intégration.

    Si vous créez une intégration :

    1. Saisissez un nom et une description dans la boîte de dialogue Créer une intégration.
    2. Sélectionnez une région pour l'intégration.
    3. Sélectionnez un compte de service pour l'intégration. Vous pouvez modifier ou mettre à jour les informations du compte de service d'une intégration à tout moment dans le volet Récapitulatif de l'intégration de la barre d'outils d'intégration.
    4. Cliquez sur Créer.

    Cela entraîne son ouverture dans l'éditeur d'intégrations.

  5. Dans l'éditeur d'intégrations, cliquez sur Menu Importer/Télécharger, puis sélectionnez Importer l'intégration.
  6. Dans la boîte de dialogue de l'explorateur de fichiers, sélectionnez le fichier que vous avez enregistré à l'étape 1, puis cliquez sur Ouvrir.

    Une nouvelle version de l'intégration est créée à l'aide du fichier importé.

  7. Dans l'éditeur d'intégrations, cliquez sur Tester.
  8. Cliquez sur Tester l'intégration. L'intégration est alors exécutée et le résultat de l'exécution s'affiche dans le volet Test d'intégration.