Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV forum
Answered

How to Create a simple Json file be sent using PUT method

Posted on by 70

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);

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!

Thank you

  • Ebitas Profile Picture
    Ebitas 70 on at
    RE: How to Create a simple Json file be sent using PUT method

    Thanks for your help

  • Ebitas Profile Picture
    Ebitas 70 on at
    RE: How to Create a simple Json file be sent using PUT method

    Thanks for your help.. that did it..

  • Verified answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,640 on at
    RE: How to Create a simple Json file be sent using PUT method

    You can use the StringContent, try to check the codeunit 7820 in the later version of NAV.

  • Hannes Holst Profile Picture
    Hannes Holst 5,767 on at
    RE: How to Create a simple Json file be sent using PUT method

    Hi,

    Maybe this blog helps?

    https://dynamics.is/?p=2303

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,564 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,651 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans