<?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 Bulk update of service groups via API in Automation/API Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/bulk-update-of-service-groups-via-api/m-p/548420#M3391</link>
    <description>&lt;P&gt;I have a requirement to do a bulk update of a custom service group in Panorama (11.0.1) via the API. This is reading in a list of services from a CSV file. However it only ever applies the last entry in the CSV. What am i doing wrong?&amp;nbsp; I've tried PUT &amp;amp; POST. Post simply errors with a duplicate entry. A PUT to an existing group only inserts the last entry overwriting everything else.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;location = {'location': 'shared', 'name': 'TEST-GRP' }&lt;/P&gt;&lt;P&gt;with open ('groups.csv') as f:&lt;BR /&gt;reader = csv.DictReader(f)&lt;BR /&gt;for row in reader:&lt;BR /&gt;member = row['members']&lt;/P&gt;&lt;P&gt;body = json.dumps(&lt;BR /&gt;{&lt;BR /&gt;"entry":&lt;BR /&gt;{&lt;BR /&gt;"@name": "TEST-GRP",&lt;BR /&gt;"members": { "member" : [ member ]&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;r = requests.put(api_url, params=location, verify=False, headers=headers, data=body)&lt;BR /&gt;print(r.text)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Contents of groups.csv&lt;/P&gt;&lt;P&gt;members&lt;BR /&gt;service-https,&lt;BR /&gt;service-http,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jul 2023 15:15:43 GMT</pubDate>
    <dc:creator>GLSparks</dc:creator>
    <dc:date>2023-07-06T15:15:43Z</dc:date>
    <item>
      <title>Bulk update of service groups via API</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/bulk-update-of-service-groups-via-api/m-p/548420#M3391</link>
      <description>&lt;P&gt;I have a requirement to do a bulk update of a custom service group in Panorama (11.0.1) via the API. This is reading in a list of services from a CSV file. However it only ever applies the last entry in the CSV. What am i doing wrong?&amp;nbsp; I've tried PUT &amp;amp; POST. Post simply errors with a duplicate entry. A PUT to an existing group only inserts the last entry overwriting everything else.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;location = {'location': 'shared', 'name': 'TEST-GRP' }&lt;/P&gt;&lt;P&gt;with open ('groups.csv') as f:&lt;BR /&gt;reader = csv.DictReader(f)&lt;BR /&gt;for row in reader:&lt;BR /&gt;member = row['members']&lt;/P&gt;&lt;P&gt;body = json.dumps(&lt;BR /&gt;{&lt;BR /&gt;"entry":&lt;BR /&gt;{&lt;BR /&gt;"@name": "TEST-GRP",&lt;BR /&gt;"members": { "member" : [ member ]&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;r = requests.put(api_url, params=location, verify=False, headers=headers, data=body)&lt;BR /&gt;print(r.text)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Contents of groups.csv&lt;/P&gt;&lt;P&gt;members&lt;BR /&gt;service-https,&lt;BR /&gt;service-http,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 15:15:43 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/bulk-update-of-service-groups-via-api/m-p/548420#M3391</guid>
      <dc:creator>GLSparks</dc:creator>
      <dc:date>2023-07-06T15:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk update of service groups via API</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/bulk-update-of-service-groups-via-api/m-p/548875#M3398</link>
      <description>&lt;P&gt;give this a go:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import json&lt;BR /&gt;from pandas import *&lt;BR /&gt;data = read_csv("groups.csv")&lt;BR /&gt;member_list = data['members'].tolist()&lt;BR /&gt;member_set = set(member_list)&lt;BR /&gt;unique_member_list = list(member_set)&lt;BR /&gt;body = json.dumps(&lt;BR /&gt;{&lt;BR /&gt;"entry":&lt;BR /&gt;{&lt;BR /&gt;"@name": "TEST-GRP",&lt;BR /&gt;"members": { "member" : unique_member_list&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;)&lt;BR /&gt;&lt;BR /&gt;print(body)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Outputs:&lt;/P&gt;&lt;PRE&gt;{"entry": {"@name": "TEST-GRP", "members": {"member": ["service-http", "service-https"]}}}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tip: conversion from list to set and back is&amp;nbsp; to remove any duplicates&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2023 07:12:07 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/bulk-update-of-service-groups-via-api/m-p/548875#M3398</guid>
      <dc:creator>SimonT</dc:creator>
      <dc:date>2023-07-11T07:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk update of service groups via API</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/bulk-update-of-service-groups-via-api/m-p/551325#M3405</link>
      <description>&lt;P&gt;Just got back to this.&lt;/P&gt;&lt;P&gt;Unfortunately it does not work. I've taken the CSV import out to test also and i still get errors. Tried it with addresses also rather than services:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"code":3,"message":"Invalid Object","details":[{"@type":"CauseInfo","causes":[{"code":12,"module":"panui_mgmt","description":"Invalid Object: TEST-GRP -&amp;gt; members unexpected here."}]}]}&lt;BR /&gt;{"entry": {"@name": "TEST-GRP", "members": {"member": ["gav-1", "gav-2"]}}}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 11:02:04 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/bulk-update-of-service-groups-via-api/m-p/551325#M3405</guid>
      <dc:creator>GLSparks</dc:creator>
      <dc:date>2023-07-27T11:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk update of service groups via API</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/bulk-update-of-service-groups-via-api/m-p/552015#M3408</link>
      <description>&lt;P&gt;Okay finally got this working so i thought i'd share:&lt;/P&gt;&lt;P&gt;import requests&lt;BR /&gt;import json&lt;BR /&gt;import csv&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;with open('test.csv', 'r') as read_obj:&lt;BR /&gt;csv_reader = csv.reader(read_obj)&lt;BR /&gt;MyList = list(csv_reader)&lt;/P&gt;&lt;P&gt;location = {'location': 'shared', 'name': 'TEST-GRP' }&lt;/P&gt;&lt;P&gt;body = json.dumps(&lt;BR /&gt;{&lt;BR /&gt;"entry": [&lt;BR /&gt;{&lt;BR /&gt;"@name": "TEST-GRP",&lt;BR /&gt;"@location": "Shared",&lt;BR /&gt;"static": {&lt;BR /&gt;"member": (MyList)&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;)&lt;/P&gt;&lt;P&gt;r = requests.put(api_url, params=location, verify=False, headers=headers, data=body)&lt;BR /&gt;print(r.text)&lt;BR /&gt;print (body)&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 08:56:27 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/bulk-update-of-service-groups-via-api/m-p/552015#M3408</guid>
      <dc:creator>GLSparks</dc:creator>
      <dc:date>2023-08-01T08:56:27Z</dc:date>
    </item>
    <item>
      <title>Re: Bulk update of service groups via API</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/bulk-update-of-service-groups-via-api/m-p/552016#M3409</link>
      <description>&lt;P&gt;Didn't have pandas available to me but got it to work based off of your input. Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 01 Aug 2023 08:57:54 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/bulk-update-of-service-groups-via-api/m-p/552016#M3409</guid>
      <dc:creator>GLSparks</dc:creator>
      <dc:date>2023-08-01T08:57:54Z</dc:date>
    </item>
  </channel>
</rss>

