Problems calling WebActions from Rest-API

edited October 2020 in General
Hi,
I'm trying to call a web action with a Rest-API call. However I always get the {ok:false} back.
This is my request uri: http://192.168.10.112:3344/printer/api/Prusa_i3_MK3S?a=webCallExecute&data={%22Name%22:%22LightsOff%22%2c%22Params%22:[%22test%22]}&apikey=....

I took the format from the Websocket action:
  1. {action: "webCallExecute", data: {name: "LightsOff", params: ["Test"]}, printer: "Prusa_i3_MK3S",…}
    1. action: "webCallExecute"
    2. callback_id: 1402
    3. data: {name: "LightsOff", params: ["Test"]}
    4. printer: "Prusa_i3_MK3S"

Is there anything I miss? The websocket returns {ok:true} for the action above, only the Rest-API call seems not to work.
This is the C# call of it.

                var client = new RestClient(string.Format("{0}{1}:{2}", httpProtocol, ServerAddress, Port));
                var request = new RestRequest(!string.IsNullOrEmpty(PrinterName) ? "printer/api/{slug}" : "printer/api");
                request.RequestFormat = DataFormat.Json;
                request.Method = Method.POST;
                request.Timeout = 2500;

                if (!string.IsNullOrEmpty(PrinterName))
                {
                    request.AddUrlSegment("slug", PrinterName);
                }
                request.AddParameter("a", Command, ParameterType.QueryString);
                request.AddParameter("data", JsonConvert.SerializeObject(JsonData), ParameterType.QueryString);
                request.AddParameter("apikey", API, ParameterType.QueryString);
                var fullUri = client.BuildUri(request);
                var respone = await client.ExecuteAsync(request);
                var result = respone.Content;

Thanks for your help!

Comments

  • edited October 2020
    Hope it is not real api key you publish here:-)

    Correct link is:
     http://192.168.10.112:3344/printer/api/Prusa_i3_MK3S?a=webCallExecute&data={%22name%22:%22LightsOff%22%2c%22params%22:[%22test%22]}&apikey=...


    Watch you with parameter names! They are case sensitive so "name" not "Name" and "params" not "Params"
  • Hi,
    thanks for your help. It's working now with this url.
    Yes it is, would yo mind if you edited the posts and remove the key?

    Thank you!
  • I have edited the key but maybe better to change it. In global settings->connectivity you can change it with a new one.
  • Repetier said:
    I have edited the key but maybe better to change it. In global settings->connectivity you can change it with a new one.
    New key generated, thanks! I thought it doesn't matter because the print server is only reachable in the home network.

  • In deed as long as it is in your intranet it does not matter except anyone having access to it might now know. So risk is minimal. But would you think of it when you decide to open it?
Sign In or Register to comment.