NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: rjolda on June 26, 2026, 03:24:11 PM

Title: How to translate C# API call to NT
Post by: rjolda on June 26, 2026, 03:24:11 PM
HI,
I am trying to write an API to send auto VIN number to NHTSA and get an XML or JSON return regarding the information about the auto.
This is the C# POST Code:
string text = "3GNDA13D76S000000;5XYKT3A12CG000000;";
string url = @"https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVINValuesBatch/";
var nameValues = new Dictionary<string, string>();
nameValues.Add("data", text);
nameValues.Add("format", "json");
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(url);
      
// using FormUrlEncodedContent
var name = new FormUrlEncodedContent(nameValues);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
System.Threading.CancellationToken token = new System.Threading.CancellationToken();
try
{
   var tmp = client.PostAsync(client.BaseAddress, name, token).Result;
   var result = tmp.Content.ReadAsStringAsync();
}
catch (Exception err)
{
   // error handling
}

Can anyone help translate this to NetTalk Client Post?
Thanks,
Ron
Title: Re: How to translate C# API call to NT
Post by: rjolda on June 26, 2026, 03:29:15 PM
Wow, I just put it into llamacoder.dev and this is what I got back!  Now to test it.
Here's the Clarion equivalent of your C# code:

```clarion
    PROGRAM
    INCLUDE('NetWebClient.INC')  ! Include for HTTP client functionality
    INCLUDE('StringTheory.INC')  ! Include for StringTheory class (string manipulation)
    MAP
    END

VINData        STRING('3GNDA13D76S000000;5XYKT3A12CG000000;')
URL            STRING('https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVINValuesBatch/')
Response       STRING(100000)
ErrorMsg       STRING(1000)
ST             StringTheory
WebClient      NetWebClient
PostData       CSTRING(1000)
    CODE
    ! Prepare the POST data
    ST.SetValue('data=' & VINData & '&format=json')
    ST.URLEncode()
    PostData = ST.GetValue()

    ! Configure the web client
    WebClient.SetSSL()  ! Enable SSL for HTTPS
    WebClient.SetHeader('Content-Type', 'application/x-www-form-urlencoded')
    WebClient.SetHeader('Accept', 'application/json')

    ! Make the POST request
    IF WebClient.Post(URL, PostData, Response)
        ! Success - Response contains the JSON data
        ! Process the response here
    ELSE
        ! Error handling
        ErrorMsg = WebClient.GetError()
        ! Handle error here
    END
```

Notes:
1. This uses the NetTalk WebClient class (NetWebClient) which is the standard HTTP client in Clarion
2. StringTheory is used for URL encoding the POST data
3. You'll need to have NetTalk installed in your Clarion environment
4. The response will be in the Response variable as a JSON string
5. Error handling is done through WebClient.GetError() if the request fails