Forum Discussion

Kelemvor's avatar
Kelemvor
Icon for Expert rankExpert
2 years ago

Using Postman to create multiple Websites via API & CSV?

Hi,

I’m testing out creating websites (or resources) via the API.  I have a standard Post working in Postman just fine.  However, when I then try to do the same thing via a CSV file in the Runner section, I’m getting 401 Authorization errors.

When I look at the data that’s being sent, it looks the same as what’s sent when I run it manually.

Is there something special I need to do when running a Post command via the Runner vs the manual Send command?

Thanks.

  • Well, just bumping this because it came up again yesterday.  I was able to create a device group with no issues, but simply by change it from device/groups to website/groups made it all break.  It ended up being the version.  When I tried to add it to the URL it didn’t help.  What seemed to work was to specify it in the header like this:

    Once I did that, everything seemed to start working.  Just in case it comes up for me again, I’m documenting it here.  Or if it helps anyone else, there you go.  :)

  • Anonymous's avatar
    Anonymous

    That’s wrong. Query parameters and data are two different things. You can have query parameters in a POST. The difference is that for a GET, LM’s API doesn’t require any payload, which is why the data variable is set to an empty string in the GET script.

  • That’s wrong. Query parameters and data are two different things. You can have query parameters in a POST. The difference is that for a GET, LM’s API doesn’t require any payload, which is why the data variable is set to an empty string in the GET script.

    I was referring to how to use LM API, not in general, so my assertion stands and the code works.

  • OK.  I decided to start over.  I installed VSCode and have Python working.  I’m able to do GETs now, but the data is coming back in a format with a ton of \n’s in it as text.  Do I need to do something to get the results with actual line returns so it’s readable?

    Thanks for all the assistance so far.

    E.g.

    {\n    "id" : 62,\n    "name" : "Client Portal",\n    "description" : "",\n    "disableAlerting" : false,\n    "stopMonitoring" : false,\n    "parentId" : 120,\n    "alertStatus" : "none",\n    "alertStatusPriority" : 100000,\n    "sdtStatus" : "none-none-none",\n    "alertDisableStatus" : "none-none-none",\n    "userPermission" : "write",\n    "rolePrivileges" : [ ],\n    "numOfDirectSubGroups" :
    0,\n    "fullPath" : "Prod/Client Portal",\n    "groupStatus" : "alive",\n    "subGroups" : [ ],\n    "hasWebsitesDisabled" : false,\n    "numOfWebsites" : 0,\n    "properties" : [ ],\n    "numOfDirectWebsites" : 0,\n    "testLocation" : {\n      "smgIds" : [ ],\n      "collectorIds" : [ ],\n      "all" : true,\n      "collectors" : [ ]\n    }\n  }, {\n    "id" : 63,\n    "name" : "Marketing Site",\n    "description" : "",\n    "disableAlerting" : false,\n    "stopMonitoring" : false,\n    "parentId" : 120,\n    "

  • Anonymous's avatar
    Anonymous

    import json

    response_dict = json.loads(response_string)

  • Anonymous's avatar
    Anonymous

    Converts from the json string to a python dictionary (equivalent to posh hashtable)

  • Anonymous's avatar
    Anonymous

    json.loads(x) takes a string (x) and converts it from json format into a dictionary. json load string.

    json.dumps(y) takes a dictionary (y) and converts it from a dictionary into a string in json format. json dump string.

  • To add to Stuart’s advice @Kelemvor , you will also need to add something similar:

    strdata = response.content

    parsed = json.loads(strdata)

    If you don’t add the bolded line above, json.loads() will not work properly. 

  • Anonymous's avatar
    Anonymous

    parsed = json.loads(response.content) works just as well. No need to set it as a variable if you’re only going to reference it once.

  • import json

    response_dict = json.loads(response_string)

    This code you shared above will not work. parsed = json.loads(response.content) will work, but not the way you previously wrote it... I illustrated further so it wasn’t as confusing for someone just getting started. 

  • Well, just bumping this because it came up again yesterday.  I was able to create a device group with no issues, but simply by change it from device/groups to website/groups made it all break.  It ended up being the version.  When I tried to add it to the URL it didn’t help.  What seemed to work was to specify it in the header like this:

    Once I did that, everything seemed to start working.  Just in case it comes up for me again, I’m documenting it here.  Or if it helps anyone else, there you go.  :)