Need Restful API functionality
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-08-07 03:58 AM - last edited on ‎2022-09-29 10:19 AM by Daniel Kassai
‎2019-08-07
03:58 AM
Hi
I noticed that there are header files for HTTP and JSON. Does Archicad 22 have the ability to do Restful calls?
I have tried, with no luck, to get 3rd party Casablanca HTTP library to work in a project.
Please help
Archicad 22
Windows
I noticed that there are header files for HTTP and JSON. Does Archicad 22 have the ability to do Restful calls?
I have tried, with no luck, to get 3rd party Casablanca HTTP library to work in a project.
Please help
Archicad 22
Windows
Labels:
- Labels:
-
Add-On (C++)
5 REPLIES 5
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2019-08-07 07:12 AM
‎2019-08-07
07:12 AM
Ok I have found examples in Goodies example project. Now having a problem with Casting to Json object, throws an exception. I am able to retreive the response data as text but I really need a JSON object
/* throws exception at GS::DynamicCast<JSON::ObjectValue>(parsed); */
DBPrintf("HTTP %u\n", response.GetStatusCode());
if (response.GetStatusCode() == StatusCode::OK) {
JSON::ObjectValueRef object = GS::DynamicCast<JSON::ObjectValue>(parsed);
JSON::StringValueRef tokenValue = GS::DynamicCast<JSON::StringValue>(object->Get("regionName"));
if (tokenValue != nullptr) {
GS::UniString token = tokenValue->Get();
DBPrintf("NBS Token: %s\n", token.ToCStr().Get());
}
}
/* Working but text only */
SAJParser saxParser;
ExampleSAJParseTracer testSAXParseTracer;
saxParser.Parse(clientConnection.BeginReceive(response), testSAXParseTracer);
if (testSAXParseTracer.ParseFinished()) {
DBPrintf("The content of the JSON file was:\n%s\n", testSAXParseTracer.GetOutput().ToCStr(0, MaxUSize, CC_UTF8).Get());
}
clientConnection.FinishReceive();
clientConnection.Close(false);
}
catch ( std::exception&)
{
std::string error;
}
/* throws exception at GS::DynamicCast<JSON::ObjectValue>(parsed); */
DBPrintf("HTTP %u\n", response.GetStatusCode());
if (response.GetStatusCode() == StatusCode::OK) {
JSON::ObjectValueRef object = GS::DynamicCast<JSON::ObjectValue>(parsed);
JSON::StringValueRef tokenValue = GS::DynamicCast<JSON::StringValue>(object->Get("regionName"));
if (tokenValue != nullptr) {
GS::UniString token = tokenValue->Get();
DBPrintf("NBS Token: %s\n", token.ToCStr().Get());
}
}
/* Working but text only */
SAJParser saxParser;
ExampleSAJParseTracer testSAXParseTracer;
saxParser.Parse(clientConnection.BeginReceive(response), testSAXParseTracer);
if (testSAXParseTracer.ParseFinished()) {
DBPrintf("The content of the JSON file was:\n%s\n", testSAXParseTracer.GetOutput().ToCStr(0, MaxUSize, CC_UTF8).Get());
}
clientConnection.FinishReceive();
clientConnection.Close(false);
}
catch ( std::exception&)
{
std::string error;
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-08-19 09:56 AM
‎2020-08-19
09:56 AM
Has anyone else worked with the JSON parsing in the ArchiCAD API? I am facing a similar problem to Bianca's example above.
I can get the response data as text no worries, but cannot seem to get a member string value cast to GS::UniString.
I can get the response data as text no worries, but cannot seem to get a member string value cast to GS::UniString.
Anonymous
Not applicable
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2020-09-18 09:57 AM
‎2020-09-18
09:57 AM
Use a JSON::JDOMParser to parse the client's response into a JSON object:
HTTP::Client::Response response;
JSON::JDOMParser parser;
JSON::ValueRef parsed = parser.Parse(client->BeginReceive(response));
// check statuscode
auto statusCode = response.GetStatusCode();
if (statusCode == HTTP::MessageHeader::StatusCode::OK) {
JSON::ObjectValueRef object = GS::DynamicCast<JSON::ObjectValue>(parsed);
// do whatever you need with 'object'
}
HTTP::Client::Response response;
JSON::JDOMParser parser;
JSON::ValueRef parsed = parser.Parse(client->BeginReceive(response));
// check statuscode
auto statusCode = response.GetStatusCode();
if (statusCode == HTTP::MessageHeader::StatusCode::OK) {
JSON::ObjectValueRef object = GS::DynamicCast<JSON::ObjectValue>(parsed);
// do whatever you need with 'object'
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2021-06-16 10:22 AM
‎2021-06-16
10:22 AM
Kengey wrote:Can you please write some code after "//do whatever you want", like how to get values from the object?
Use a JSON::JDOMParser to parse the client's response into a JSON object:
HTTP::Client::Response response;
JSON::JDOMParser parser;
JSON::ValueRef parsed = parser.Parse(client->BeginReceive(response));
// check statuscode
auto statusCode = response.GetStatusCode();
if (statusCode == HTTP::MessageHeader::StatusCode::OK) {
JSON::ObjectValueRef object = GS::DynamicCast<JSON::ObjectValue>(parsed);
// do whatever you need with 'object'
}
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2021-06-17 04:31 PM
‎2021-06-17
04:31 PM
I found another parser here.
C:\Program Files\GRAPHISOFT\API Development Kit 24.3009\Support\Modules\RapidJSON
Documentation for rapidJSON
It gave me better results and the code is much more readable.
C:\Program Files\GRAPHISOFT\API Development Kit 24.3009\Support\Modules\RapidJSON
Documentation for rapidJSON
It gave me better results and the code is much more readable.