LISP function with REST POST API, is it doable ?

LISP function with REST POST API, is it doable ?

Antonin_JubaultSRF25
Participant Participant
556 Views
4 Replies
Message 1 of 5

LISP function with REST POST API, is it doable ?

Antonin_JubaultSRF25
Participant
Participant

Hi,

 

I want to go on a journey with LISP and before doing so, I thought  I would ask you guys if it's doable.

 

I want to send a request to a server with a parameter and based on the json answer, use this data to insert a specific bloc into my drawing.

 

Here is an example :

 

Let's say I have a server with a house made of rooms who host parameters. Everything in a json file like

[{'house': [{'room_name:bedroom':},{'room_name:kitchen':}]}]

 

From Autocad, I want the user to be able to call a function with a parameters like "Kitchen" (enter with keyboard) and this function will send a REST POST request to my server which will send back a json file answer and on the autocad side I will be able to use the json value to INSERT block who are having those name "kitchen" into my drawing.

 

Is it possible ?

 

Don't hesitate to ask me question if I am not clear 🙂

 

Thank you so much, so far the help I have received from this community has been amazing.

 

AJ.

0 Likes
557 Views
4 Replies
Replies (4)
Message 2 of 5

Antonin_JubaultSRF25
Participant
Participant

Update : 

I have seen the amazing work from CodeDing here
Make an API call with AutoLISP / VisualLISP 

 

Can we update it so a POST function is used and pass a parameter ?

0 Likes
Message 3 of 5

Michiel.Valcke
Advisor
Advisor


If you can get the Json as a text string or text file you can read the file with lisp and since you know the structure of the json and what to expect you can write a function to query or select the values that are interesting for you. 
https://help.autodesk.com/view/OARX/2025/ENU/?guid=GUID-AC74D827-0969-4888-91C0-C3149DEC3659


I have used similar ideas to read .xml or .ini files to get settings for a program or do secondary license checks etc... 

 

You can also write files. I've used this to write .csv reports, temporary .lin or .pat files, etc...

0 Likes
Message 4 of 5

CodeDing
Advisor
Advisor

@Antonin_JubaultSRF25 ,

 

Yes, it is possible. Below is some code that makes a POST request to a real website. And shows you the successful (fake, but still successful) response. I love this free testing site, I use them often to test code.

 

Here is the example from the website, scroll down to "Creating a resource" :

https://jsonplaceholder.typicode.com/guide/ 

 

The code:

(defun c:TEST ( / url data http_object response)
  (setq
    url  "https://jsonplaceholder.typicode.com/posts"
    data
      (strcat
        "{"
          "\"title\" : \"foo\","
          "\"body\"  : \"bar\","
          "\"userId\"  : 1"
        "}"
      );strcat
    http_object (vlax-create-object "WinHTTP.WinHTTPRequest.5.1")
  )
  (vlax-invoke-method http_object 'open "POST" url :vlax-false)
  (vlax-invoke-method http_object 'SetRequestHeader "Content-type" "application/json; charset=UTF-8")
  (vlax-invoke-method http_object 'send data)
  (setq response (vlax-get-property http_object "ResponseText"))
  (if http_object (vlax-release-object http_object))
  (alert response)
  (princ)
)

 

Best,

~DD

0 Likes
Message 5 of 5

Antonin_JubaultSRF25
Participant
Participant

Amazing thank you so much !

0 Likes