Created
April 9, 2018 01:03
-
-
Save amreeksingh/ab6f0acd8acc161aaa3315d2c0e058bf to your computer and use it in GitHub Desktop.
Logic app with Batch Request with manual GUID creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$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": "--@{variables('BatchNo')}\nContent-Type: multipart/mixed;boundary=@{variables('ChangesetNo')}\n\n\n--@{variables('ChangesetNo')}\nContent-Type: application/http\nContent-Transfer-Encoding:binary\nContent-ID: 1\n\nPOST https://hpecrm365.api.crm6.dynamics.com/api/data/v9.0/contacts HTTP/1.1\nContent-Type: application/json;type=entry\n\n{\"firstname\":\"@{triggerBody()?['FirstName']}\",\"lastname\":\"@{triggerBody()?['LastName']}\", \"emailaddress1\":\"@{triggerBody()?['Email']}\",\"contactid\":\"@{variables('NewGuid')}\"}\n\n\n--@{variables('ChangesetNo')}\nContent-Type: application/http\nContent-Transfer-Encoding:binary\nContent-ID: 2\n\nPOST https://hpecrm365.api.crm6.dynamics.com/api/data/v9.0/customeraddresses HTTP/1.1\nContent-Type: application/json;type=entry\n\n{\"line1\":\"@{triggerBody()?['Billing Address']['b_address']}\",\"city\":\"@{triggerBody()?['Billing Address']['b_city']}\",\"stateorprovince\":\"@{triggerBody()?['Billing Address']['b_state']}\",\"postalcode\":\"@{triggerBody()?['Billing Address']['b_zip']}\",\"addresstypecode\":\"1\",\n\"parentid_contact@odata.bind\":\"/contacts(@{variables('NewGuid')})\",\"name\":\"Billing Address\"}\n\n--@{variables('ChangesetNo')}\nContent-Type: application/http\nContent-Transfer-Encoding:binary\nContent-ID: 3\n\nPOST https://hpecrm365.api.crm6.dynamics.com/api/data/v9.0/customeraddresses HTTP/1.1\nContent-Type: application/json;type=entry\n\n\n{\"line1\":\"@{triggerBody()?['Shipping Address']['s_address']}\",\"city\":\"@{triggerBody()?['Shipping Address']['s_city']}\",\"stateorprovince\":\"@{triggerBody()?['Shipping Address']['s_state']}\",\"postalcode\":\"@{triggerBody()?['Shipping Address']['s_zip']}\",\"addresstypecode\":\"3\",\n\"parentid_contact@odata.bind\":\"/contacts(@{variables('NewGuid')})\",\"name\":\"Shipping Address\"}\n\n--@{variables('ChangesetNo')}--\n\n--@{variables('BatchNo')}--\n", | |
"headers": { | |
"Accept": "application/json", | |
"Authorization": "Bearer @{body('Parse_JSON')?['access_token']}", | |
"Cache-Control": "no-cache", | |
"Content-Type": "multipart/mixed;boundary=@{variables('BatchNo')}", | |
"OData-MaxVersion": "4.0", | |
"OData-Version": "4.0" | |
}, | |
"method": "POST", | |
"retryPolicy": { | |
"type": "none" | |
}, | |
"uri": "https://hpecrm365.api.crm6.dynamics.com/api/data/v9.0/$batch" | |
}, | |
"runAfter": { | |
"Parse_JSON": [ | |
"Succeeded" | |
] | |
}, | |
"type": "Http" | |
}, | |
"HTTP-GetToken": { | |
"inputs": { | |
"body": "grant_type=client_credentials&client_id=507cfbe8-c898-4f59-9cc4-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