<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Powershell Put Script - Create Third Party VPN Peer in Network Platform API</title>
    <link>https://community.cisco.com/t5/network-platform-api/powershell-put-script-create-third-party-vpn-peer/m-p/5416561#M2887</link>
    <description>&lt;P&gt;From your specific example, it looks like you're missing [ ] brackets around your child cipher statements. As the dashboard takes multiple values you'll need to pass the values in as an array. Here's the JSON that I used when trying directly in postman. &lt;/P&gt;&lt;PRE&gt;[
    {
        "name": "test",
        "publicIp": "1.1.1.1",
        "privateSubnets": [
            "10.1.1.1/32"
        ],
        "secret": "WWWWWW",
        "ipsecPolicies": {
            "ikeCipherAlgo": "aes256",
            "ikeAuthAlgo": "sha1",
            "ikeDiffieHellmanGroup": "group2",
            "ikeLifetime": "28800",
            "childCipherAlgo": [
                "aes256"
            ],
            "childAuthAlgo": [
                "sha1"
            ],
            "childPfsGroup": "disabled",
            "childLifetime": "3600"
        },
        "networkTags": [
            "all"
        ]
    }
]&lt;/PRE&gt;</description>
    <pubDate>Sat, 23 Mar 2019 17:30:29 GMT</pubDate>
    <dc:creator>cfn</dc:creator>
    <dc:date>2019-03-23T17:30:29Z</dc:date>
    <item>
      <title>Powershell Put Script - Create Third Party VPN Peer</title>
      <link>https://community.cisco.com/t5/network-platform-api/powershell-put-script-create-third-party-vpn-peer/m-p/5416560#M2886</link>
      <description>&lt;P&gt;I am using the following PowerShell code to attempt to create a Third Party VPN Peer in a Meraki organization.&lt;/P&gt;&lt;PRE&gt;[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX'

$header = @{
	
	"X-Cisco-Meraki-API-Key" = $api_key
	"Content-Type" = 'application/json ; charset=utf-8'
	
}

$orgID = 'YYYYYYYYYYYYYYYYY'

$api = @{

	"endpoint" = 'https://nZZ.meraki.com/api/v0'

}

$api.url = '/organizations/' + $orgID + '/thirdPartyVPNPeers'
$uri = $api.endpoint + $api.url

$parms = [ordered]@{
	name = "VPN-PEER-NAME"
    publicIp = "1.1.1.1"
    privateSubnets = @(
        "10.0.1.1/32"
    )
    secret = "WWWWWWWWWWWWWWWWWWWWW"
    ipsecPolicies = @{
        ikeCipherAlgo = "aes256"
        ikeAuthAlgo = "sha1"
        ikeDiffieHellmanGroup = "group2"
        ikeLifetime = "28800"
        childCipherAlgo = "aes256"
        childAuthAlgo = "sha1"
        childPfsGroup = "disabled"
        childLifetime = "3600"
    }
}
$json = $parms | ConvertTo-Json
$change = Invoke-RestMethod -Method Put -Uri $uri -Body $json -Headers $header
$change

&lt;/PRE&gt;&lt;P&gt;Once I run that, I get the following error:&lt;/P&gt;&lt;PRE&gt;Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:58 char:11
+ $change = Invoke-RestMethod -Method Put -Uri $uri -Body $json -Header ...
+           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand&lt;/PRE&gt;&lt;P&gt;I was thinking that perhaps my json is incorrect. I've tried numerous different approaches to format it.&lt;/P&gt;&lt;P&gt;I am following this link for direction on the construction of the calls:&lt;/P&gt;&lt;P&gt;&lt;A href="https://documenter.getpostman.com/view/897512/meraki-dashboard-api/2To9xm#c2d0ec2c-b1e9-4eaa-83eb-cf06119cd0c9" target="_blank" rel="noopener nofollow noreferrer"&gt;https://documenter.getpostman.com/view/897512/meraki-dashboard-api/2To9xm#c2d0ec2c-b1e9-4eaa-83eb-cf06119cd0c9&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Now, I do note that this says "update" and not "create". So, that may be the issue as well....&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 15:18:33 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/powershell-put-script-create-third-party-vpn-peer/m-p/5416560#M2886</guid>
      <dc:creator>scubes</dc:creator>
      <dc:date>2019-03-23T15:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Put Script - Create Third Party VPN Peer</title>
      <link>https://community.cisco.com/t5/network-platform-api/powershell-put-script-create-third-party-vpn-peer/m-p/5416561#M2887</link>
      <description>&lt;P&gt;From your specific example, it looks like you're missing [ ] brackets around your child cipher statements. As the dashboard takes multiple values you'll need to pass the values in as an array. Here's the JSON that I used when trying directly in postman. &lt;/P&gt;&lt;PRE&gt;[
    {
        "name": "test",
        "publicIp": "1.1.1.1",
        "privateSubnets": [
            "10.1.1.1/32"
        ],
        "secret": "WWWWWW",
        "ipsecPolicies": {
            "ikeCipherAlgo": "aes256",
            "ikeAuthAlgo": "sha1",
            "ikeDiffieHellmanGroup": "group2",
            "ikeLifetime": "28800",
            "childCipherAlgo": [
                "aes256"
            ],
            "childAuthAlgo": [
                "sha1"
            ],
            "childPfsGroup": "disabled",
            "childLifetime": "3600"
        },
        "networkTags": [
            "all"
        ]
    }
]&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Mar 2019 17:30:29 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/powershell-put-script-create-third-party-vpn-peer/m-p/5416561#M2887</guid>
      <dc:creator>cfn</dc:creator>
      <dc:date>2019-03-23T17:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Put Script - Create Third Party VPN Peer</title>
      <link>https://community.cisco.com/t5/network-platform-api/powershell-put-script-create-third-party-vpn-peer/m-p/5416562#M2888</link>
      <description>&lt;P&gt;I've been analyzing it a bit and I think apart from what &lt;A href="https://community.meraki.com/t5/user/viewprofilepage/user-id/3786"&gt;@cfn&lt;/A&gt; mentioned about the child ciphers I think you also need an array at the outermost level:&lt;/P&gt;&lt;PRE&gt;@(
   [ordered]@{
		name = "...
   }
)&lt;/PRE&gt;&lt;P&gt;I also noticed that for me postman puts not only the child ipsecPolicies in brackets but all of them except the 2 lifetime ones.&lt;/P&gt;&lt;P&gt;I also noticed that there's a difference in behavior between:&lt;/P&gt;&lt;PRE&gt;$json = $parms | ConvertTo-Json


$json = ConvertTo-Json -InputObject $parms&lt;/PRE&gt;&lt;P&gt;I couldn't get it to work with powershell myself either, I'm still experimenting...&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 18:16:50 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/powershell-put-script-create-third-party-vpn-peer/m-p/5416562#M2888</guid>
      <dc:creator>BrechtSchamp</dc:creator>
      <dc:date>2019-03-23T18:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Put Script - Create Third Party VPN Peer</title>
      <link>https://community.cisco.com/t5/network-platform-api/powershell-put-script-create-third-party-vpn-peer/m-p/5416563#M2889</link>
      <description>&lt;P&gt;All right, I think I figured it out. The remaining issue was the depth of the JSON conversion.&lt;/P&gt;&lt;P&gt;Here's the working code:&lt;/P&gt;&lt;PRE&gt;[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX'

$header = @{
	
	"X-Cisco-Meraki-API-Key" = $api_key
	"Content-Type" = 'application/json'
	
}

$orgID = 'XXXXXXXXXXXXXXXXXXXXXXXXX'

$api = @{

	"endpoint" = 'https://nXXX.meraki.com/api/v0'

}

$api.url = '/organizations/' + $orgID + '/thirdPartyVPNPeers'
$uri = $api.endpoint + $api.url



$parms =@(
[ordered]@{
		name = "My peer 2"
		publicIp = "123.123.123.1"
		privateSubnets = @(
			"192.168.13.0/24"
		)
		secret = "asdf1234"
		ipsecPolicies = [ordered]@{
			ikeCipherAlgo = @(
				"tripledes"
			)
			ikeAuthAlgo = @(
				"sha1"
			)
			ikeDiffieHellmanGroup = @(
				"group2"
			)
			ikeLifetime = "28800"
			childCipherAlgo = @(
				"aes128"
			)
			childAuthAlgo = @(
				"sha1"
			)
			childPfsGroup = @(
				"disabled"
			)
			childLifetime = "28800"
		}
	}
)

$json = ConvertTo-Json -Depth 5 -InputObject $parms 

$change = Invoke-RestMethod -Method Put -Uri $uri -Body $json -Headers $header -Verbose
$change&lt;/PRE&gt;&lt;P&gt;Hope that helps.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 18:28:33 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/powershell-put-script-create-third-party-vpn-peer/m-p/5416563#M2889</guid>
      <dc:creator>BrechtSchamp</dc:creator>
      <dc:date>2019-03-23T18:28:33Z</dc:date>
    </item>
    <item>
      <title>Re: Powershell Put Script - Create Third Party VPN Peer</title>
      <link>https://community.cisco.com/t5/network-platform-api/powershell-put-script-create-third-party-vpn-peer/m-p/5416564#M2890</link>
      <description>&lt;P&gt;Thanks everyone! I would have *never* figured that out!&lt;/P&gt;&lt;P&gt;Amazing help!&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 21:25:23 GMT</pubDate>
      <guid>https://community.cisco.com/t5/network-platform-api/powershell-put-script-create-third-party-vpn-peer/m-p/5416564#M2890</guid>
      <dc:creator>scubes</dc:creator>
      <dc:date>2019-03-23T21:25:23Z</dc:date>
    </item>
  </channel>
</rss>

