Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Send Rest Request
#1
Hi,
 How to convert the following CURL code into QM code? The Chilkat C# code below can work, but the DLL is too large.
 
Thank you in advance for any suggestions and help.
David

CURL Code:
Code:
Copy      Help
curl -L \
  -X PUT \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>"\
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/repos/OWNER/REPO/contents/PATH \
  -d '{"message":"my commit message","committer":{"name":"Monalisa Octocat","email":"[email protected]"},"content":"bXkgbmV3IGZpbGUgY29udGVudHM="}'

ChilKat C# Code:
Code:
Copy      Help
Add-Type -Path "C:\chilkat\ChilkatDotNet47-9.5.0-x64\ChilkatDotNet47.dll"

$rest = New-Object Chilkat.Rest

# URL: https://api.github.com/repos/OWNER/REPO/contents/PATH
$bTls = $true
$port = 443
$bAutoReconnect = $true
$success = $rest.Connect("api.github.com",$port,$bTls,$bAutoReconnect)
if ($success -ne $true) {
    $("ConnectFailReason: " + $rest.ConnectFailReason)
    $($rest.LastErrorText)
    exit
}

# Note: The above code does not need to be repeatedly called for each REST request.
# The rest object can be setup once, and then many requests can be sent.  Chilkat will automatically
# reconnect within a FullRequest* method as needed.  It is only the very first connection that is explicitly made via the Connect method.

# Use this online tool to generate code from sample JSON: Generate Code to Create JSON
# The following JSON is sent in the request body
# {
#   "message": "my commit message",
#   "committer": {
#     "name": "Monalisa Octocat",
#     "email": "[email protected]"
#   },
#   "content": "bXkgbmV3IGZpbGUgY29udGVudHM="
# }

$json = New-Object Chilkat.JsonObject
$json.UpdateString("message","my commit message")
$json.UpdateString("committer.name","Monalisa Octocat")
$json.UpdateString("committer.email","[email protected]")
$json.UpdateString("content","bXkgbmV3IGZpbGUgY29udGVudHM=")

$rest.AddHeader("Authorization","Bearer <YOUR-TOKEN>")
$rest.AddHeader("Accept","application/vnd.github+json")
$rest.AddHeader("X-GitHub-Api-Version","2022-11-28")

$sbRequestBody = New-Object Chilkat.StringBuilder
$json.EmitSb($sbRequestBody)
$sbResponseBody = New-Object Chilkat.StringBuilder
$success = $rest.FullRequestSb("PUT","/repos/OWNER/REPO/contents/PATH",$sbRequestBody,$sbResponseBody)
if ($success -ne $true) {
    $($rest.LastErrorText)
    exit
}

$respStatusCode = $rest.ResponseStatusCode
$("response status code = " + $respStatusCode)
if ($respStatusCode -ge 400) {
    $("Response Status Code = " + $respStatusCode)
    $("Response Header:")
    $($rest.ResponseHeader)
    $("Response Body:")
    $($sbResponseBody.GetAsString())
    exit
}

The following code is not working. Why?

Macro Macro7
Code:
Copy      Help
str url = "https://api.github.com/repos/OWNER/REPO/contents/PATH"

str headers =
F
;{{
;"Accept": "application/vnd.github+json",
;"Authorization": "Bearer <YOUR-TOKEN>",
;"X-GitHub-Api-Version": "2022-11-28"
;}

str body =
F
;{{
;;;;;"message":  "my commit message",
;;;;;"committer":  {{
;;;;;;;;;;;;;;;;;;;;;;;"email":  "[email protected]",
;;;;;;;;;;;;;;;;;;;;;;;"name":  "Monalisa Octocat"
;;;;;;;;;;;;;;;;;;;},
;;;;;"content":  "bXkgbmV3IGZpbGUgY29udGVudHM="
;}

str r8 r9
Http Host.Connect(url 0 0 443)

out Host.Post("Put" body r8 headers INTERNET_FLAG_SECURE r9)
out r8
out r9
#2
I found an online tool that can convert CURL REST requests into ChilKat code for various programming languages
https://tools.chilkat.io/curl

Nowadays, REST requests are very common. How implemented in QM without using third-party components and C # code?

I made the following modifications, but still did not output
Code:
Copy      Help
str headers =
;"Accept": "application/vnd.github+json"; "Authorization": "Bearer <YOUR-TOKEN>"; "X-GitHub-Api-Version": "2022-11-28"
#3
For HTTP requests also can be used WinHttp.WinHttpRequest. Search in this forum.
If you want to use send or parse received JSON, QM does not have JSON functions. Use LA.
#4
Thank you!
it has been resolved. use the code provided in the following link.
https://www.libreautomate.com/forum/show...1#pid34071


Forum Jump:


Users browsing this thread: 1 Guest(s)