<?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 Upload ActiveGate plugin through API in Dynatrace API</title>
    <link>https://community.dynatrace.com/t5/Dynatrace-API/Upload-ActiveGate-plugin-through-API/m-p/124298#M1062</link>
    <description>&lt;P&gt;We are currently automating our plugin deployment. But we can't get the POST call right to upload the zip (or plugin.json) file to our managed server.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We tryd it through Invoke-RestMethod with the following config:&lt;/P&gt;
&lt;PRE&gt;$urlPluginAPI = "https://dynatrace.xxxx.be/e/xxx-xxx-xxx-xxx/api/config/v1/plugins?overrideAlerts=false"&lt;BR /&gt;$headers = @{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Authorization='Api-Token notArealToken'&lt;BR /&gt;}&lt;BR /&gt;$FileContent = [IO.File]::ReadAllBytes($zipPath)&lt;BR /&gt;$Fields = @{file=$FileContent};&lt;BR /&gt;&lt;BR /&gt;Invoke-RestMethod -Uri $urlPluginAPI -ContentType 'multipart/form-data' -Method Post -Headers $Headers -Body $Fields;&lt;/PRE&gt;
&lt;P&gt;But we got the following result from that:&lt;/P&gt;
&lt;PRE&gt;Invoke-RestMethod : {"error":{"code":400,"message":"HTTP 400 Bad Request"}}&lt;BR /&gt;At line:8 char:1&lt;BR /&gt;+ Invoke-RestMethod -Uri $urlPluginAPI -ContentType 'multipart/form-dat ...&lt;BR /&gt;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;&amp;nbsp; &amp;nbsp; + CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequ&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;est) [Invoke-RestMethod], WebException&lt;BR /&gt;&amp;nbsp; &amp;nbsp; + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Comma&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;nds.InvokeRestMethodCommand&lt;/PRE&gt;
&lt;P&gt;We also tryd it through Windows Curl with the following results&lt;/P&gt;
&lt;PRE&gt;C:\Users\REM_Dynatrace01\curl-7.66.0-win64-mingw\bin&amp;gt;curl -X POST 'https://dynatrace.xxxx.be/e/xxx-xxx-xxx-xxx/api/config/v1/plugins' -H 'Authorization: Api-token notArealToken'&amp;nbsp;-H 'content-type: multipart/form-data' &amp;nbsp;-F file=@C:\Users\REM_Dynatrace01\Documents\custom.remote.python.&lt;BR /&gt;printbat.zip&lt;BR /&gt;curl: (26) Failed to open/read local data from file/application&lt;BR /&gt;curl: (26) Failed to open/read local data from file/application&lt;BR /&gt;curl: (26) Failed to open/read local data from file/application&lt;BR /&gt;curl: (26) Failed to open/read local data from file/application&lt;/PRE&gt;
&lt;P&gt;Anybody that got a working example that we can do through Powershell? Preferably through Invoke-RestMethod&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Aug 2024 10:41:40 GMT</pubDate>
    <dc:creator>ynias_reynders</dc:creator>
    <dc:date>2024-08-21T10:41:40Z</dc:date>
    <item>
      <title>Upload ActiveGate plugin through API</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/Upload-ActiveGate-plugin-through-API/m-p/124298#M1062</link>
      <description>&lt;P&gt;We are currently automating our plugin deployment. But we can't get the POST call right to upload the zip (or plugin.json) file to our managed server.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We tryd it through Invoke-RestMethod with the following config:&lt;/P&gt;
&lt;PRE&gt;$urlPluginAPI = "https://dynatrace.xxxx.be/e/xxx-xxx-xxx-xxx/api/config/v1/plugins?overrideAlerts=false"&lt;BR /&gt;$headers = @{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; Authorization='Api-Token notArealToken'&lt;BR /&gt;}&lt;BR /&gt;$FileContent = [IO.File]::ReadAllBytes($zipPath)&lt;BR /&gt;$Fields = @{file=$FileContent};&lt;BR /&gt;&lt;BR /&gt;Invoke-RestMethod -Uri $urlPluginAPI -ContentType 'multipart/form-data' -Method Post -Headers $Headers -Body $Fields;&lt;/PRE&gt;
&lt;P&gt;But we got the following result from that:&lt;/P&gt;
&lt;PRE&gt;Invoke-RestMethod : {"error":{"code":400,"message":"HTTP 400 Bad Request"}}&lt;BR /&gt;At line:8 char:1&lt;BR /&gt;+ Invoke-RestMethod -Uri $urlPluginAPI -ContentType 'multipart/form-dat ...&lt;BR /&gt;+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;BR /&gt;&amp;nbsp; &amp;nbsp; + CategoryInfo &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequ&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;est) [Invoke-RestMethod], WebException&lt;BR /&gt;&amp;nbsp; &amp;nbsp; + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Comma&amp;nbsp;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;nds.InvokeRestMethodCommand&lt;/PRE&gt;
&lt;P&gt;We also tryd it through Windows Curl with the following results&lt;/P&gt;
&lt;PRE&gt;C:\Users\REM_Dynatrace01\curl-7.66.0-win64-mingw\bin&amp;gt;curl -X POST 'https://dynatrace.xxxx.be/e/xxx-xxx-xxx-xxx/api/config/v1/plugins' -H 'Authorization: Api-token notArealToken'&amp;nbsp;-H 'content-type: multipart/form-data' &amp;nbsp;-F file=@C:\Users\REM_Dynatrace01\Documents\custom.remote.python.&lt;BR /&gt;printbat.zip&lt;BR /&gt;curl: (26) Failed to open/read local data from file/application&lt;BR /&gt;curl: (26) Failed to open/read local data from file/application&lt;BR /&gt;curl: (26) Failed to open/read local data from file/application&lt;BR /&gt;curl: (26) Failed to open/read local data from file/application&lt;/PRE&gt;
&lt;P&gt;Anybody that got a working example that we can do through Powershell? Preferably through Invoke-RestMethod&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2024 10:41:40 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/Upload-ActiveGate-plugin-through-API/m-p/124298#M1062</guid>
      <dc:creator>ynias_reynders</dc:creator>
      <dc:date>2024-08-21T10:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: Upload AG plugin through api</title>
      <link>https://community.dynatrace.com/t5/Dynatrace-API/Upload-ActiveGate-plugin-through-API/m-p/124299#M1063</link>
      <description>&lt;P&gt;I would say PowerShell is not the best tool to do that, but it is possible.&lt;/P&gt;&lt;P&gt;There are two problems:&lt;BR /&gt;1. PowerShell constructs request as specified in body (so no magic that will fill stuff for you)&lt;/P&gt;&lt;P&gt;2. The way you passed fileContent to body, resulted in having "System.Byte%5B%5D" in request instead of bytes itself.&lt;/P&gt;&lt;PRE&gt;$zipName = "custom.remote.python.demo.zip"&lt;BR /&gt;$zipPath = "your\\path\\to\\plugin\\$zipName"&lt;BR /&gt;$urlPluginAPI = "https://dynatrace.xxxx.be/e/xxx-xxx-xxx-xxx/api/config/v1/plugins?overrideAlerts=false"&lt;BR /&gt;$headers = @{&lt;BR /&gt;&amp;nbsp; &amp;nbsp; 'Authorization'='Api-Token some-token'&lt;BR /&gt;}&lt;BR /&gt;$FileContent = [IO.File]::ReadAllBytes($zipPath)&lt;BR /&gt;$ct = [System.Text.Encoding]::GetEncoding("iso-8859-1").GetString($FileContent)&lt;BR /&gt;&lt;BR /&gt;$boundary = [System.Guid]::NewGuid().ToString()&lt;BR /&gt;&lt;BR /&gt;$LF = "`n"&lt;BR /&gt;$bodyLines = (&lt;BR /&gt;&amp;nbsp; &amp;nbsp; "--$boundary",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; "Content-Disposition: form-data; name=`"file`"; filename=`"$zipName`"",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; "Content-Type: application/zip$LF",&lt;BR /&gt;&amp;nbsp; &amp;nbsp; $ct,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; "--$boundary--$LF"&lt;BR /&gt;&amp;nbsp; &amp;nbsp; ) -join $LF&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Invoke-RestMethod -Uri $urlPluginAPI &amp;nbsp;-Body $bodyLines -Headers $Headers -Method Post -ContentType "multipart/form-data; boundary=`"$boundary`"" -TimeoutSec 20&lt;/PRE&gt;&lt;P&gt;that's the code that worked for me&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Oct 2019 13:47:38 GMT</pubDate>
      <guid>https://community.dynatrace.com/t5/Dynatrace-API/Upload-ActiveGate-plugin-through-API/m-p/124299#M1063</guid>
      <dc:creator>piotr_kuchta</dc:creator>
      <dc:date>2019-10-11T13:47:38Z</dc:date>
    </item>
  </channel>
</rss>

