Reply

Using API to create a new python script

New Member
Posts: 2
4736     0

Hi, trying to use API to create / update a script in NetMRI so that I can automate the process of uploading the script from my local machine to NetMRI.

 

When I do the post before (pseudo code from PostMan), the script gets created, but does not have a Name.   

 

POST https://{{netmri}}/api/3.3/scripts/create HTTP/1.1
{
    "language" : "Python",
    "script_file" : "# Script: 0-test2\n#\n# BEGIN-SCRIPT-BLOCK\n#\n# Script-Filter:\n# $Vendor =~ /^(cisco)/i\n#\n# Script-Timeout: 3600\n#\n# Script-Variables:\n# END-SCRIPT-BLOCK\nprint('hello')\n"
}
 
 
Worse than that is when I try an update, I get an immediate HTTP 500.
POST https://{{netmri}}/api/3.3/scripts/update HTTP/1.1
{
    "id" : 187,
    "overwrite" : 1,
    "script_file" : "# Script: 0-test2\n#\n# BEGIN-SCRIPT-BLOCK\n#\n# Script-Filter:\n# $Vendor =~ /^(cisco)/i\n#\n# Script-Timeout: 3600\n#\n# Script-Variables:\n# END-SCRIPT-BLOCK\nprint('hello')\n"
}
 
 
Ideas about what might be going on?
 
 

Re: Using API to create a new python script

Expert
Posts: 18
4736     0

I have this call out myself just now, and it fails, but in looking at the output it seems to think the script_file type is an array and not a string.  Try it as an array instead and see if that works.

 

<response>
    <error>general/validation-failed</error>
    <message>
          Validation failed: Script file Invalid import file: missing script name
    </message>
    <fields type="hash">
        <script_file type="array">
             <string>Invalid import file: missing script name</string>
        </script_file>
    </fields>
</response>

Re: Using API to create a new python script

New Member
Posts: 2
4736     0

Thanks for the quick reply.

 

Which one did you try and get the error on, the create or the update?

 

My create is working ok, other than it doesn't have the name when I look at the scripts page in the GUI. 

 

When I do a create with this JSON:

{
    "language" : "Python",
    "script_file" : "# Script: 0-test2\n#\n# BEGIN-SCRIPT-BLOCK\n#\n# Script-Filter:\n# $Vendor =~ /^(cisco)/i\n#\n# Script-Timeout: 3600\n#\n# Script-Variables:\n# END-SCRIPT-BLOCK\nprint('hello')\n"
}

 

It works, I get back HTTP 200, and this is what I get for a response.  You can see the Name is "".

{ "script": { "category": "Uncategorized", "created_at": "2019-07-19 10:41:00", "created_by": "svcnpmauto1", "description": "", "id": 190, "language": "Python", "module": "CCS", "name": "", "read_only": false, "risk_level": 1, "target_mapping": "device", "taskflow_create": "device\/standard", "taskflow_edit": "device\/standard", "taskflow_revert": null, "transactional_ind": false, "updated_at": "2019-07-19 10:41:00", "updated_by": "svcnpmauto1", "visible": true, "script_variables": [], "_class": "Script" } }

 

 

When I do an update with this JSON:

{
    "id" : 190,
    "overwrite" : 1,
    "script_file" : "# Script: 0-test2\n#\n# BEGIN-SCRIPT-BLOCK\n#\n# Script-Filter:\n# $Vendor =~ /^(cisco)/i\n#\n# Script-Timeout: 3600\n#\n# Script-Variables:\n# END-SCRIPT-BLOCK\nprint('hello')\n"
}
 
I get back a HTTP 400 with this:
{ "error": "general\/validation-failed", "message": "Validation failed: Script text \n*** ERROR: Required attribute not found 'Script-Filter' ***\n", "fields": { "script_text": [ "\n*** ERROR: Required attribute not found 'Script-Filter' ***\n" ] } }
 
 

Re: Using API to create a new python script

Expert
Posts: 18
4736     0

I was just popping it into my browser and trying it.  I can't troubleshoot this more today, but can try and look at it later.  You might also try posting this in the Infoblox NetMRI Slack site.

 

Thanks.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You