Right way to send a URL in a JSON response - json

I have a backend that will respond to a mobile frontend like this:
{
"id": 12345,
"url": "https://www.example.com?origin=Papá"
}
The problem is, the param origin in the URL has an accentuation mark, so in iOS the parser breaks and the link does not work.
So what I thought about doing was to encode the entire URL. So my response would look like this:
{
"id": 12345,
"url": "https%3A%2F%2Fwww.example.com%3Forigin%3DPap%C3%A1"
}
Is this correct? Should I do this? What is the right way to go about sending URLs in a JSON response?

Related

Graph API: JSON batching to upload item to OneDrive is failing

I am trying to upload a text file to OneDrive using Graph APIs and I also want to update it in the same request using JSON batch.
My JSON request body is below:
{
"requests":[
{
"id":"1",
"method":"PUT",
"url":"/drives/b!ddubdQaackeT9nu3x4onivgPxHH2-
gpFsk_mo9hryZabqK7w279YSpMqiNodZDaa/items/01BTTSDZ56Y2GOVW772
5BZO354PWSELRRZ:/abc2.txt:/content",
"headers":{
"Content-Type":"application/octet-stream",
"Content-Length":"21"
},
"body":{
"content":"Test content for body"
}
},
{
"id":"2",
"method":"PATCH",
"url":"/drives/b!ddubdQaackeT9nu3x4onivgPxHH2-
gpFsk_mo9hryZabqK7w279YSpMqiNodZDaa/items/01BTTSDZ56Y
2GOVW7725BZO354PWSELRRZ:/abc2.txt",
"headers":{
"Content-Type":"application/json; charset=utf-8"
},
"body":{
"fileSystemInfo":{
"lastModifiedDateTime":"2020-08-09T00:49:37.7758742+03:00"
}
},
"dependsOn":["1"]
}
]
}
When I send this request from my code, I always get a response "Invalid body for request id: 1. The body must be a valid base64 string or JSON.".
Postman refused to run the above request with the message "Method not allowed".
In the above example, I am uploading and updating text files but my code will have to handle all file types (e.g. images, videos, etc.)
Not sure if I am correctly specifying all the JSON fields. Unfortunately unable to find much info on this. Any help would be appreciated.

string in response instead of a correct JSON format

How to tell my customer's provider to send the response in a valid format, or I misunderstood something?
The response I get is:
{
"Code": "202",
"Message": "BUIxxxxxxxxxxxxxxxxxxxxxLUE",
"Status": "SUCCESS",
"Data": "{\"PRxxxxxxX\":\"2712.0000\",\"TRANSACTION_ID\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"REMARKS\":\"SUCCESS\"}"
}
My problem is that, I can not map back the Data section this way, so I have to trim out values with an excel, which is not a good solution in long term (like =LEFT(D8,FIND("TRANSACTION_ID",D8,18)-4))
When I told him this he replied the following:
"we are serializing the object hence slash is added automatically (below is the screen shot)
apiResult.Data = JsonConvert.SerializedObject(
**The slash will not appear in the actual output"

How to post file along with json data in Postman?

I know how to post json and I know how to post file in multipart form in Postman. But how can I do both together. For example:
Here is my jason to post:
{
"title": "Post title yeah",
"body": "My first post body"
}
So how can I post image.jpg located at /home/me/Desktop along with the the above json?
UPDATE: Note that I want so send file using JSON, so my question is different from this which is about multipart form sending using Postman.
You can use this online tool to convert your file to a base64 (https://www.browserling.com/tools/file-to-base64), then you can send it as part of the json. I reduced the size of the base64 string for the answer.
{
"title": "Post title yeah",
"body": "My first post body",
"image": "JVBERi0xLjQKJeLjz9MKMiAwIG9iago8PC9MZW5ndGggMjcyNS9GaWx0ZXIvRmxhdGVEZWNvZGU+PnN0cmVhbQpYCb1c247byBF9X8D/0MC+JIFNs5t9IY0gwHicXRjI2GOPvPsQ5EGrocdKRGmiofby9+kmu5t901BFKoLhi8qqc04Xq07zZr/47r8olz84JlmORKV+3dfoZ7R9If8GcxVkeUZLjijNBEOYZhgT+523C/T6hwJVWVVVaPG1w5IID4gxluESLf6BMMuqkkqYImOMoMU9+tPH/X29R9+/+TNa/Bst/oL+vnjx3aeBkJcZqwQilfwwnU/gjFe843u3bOuYjHcLUstjVYlwgfX6cp+NJtgoI5no6RQKKSWMTGQ9HaG4EDzio2o9QshqckkjMklGMsJAbAqjIBKlyHJOO7acvCb8NcnlFzB7g+kbUqbrykUla0kR491CeVZFdcV4vLC8JFlJy477bre5R4v"
}

Cannot update fulfillment in Shopify

I have this: PUT/admin/orders/450789469/fulfillments/255858046.json in updating the fulfillment.
I have this following json data to update:
{ "fulfillment": {"id":3604167143,"order_id":4015640143,"status":"success","tracking_numbers":"6J700123456","variant_inventory_management":"shopify"}}
It returns a 400 error - Bad request.
Is there anything I've missed in passing the data to update? Thanks.
You'll want to send tracking_numbers as an array, rather than a string. Try something like this:
{
"fulfillment": {
"id": 3604167143,
"order_id": 4015640143,
"status": "success",
"tracking_numbers": ["6J700123456"],
"variant_inventory_management": "shopify"
}
}
If you look in the body of the response from Shopify then you can sometimes find more info about what went wrong.

Search ElasticSearch via GET using JSON

Anyone know of a way to send a JSON query to an ElasticSearch server via HTTP GET? I know you can POST the JSON content to _search, but POST is not available because this is cross-domain. For example, if my query looks like this:
{
"query": {
"query_string": {
"fields": ["name", "description"],
"query": "Elastic Search"
}
}
}
Which I would convert to something like:
{"query":{"query_string":{"fields":["name","description"],"query":"Elastic Search"}}}
Is there a way to GET server:9200/index/type/_search?content=stringifiedquery or something similar? I've tried q= and content= as well as just passing the content after the ? but nothing seems to work. Anyone have any ideas? Or am I just out of luck?
You can use the source query string parameter to send what would normally be the post body.
See the bottom of this page: http://www.elasticsearch.org/guide/reference/api/