Api use, JSON POST request

Post your questions and help other users.

Moderator: Martin

Post Reply
GhostTheToast
Posts: 3
Joined: 10 Nov 2017 20:03

Api use, JSON POST request

Post by GhostTheToast » 12 Nov 2017 06:34

Hey guys,

I'm new to AutoMagic and was wondering what is the most advised way to use send JSON Post request to an API? I'm using Toggl's API, more specifically the start and stop timer calls, but I can't seem to figure out how to go about it with AutoMagic. If I need send screenshots, let me know.

Thank you,
Ghost

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Api use, JSON POST request

Post by Martin » 12 Nov 2017 19:59

Hi,

You can use action HTTP Request with request method POST and content type General Text to send the request. You will likely have to prepare the entire JSON data in an action Script in a variable (e.g. json_data) and then just reference the variable in the action HTTP Request in field data with {json_data}.

Regards,
Martin

GhostTheToast
Posts: 3
Joined: 10 Nov 2017 20:03

Re: Api use, JSON POST request

Post by GhostTheToast » 13 Nov 2017 00:27

Awesome, Thank you!

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Api use, JSON POST request

Post by Desmanto » 13 Nov 2017 08:10

You can look more example of using http API request at here
viewtopic.php?f=6&t=6748

To create JSON data, you can create a map first, using newMapFromValues(). Then use toJSON() to convert the map to JSON, or simply just show the variable in jsonformat >> {data,jsonformat}

Look at this for example of creating and sending the JSON.
viewtopic.php?f=5&t=3088
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

Post Reply