How would I put the following JSON request body into the “Get Contents of URL” action with POST in Shortcuts?
GM_xmlhttpRequest({
method: 'POST',
url: 'http://ascii2d.net/imagesearch/search',
data: 'uri=https://i.imgur.com/RqikjW1.jpg',
headers: {'Content-Type': 'multipart/form-data'},
onload: function(r) {
//parse r.responseText
}
});
I don’t think your provided URL is correct, and note that it would be useful to have access to the API documentation to check details.
I think the API call has to be HTTPS, not HTTP as it gives a 307 (temporary redirect). If you follow it through, it takes you to an HTTPS page on the domain’s website. Using HTTPS, there is a 302 (temporary move), but it then goes to the same reverse image search page you would get from loading via the web site; maybe the URL is just forwarding on? That’s where the documentation would be useful.
Here’s a shortcut with a basic call.
https://www.icloud.com/shortcuts/0452f92e931442a283d639463621f073
However, looking at the results, the resulting web page returned contains lazy loading of images and relative images. Maybe if you need to extract some of the images or something you could try this enhanced version of the shortcut.
https://www.icloud.com/shortcuts/3b7e3e3a78cc42f8b55445862a1bec06
If you instead wanted to go to the search page on the web site, take a look at the image ID that makes up the filename of the first image in the HTML (376c3c86f01eaf29d7e4ee1ec3cb4b36
). You can pull that out of the HTML returned from the API, and use it in a URL to open the page.
The base URL is https://ascii2d.net/search/color/
, so you just append the image ID, and open the resulting URL.
https://ascii2d.net/search/color/376c3c86f01eaf29d7e4ee1ec3cb4b36
There is actually a bit of a shortcut we can take in doing that and implicitly get the URLs from the results and match for /search/color/
at the start of the URL. Something like this:
https://www.icloud.com/shortcuts/988a2865ed36484db9820e6e0a34bec6
Hope that helps.
2 Likes
Thank you! This is exactly what I was looking for.