Shopify fulfillment - json

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.

Related

Complex object multpart 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!

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.

Swagger API - multiple #ApiImplicitParam for JSON POST

I am trying to create my first REST app and I am using Swagger to document and test it. My controller receives POST in JSON:
"body": {
"search_query" : "text",
"page" : 1
}
I thought I can annotate controller like this:
#ApiImplicitParams({
#ApiImplicitParam(name="search_query",value="Text to search for",required = false,dataType = "String",paramType = "body"),
#ApiImplicitParam(name="page",value="Page number",required = true,dataType = "int",paramType = "body")
})
But generated curl looks like this:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '1' 'http://localhost:9000/api/search'
And this is not what I am looking for.. , then I found out I can not have 2 body parameters. But how do I annotate my controller then , if I do not want to create class for this data and annotate it with model?

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

Grails command object and 404 when space inside JSON from CURL

I have inherited a controller.
When a post request is made, with a well structured JSON document everything is fine.
When the JSON contains a space in a feld, 404 is returned.
However, when the same request is made from mozilla restclient extension everything works.
The CURL request specifically is:
curl --include \
--request POST \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data-binary "{
"planCode" : "My Test App-standard"
}" \
"https://localhost/signupApi/v2/signup"
URLMapping:
"/signupApi/v2/$action"{
parseRequest = true // parse json, and assign to params
controller = "signupApiSignup"
}
So, why would a space in curl cause problems in the request body that grails receives?
Thanks
You are not quoting your strings there properly in your shell. Use ' for your parameters, if you plan to use "sensitive" chars like " there. Or use \" inside. Also curl can read a filename if you prefix it with # instead of the actual data.
Yet in this case maybe quoting with ' is easiest. E.g.:
...
--data-binary '{
"planCode" : "My Test App-standard"
}'
...