0

recently my admin asked me if I can create an app to input some data into our Sonicwall. I found some API, created an account, and ran some "get" methods, which worked just fine. I am trying now to post a new object into our pv4 rules and cannot get over it. The problem is when I write something like this:

def postIpv4Object(session):
body = {
    "address_objects": [{
            "ipv4": {
                "name": "Test 1",
                "zone": "LAN",
                "host": {
                    "ip": "192.168.168.10"
                }
            }
        }
    ]
}

resp = session.post(fw + '/api/sonicos/address-objects/ipv4', headers=good_headers,params=body, verify=False)

I am still getting this error:

{'status': {'info': [{'code': 'E_INVALID_API_CALL',
                  'level': 'error',
                  'message': 'Expected a request body.'}],
        'success': False}}

I am reading docs but cannot really figure this out. Does anyone tried it and help me out a little?

LukasEko
  • 5
  • 4
  • Just throwing this out here as I haven't played with the new sonicwall OS with API support, but what happens if you complete the api address instead of using the FW variable. I assume you have it defined somewhere... – Jason Owens Jul 30 '21 at 17:23
  • 1
    It wasn't the case. The case was the "Body" object. It must be a JSON type, mine was just a dict. The simple conversion did the trick. – LukasEko Aug 05 '21 at 20:01
  • That's good to know, glad you got it fixed, I will start to play around with it, we're still using 6.5 in our office for our clients :( – Jason Owens Aug 12 '21 at 18:13

1 Answers1

0

After a couple of days of trying, I figured that "body" should be converted into JSON type, and instead of "params I need to use "data".

LukasEko
  • 5
  • 4