Post Request With API

Hello Dear Coders,

I want to post request with my web api and this way my web site can create an order.
When i tried this method in kodular it is worked! but not for all datas.
Here is my kodular blocks;
Web url format is: https://example.com/ /wp-json/wc/v3/orders?consumer_key=ck_xxxx&consumer_secret=cs

With above blocks i can succesfully post with main array which are “payment_method”,“set_paid”,“payment_method_title” but i can not post first name, last name under the “billing” array. How can i run this ?,
The api intruction is in below,

1 Like

Try PostText with a string of parameters:

for example

.PostText text > join > firstname=tttt&lastname=zzz&city=yyy

(note no question mark needed for the first parameter when using PostText)

2 Likes

Hello they are sub strings i have already try this it is not working what is your suggestion to run sub strings ?

Create your POST parameters with Join .

Can you explain more detaily with block ?

If I must…

image

If as you say, these are substrings, you may need to either:

  1. add an “&” to the first item parameter
    or
  2. Place all of your parameters in your posttext join block
1 Like

Maybe :

I have tried your method posting funciton is working but sub string is data first name is not posted.

Main string is “billing”
and sub string is “first-name” and this is what i tried;

you didn’t add a value to the billing parameter…

yes i am trying to add for first name value but first name string is under string to billing data.

In this block remove & and try

It will print as first name=text box.text

sorry, did not worked. and it does not make sense because in my json data both under the billing object and shipping object includes “first_name” string.

I am sorry, I have not being paying attention! You probably need to manually create a json string for your “substring”. Back in a minute with an example here…

Like this ?

image

You may need to post all your parameters in a json string…

1 Like

you also have to set the Content-Type in the request header…
your Content-Type is application/json
see an example here App Inventor Tutorials and Examples: Dropbox | Pura Vida Apps
and you have to put together your json string manually as @TimAi2 already mentioned…

Taifun

2 Likes

Hello Dear All,

I have tried all your methods what you told me but never worked. What is my fault ?
Here is my blocks.

Here is documantetion about api;

https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#create-an-order

Remove the single quotes from the beginning and end of your JSON string?

'{ > { and }' > }

Try billing outside of the JSON with an equals sign ?

Hello,

did not worked. As i said before, all main object i can post but sub strings i could not posted.

follow @TimAi2 's advice…
and post a screenshot of your complete JSON string… where are your substrings?

also use Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools

and then you might want to verify your JSON string in an online tools like https://jsonlint.com/
in the end your JSON string must look like exactly as in the example
https://kodular-community.s3.dualstack.eu-west-1.amazonaws.com/optimized/3X/7/9/799527aabc424f08e99231be81fe5b9f039dcb1d_2_1035x345.png

Taifun

Hi Taifun

Please , can you tell me how can i setup but not for header but for the Body ? Is it Possible to setup not the header but the Body with by example ==> Content-Type ?

There are many examples here in comunnity.

:point_down: Did You search ? :face_with_monocle:

:mag: Web Component API post

https://community.kodular.io/search?context=topic&context_id=113224&q=Web%20Component%20API%20post&skip_context=true

https://community.kodular.io/search?context=topic&context_id=113224&q=Web%20Component%20API%20post&skip_context=true

1 Like