formcreator icon indicating copy to clipboard operation
formcreator copied to clipboard

Insert question into Form via Api apirest.php/PluginFormcreatorQuestion

Open blackmagic42 opened this issue 1 year ago • 1 comments

Hello I'm trying to insert questions into form with the Api But i got this error because i don't have the good parameters "ERROR_GLPI_ADD","Vous n'avez pas les droits requis pour r\xc3\xa9aliser cette action."

This is my code

`import requests import json

def add_form_question(session_token,id,name,description,port):

data = json.dumps(
{   "input": {
        "items_id": id,
        "itemtype": "",
        "entities_id": 1,
        "row": 3,
        "col": 1,
        "width": 5,
        "show_rule": 1,
        "name": name,
        "is_recursive": 0,
        "required": 0,
        "fieldtype": "textarea",
        "description": description,
        "values": None,
        "uuid": None,
        "required": 0,
        "show_empty": 0,
        "default_values": '',
        'links': {},
        "_parameters[textarea][regex][regex]": "",
        "_parameters[textarea][range][range_min]": 0,
        "_parameters[textarea][range][range_max]": 0,
        "_conditions[show_logic][]": 1,
        "_conditions[plugin_formcreator_questions_id][]": 24, #don"t worry it's the good id because i have done it with burp 
        "_conditions[show_value][]": port,
    }
})
response = requests.post(f"XXXXXX/apirest.php/PluginFormcreatorQuestion/{id}", #don't worry i got the good url in my code
    headers={
        "Content-Type": "application/json",
        "Session-Token": session_token,
        "App-Token": "XXXXXX", #don't worry i have put my app token here 
    },
    data=data
)
if response.status_code == 200 or response.status_code == 206:
    data = response.json()
    print(data)
    return data
else:
    print(response.content)
    raise Exception(f"Erreur lors de l'ajout d'un ordinateur : {response.status_code}")

`

blackmagic42 avatar Nov 22 '23 15:11 blackmagic42

Hi

It seems you did not specified in which section the question is inserted. Try again by setting the parent section in the request.

btry avatar Nov 29 '23 07:11 btry