Skip to content

Instantly share code, notes, and snippets.

@amreeksingh
Created April 9, 2018 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amreeksingh/e776609de333b14a5a2f4ed225148181 to your computer and use it in GitHub Desktop.
Save amreeksingh/e776609de333b14a5a2f4ed225148181 to your computer and use it in GitHub Desktop.
Logic App with Deep Insert
{
"$connections": {
"value": {
"dynamicscrmonline": {
"connectionId": "/subscriptions/6a539c1f-4415-493f-89b6-9458246ac115/resourceGroups/amreek/providers/Microsoft.Web/connections/dynamicscrmonline-5",
"connectionName": "dynamicscrmonline-5",
"id": "/subscriptions/6a539c1f-4415-493f-89b6-9458246ac115/providers/Microsoft.Web/locations/australiaeast/managedApis/dynamicscrmonline"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Generate_the_GUID": {
"inputs": {
"variables": [
{
"name": "NewGuid",
"type": "String",
"value": "@{guid()}"
}
]
},
"runAfter": {
"Initialize_ChangeSetNo": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"HTTP-Call CRM API": {
"inputs": {
"body": {
"Contact_CustomerAddress": [
{
"addresstypecode": "1",
"city": "@{triggerBody()?['Billing Address']['b_city']}",
"line1": "@{triggerBody()?['Billing Address']['b_address']}",
"name": "Billing Address",
"postalcode": "@{triggerBody()?['Billing Address']['b_zip']}",
"stateorprovince": "@{triggerBody()?['Billing Address']['b_state']}"
},
{
"addresstypecode": "3",
"city": "@{triggerBody()?['Shipping Address']['s_city']}",
"line1": "@{triggerBody()?['Shipping Address']['s_address']}",
"name": "Shipping Address",
"postalcode": "@{triggerBody()?['Shipping Address']['s_zip']}",
"stateorprovince": "@{triggerBody()?['Shipping Address']['s_state']}"
}
],
"emailaddress1": "@{triggerBody()?['Email']}",
"firstname": "@{triggerBody()?['FirstName']}",
"lastname": "@{triggerBody()?['LastName']}"
},
"headers": {
"Accept": "application/json",
"Authorization": "Bearer @{body('Parse_JSON')?['access_token']}",
"Cache-Control": "no-cache",
"Content-Type": "application/json",
"OData-MaxVersion": "4.0",
"OData-Version": "4.0"
},
"method": "POST",
"retryPolicy": {
"type": "none"
},
"uri": "https://hpecrm365.api.crm6.dynamics.com/api/data/v9.0/contacts"
},
"runAfter": {
"Parse_JSON": [
"Succeeded"
]
},
"type": "Http"
},
"HTTP-GetToken": {
"inputs": {
"body": "grant_type=client_credentials&client_id=507cfbe8-c898-4f59-9bb2-b09d579de34c&client_secret=SGDvDTvWb3QqpfBc4SShWuVLceVJLhVVGowPh/HDJdA=&resource=https://hpecrm365.api.crm6.dynamics.com",
"headers": {
"Cache-Control": "no-cache",
"content-type": "application/x-www-form-urlencoded"
},
"method": "POST",
"uri": "https://Login.windows.net/0cb4884d-d869-4d3e-adb4-c62880b6f645/oauth2/token"
},
"runAfter": {
"Generate_the_GUID": [
"Succeeded"
]
},
"type": "Http"
},
"Initialize_BatchNo": {
"inputs": {
"variables": [
{
"name": "BatchNo",
"type": "String",
"value": "Batch__@{guid()}"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_ChangeSetNo": {
"inputs": {
"variables": [
{
"name": "ChangesetNo",
"type": "String",
"value": "changeset_@{rand(100,999)}"
}
]
},
"runAfter": {
"Initialize_BatchNo": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Log_an_error": {
"inputs": {
"body": {
"new_description": "@{body('HTTP-Call CRM API')}",
"new_httpstatus": "@{outputs('HTTP-Call CRM API')['statusCode']}",
"new_name": "contactId :@{triggerBody()?['contactid']}"
},
"host": {
"connection": {
"name": "@parameters('$connections')['dynamicscrmonline']['connectionId']"
}
},
"method": "post",
"path": "/datasets/@{encodeURIComponent(encodeURIComponent('org63b0712d.crm6'))}/tables/@{encodeURIComponent(encodeURIComponent('new_integrationlogs'))}/items"
},
"runAfter": {
"HTTP-Call CRM API": [
"Failed"
]
},
"type": "ApiConnection"
},
"Parse_JSON": {
"inputs": {
"content": "@body('HTTP-GetToken')",
"schema": {
"properties": {
"access_token": {
"type": "string"
},
"expires_in": {
"type": "string"
},
"expires_on": {
"type": "string"
},
"ext_expires_in": {
"type": "string"
},
"not_before": {
"type": "string"
},
"resource": {
"type": "string"
},
"token_type": {
"type": "string"
}
},
"type": "object"
}
},
"runAfter": {
"HTTP-GetToken": [
"Succeeded"
]
},
"type": "ParseJson"
},
"Terminate": {
"inputs": {
"runError": {
"code": "@{outputs('HTTP-Call CRM API')['statusCode']}",
"message": "Failed"
},
"runStatus": "Failed"
},
"runAfter": {
"Log_an_error": [
"Succeeded"
]
},
"type": "Terminate"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {
"properties": {
"Billing Address": {
"properties": {
"b_address": {
"type": "string"
},
"b_city": {
"type": "string"
},
"b_state": {
"type": "string"
},
"b_zip": {
"type": "string"
}
},
"type": "object"
},
"Email": {
"type": "string"
},
"FirstName": {
"type": "string"
},
"LastName": {
"type": "string"
},
"Shipping Address": {
"properties": {
"s_address": {
"type": "string"
},
"s_city": {
"type": "string"
},
"s_state": {
"type": "string"
},
"s_zip": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
},
"kind": "Http",
"type": "Request"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment