How to createsimple JSON file with Dynamics Nav

ebitas
Member Posts: 71
Using REST services I'm trying create a simple file to pass it Using the PUT method. example: the content should look like this ["WO_1234"]
I'm using the following function:
HttpClient := HttpClient.HttpClient();
//HttpClient.DefaultRequestHeaders.Add('x-api-operation',dhbOperation);
HttpClient.DefaultRequestHeaders.Add('x-api-key','GPES0dkIMv2jTdpo2SWyQ7vlYF03v9uc2aouKIul');
HttpClient.DefaultRequestHeaders.Add('Authorization',dhbAuthText);
HttpClient.DefaultRequestHeaders.Add('ContentType','application/json');
HttpClient.BaseAddress := Uri.Uri(BaseURL);
//MESSAGE('%1',dhbAuthText);
CASE RestMethod OF
'GET':
HttpResponseMessage := HttpClient.GetAsync(Method).Result;
'POST':
HttpResponseMessage := HttpClient.PostAsync(Method,HttpContent).Result;
'PUT':
HttpResponseMessage := HttpClient.PutAsync(Method,HttpContent).Result;
'DELETE':
HttpResponseMessage := HttpClient.DeleteAsync(Method).Result;
END;
HttpResponseMessage.EnsureSuccessStatusCode();
String := HttpResponseMessage.Content.ReadAsStringAsync.Result;
My question is: how to I create HttpContent to be used in the PUT method?
I see examples on the web for JasonTextWriter but it requires Propertyname Exaple: [{"Workorder":"WO_1234"}] . I just need to pass the value without property name ["WO_1234"].
Please help
Thanks
I'm using the following function:
HttpClient := HttpClient.HttpClient();
//HttpClient.DefaultRequestHeaders.Add('x-api-operation',dhbOperation);
HttpClient.DefaultRequestHeaders.Add('x-api-key','GPES0dkIMv2jTdpo2SWyQ7vlYF03v9uc2aouKIul');
HttpClient.DefaultRequestHeaders.Add('Authorization',dhbAuthText);
HttpClient.DefaultRequestHeaders.Add('ContentType','application/json');
HttpClient.BaseAddress := Uri.Uri(BaseURL);
//MESSAGE('%1',dhbAuthText);
CASE RestMethod OF
'GET':
HttpResponseMessage := HttpClient.GetAsync(Method).Result;
'POST':
HttpResponseMessage := HttpClient.PostAsync(Method,HttpContent).Result;
'PUT':
HttpResponseMessage := HttpClient.PutAsync(Method,HttpContent).Result;
'DELETE':
HttpResponseMessage := HttpClient.DeleteAsync(Method).Result;
END;
HttpResponseMessage.EnsureSuccessStatusCode();
String := HttpResponseMessage.Content.ReadAsStringAsync.Result;
My question is: how to I create HttpContent to be used in the PUT method?
I see examples on the web for JasonTextWriter but it requires Propertyname Exaple: [{"Workorder":"WO_1234"}] . I just need to pass the value without property name ["WO_1234"].
Please help
Thanks
0
Best Answer
-
You could try something like this:
StrContent := StrContent.StringContent('["WO_1234"]');
Where StrContent isName DataType Subtype Length StrContent DotNet System.Net.Http.StringContent.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
And pass this variable how HttpContent.1
Answers
-
You could try something like this:
StrContent := StrContent.StringContent('["WO_1234"]');
Where StrContent isName DataType Subtype Length StrContent DotNet System.Net.Http.StringContent.'System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
And pass this variable how HttpContent.1 -
ftornero; That did it. Thank you so much for your help..0 -
Thanks juhl for your comment. How would I use Json and you have mentioned jarray? can you please explain?
Thanks0 -
I have been searching for this blog for a long time and by now I am able to get it to read. Keep sharing more.
Best TOEFL Coaching in Chennai | Spoken English Classes in Coimbatore | English Speaking Classes in Mulund | Spoken English Classes in JP Nagar-3 -
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions