gophish / api-client-python

A Python API Client for Gophish
MIT License
44 stars 48 forks source link

Error in Creating and Sending Campaign using API #22

Closed haxpak closed 5 years ago

haxpak commented 5 years ago

I am facing a problem with invalid JSON structure

def GoSend(group):
    pages = api.pages.get()
    for page in pages:
        if (page.name == 'test'):
            toSendPage = page
    templates = api.templates.get()
    for template in templates:
        if (template.name == 'Key'):
            toSendTemplate = template
    senders = api.smtp.get()
    for sender in senders:
        if (sender.name == 'UWP keygen'):
            toSendSmtp = sender
    # toSendGroup = [Group(name=group.name)]
    # toSendPage = Page(name='test')
    # toSendTemplate = Template(name='Key')
    # toSendsmtp = SMTP(name='UWP keygen')
    toSendUrl = "<redacted>"
    campaign = Campaign(
    name=group.name, groups=group, page=toSendPage, 
    template=toSendTemplate, smtp=toSendSmtp, url=toSendUrl)
    result = api.campaigns.post(campaign)
    debug("[*] {} GoSend complete".format(ln()))
    return result

I am getting the following error :

.
.
.
File "/usr/local/lib/python3.7/dist-packages/gophish/api/campaigns.py", line 20, in post
    return super(API, self).post(campaign)
  File "/usr/local/lib/python3.7/dist-packages/gophish/api/api.py", line 92, in post
    raise Error.parse(response.json())
gophish.models.Error: Invalid JSON structure
haxpak commented 5 years ago

I was not using groups=[group] but just groups=group. It appears to be the main cause. Resolved