Complex object multpart json - json

I want to build a request in insomnia to upload person, documents and it's files
How can I put a multipart file inside a JSON object? I don't want to deal with string base64 because it's too big and too slow to travel over the network.
I have a rest api made with spring boot and kotlin that will receive this JSON file.
Here's some code for what I want to achieve:
curl --request POST \
--url http://localhost:8080/ \
--header 'content-type: multipart/form-data; boundary=--
-011000010111000001101001' \
--form 'person={
"first_name": "Foo",
"last_name": "Fighters"
}' \
--form 'document=[
{
"document_name": "test1",
"document_description":"test1",
"document_file": "multipart file1"
},
{
"document_name": "test2",
"document_description":"test2",
"document_file": "multipart file2"
},
{
"document_name": "testN",
"document_description":"testN",
"document_file": "multipart fileN"
}
]'
Where the key document_file value stands for the file itself, not a String.
Some pictures to make it clear:
Here is the overview of the multipart
Person detail:
Document detail:
I need to know what files are from what documents, and I can have 0 or many documents related to the person.
Therefore, that's why adding 1 file for each document I want to create won't work. It needs to be inside the object(just like presented in the images) that way I know that file-X is from document-X and vice-versa.
Thanks in advance!

Related

No model issue for IFC Models in the Viewer

Need help on the similar topic posted below:
Autodesk Forge Viewer gives empty model (no geometry) issue on IFC file that works in BIM360
As suggested in the article, I have added the required options for the translation, and the model creates the correct derivatives. But , still the Viewer shows the same error of "model is empty. there is no geometry for the viewer to show" Please suggest, if the Viewer also needs to be handled differently to load these "modern" conversion-based files. Thanks very much.
Thank you for your reproducible model. The translation result looks fine while using the modern conversion method. I replied to you via Forge Help. It contains a snapshot of my test.
So, could you have a try? This is the code example of how I send the translation request using the modern conversion method.
Note. if you want to override an existing translation result, please be sure to set the header parameter x-ads-force: true.
curl --location --request POST 'https://developer.api.autodesk.com/modelderivative/v2/designdata/job' \
--header 'Authorization: Bearer ' \
--header 'Content-Type: application/json' \
--header 'x-ads-force: true' \
--data '{
"input": {
"urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6bXlidWNrZXQvSUZDX0JydWVja2VfS2xpbmdlbmJlcmdfNC56aXA"
},
"output": {
"formats": [
{
"type": "svf",
"views": [
"3d"
],
"advanced": {
"conversionMethod": "modern"
}
}
]
}
}'
ref: https://forge.autodesk.com/en/docs/model-derivative/v2/reference/http/job-POST/#headers

copy contents from sample json file to index elastic aearch index json file

elastic search version i am using 6.6.1
i have created index by running following command
curl -XPUT http://localhost:9200/incident_422? -H 'Content-Type: application/json' -d #elasticsearch.json
i need to update the index file with sample json data.(sample.json)
{
"properties": {
"id185": {
"type": "byte"
},
"id255": {
"type": "text"
},
"id388": {
"type": "text"
}
}
}
I tried running the command
curl -XPUT http://localhost:9200/incident_422/mapping/_doc? -H 'Content-Type: application/json' -d #sample.json
but i get the error message saying that
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"Rejecting mapping update to [incident_422] as the final mapping would have more than 1 type: [mapping, doc]"}]
i have read somewhere that ELK 6 doesnt support more than two types.
Could anyone please tell me how this can be achieved without downgrading the version
This seems to related to the removal of mapping type, you need to specify the type name while indexing the documents.
try adding type to your index request aka http://localhost:9200/incident_422/<your-type-name> in your URL and it should solve the issue.

Access Next Offset from GET http api request

I'm unable to understand pagination of Chargebee (https://apidocs.chargebee.com/docs/api) , I need to create a request in where I can add next offset to the request to get further data (without setting limit other then by default, which is 10). But i'm unable to understand how http request will be formed with this given next_offset like attached image.
Screenshot of request and response
I have had success submitting the identical request with the offset tacked onto the end. Here is an example:
First Request
curl -s https://xxyyzz.chargebee.com/api/v2/events -G -K /home/xxyyzz/.cb_curl_key.cfg --data-urlencode limit=2 --data-urlencode occurred_at[between]="[1554076800,1554077099]"
JSON results:
{
"list": [
{"event": {
"id": "ev_xxyyzz1",
"occurred_at": 1554077022,
...
"next_offset": "[\"1556428868000\",\"364450353\"]"
}
The tool I used to display the json is trying to be helpful with the backslashes.
The real next_offset value is
["1556428868000","364450353"]
Second Request
Identical to the first with
offset="["1554077017000","345017569"]"
tacked on to the end:
curl -s https://xxyyzz.chargebee.com/api/v2/events -G -K /home/xxyyzz/.cb_curl_key.cfg --data-urlencode limit=2 --data-urlencode --data-urlencode occurred_at[between]="[1554076800,1554077099]" offset="["1554077017000","345017569"]"
JSON results:
{
"list": [
{"event": {
"id": "ev_xxyyzz3",
"occurred_at": 1556429028,
}
Keep repeating the process until the "next_offset" key does not appear in the JSON result.

Making HTTP form POST request

I'm trying to make a HTTP form POST request to http://example.co.uk.
I used curl http://example.co.uk -d #example.json. However it gives me error saying it should only contain single field called application.
example.json file:
{"application":[
{
"name":"John",
"email":"john#example.com",
"github":"https://github.com/john",
"twitter":"https://twitter.com/john",
}
]
}
What's the correct way to do it? Any help will be appreciated. Thanks
You'll need to indicate to the server that the content type is JSON instead of the standard form-encoded data, so use:
curl -H "Content-Type: application/json" http://example.co.uk -d #example.json
Also, your JSON file should be valid JSON i.e. without any ending/redundant , characters, so:
{"application":[
{
"name":"John",
"email":"john#example.com",
"github":"https://github.com/john",
"twitter":"https://twitter.com/john"
}
]
}
Check the contents at http://jsonlint.com

Shopify fulfillment

The online shopify docs for fulfillment show this example:
POST /admin/orders/#{id}/fulfillments.json
{
"fulfillment": {
"tracking_number": null,
"line_items": [
{
"id": 466157049
}
]
}
}
The docs also say that not specifying an item id will cause all items to fulfill.
My postdata to that api endpoint reads:
{"fulfillment":{"tracking_number":null}}
This comes back:
{"errors":{"fulfillment":"can't be blank"}}
I have tried this:
{"fulfillment":{"tracking_number":null,"line_items":[{"id":300668234}]}}
which is a valid item id for my order. The same message comes back.
Ideas?
Are you setting your Content-Type to application/json?
Trying sending the same request using cURL
curl -X POST -H 'Content-Type: application/json' -d #fulfillment.json https://API_KEY:API_TOKEN#SHOP.myshopify.com/admin/orders/ORDER_ID/fulfillments.json
If that works, it means you aren't sending your request correctly.
curl -H "Content-Type: application/json" -X POST -d '{"fulfillment": {"tracking_number": "123456789","notify_customer": true}}' https://API_KEY:TOKEN#SHOP.myshopify.com/admin/orders/ORDER_ID/fulfillments.json
This is the working example of updating tracking number for an order. It took me a minute to realize that the ORDER_ID is the long form shopify order id. It should be about 9 to 10 digits.