Android Question Curl Multi parts (Map) within MultipartPost (array with in array)

fasilosman

Active Member
Licensed User
Longtime User
I use okhttp for Curl with multipartpost.
there is an array within the multipart map/array variable
But I don't have idea to implement it.
following is the Curl
.....................
curl -X POST https://example.com/wp-json/wc/v2/products \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"name": "Ship Your Idea",
"type": "variable",
"description": "New Ideas and thoughts",
"attributes": [ {
"id": 6,
"name": "Color",
"visible": false,

"options": [
"Black",
"Green" ]

]
}
}
...................................

I Tried the following. I have no idea how to put the attribute and options. Therefore I can't continue
further
........................
Dim NV As Map
NV.Initialize
NV.Put("name", "Ship Your Idea")
NV.Put("type", "variable")
NV.Put("description", "New Ideas and thoughts")
NV.Put("attributes",???????????
Dim req As OkHttpRequest
req = MultipartPost.CreatePostRequest("https://example.com/wp-json/wc/v2/products", NV, Null)
req.SetHeader("Content-Type", "application/json")
req.SetContentType("application/json")
req.SetContentEncoding("text/plain")
hc.ExecuteCredentials(req,1,"consumer_key","consumer_secret")
...............................................................

I am a beginner. Can anyone please help me in this regard...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.

The first step is to use OkHttpUtils2. It also supports multipart requests, though you don't need one here.
You need to create a json string and send it with HttpJob.PostString. You also need to set HttpJob.GetRequest.SetContentType and set Job.Username / Password.
 
Upvote 0
Top