How do I add a relation to my parse.com object using the REST API? - rest

I have two classes, the standard User and my custom class Story.
Every User can have one or more Story. I can save a new User, I can save a new Story (from my .net application using parse.com REST API), but how do I create a relation between them?
I see this example in the documentation:
curl -X PUT \
-H "X-Parse-Application-Id: MY APP KEY" \
-H "X-Parse-REST-API-Key: MY REST KEY" \
-H "Content-Type: application/json" \
-d '{"User":{"__op":"AddRelation","objects":[{"__type":"Pointer","className":"_User","objectId":"Vx4nudeWn"}]}}'
https://api.parse.com/1/classes/Story/Ed1nuqPvcm
How do I "put" this in using POSTMAN (chrome addon) for instance? What is "-d" in this case, it doesnt seem to be a normal url parameter?
Thanks!

I'm not sure but it seems you have a double question there. The first one, on how to create a parse relation via rest api, you answered with the curl example.
About using postman, you can specify the json content under the raw tab (check the image bellow). Also make sure the content type is set to JSON (application/json), in the blueish dropdown next to the tabs.
I've tested and worked fine. Hope it helps.
Cheers.

Related

Is there a way of getting only the issues without a certain label using the GitHub Api

I have the following
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
https://api.github.com/repos/OWNER/REPO/issues?labels=label
Currently I am only able to get the issues that have a certain label using the GitHub api, is there a way to get all the issues that doesn’t have a specific label using the GitHub api?
Based on github DOC, It's not possible
labels string
A list of comma separated label names. Example: bug,ui,#high
One solution would be to implement it. You can get all the issue then iterate using a loop to remove the issue that has the specific label

Understanding the GET/POST/DELETE requests on a basic level?

I'm currently learning to use REST API (from WooCommerce in this case) and got some basic questions:
How to see complete request string in Postman software?
I'm testing a simple GET request which works great with for example:
<host>/wp-json/wc/v3/products
to receive the product list. In this case I use the authorization tab to enter my user/pass as Basic Auth.
I also tested curl.exe using another simple Windows command prompt. This also returned product list:
curl.exe <host>/wp-json/wc/v3/products -u mykey:mysecret
What is the difference between them? The last example is a simple GET, i assume, although it's not stated. How about POST or DELETE etc? This is what i don't understand: A https request can only have an address and eventual parameters. Where and how does "GET" come into the picture?!
If possible, I would like the see the complete URL request (as one string) from the working Postman example?
My last question is about testing the same method on another server/service which is not WooCommerce. Afaik this service is created with something called swagger:
curl "<host>/orderapi/item" -H "accept: application/json" -H "X-Customer: <customer>" -H "X-ApiKey: <mykey>" -H "X-ApiSecret: <mysecret>" -H "Content-Type: application/json"
This also returns a list of, in this case orders instead of products. All good.
But for this example I haven't figured out how to achieve the same request in Postman. What auth method should I use?
And again, I don't understand the GET/POST/DELETE thing. And I also would like to see the complete request as one-string.
1) How to see complete request string in Postman software? I would like the see the complete URL request (as one string) from the working Postman example
On version 9.x.x:
The code window(image) shows the choosen method (yellow mark) and the code window(red arrow), where you get the actual
curl code(image)
2) What is the difference between them? The last example is a simple GET, i assume, although it's not stated. How about POST or DELETE etc? Where and how does "GET" come into the picture?
From the curl documentation:
-X, --request
(HTTP) Specifies a custom request method to use when communicating
with the HTTP server. The specified request method will be used
instead of the method otherwise used (which defaults to GET). Read the
HTTP 1.1 specification for details and explanations. Common additional
HTTP requests include PUT and DELETE, but related technologies like
WebDAV offers PROPFIND, COPY, MOVE and more.
GET is the default method for curl, which means:
curl.exe <host>/wp-json/wc/v3/products -u mykey:mysecret
is the same as:
curl.exe <host>/wp-json/wc/v3/products -u mykey:mysecret -X "GET"
so, for a POST/DELETE/... you should change your '-X' parameter for example:
curl.exe <host>/wp-json/wc/v3/products -u mykey:mysecret -X "POST" [...otherOptions]
(Assuming that you can receive a POST on the url above)
3) [On another server/service] I haven't figured out how to achieve the same request in Postman. What auth method should I use?
The -H specify the header parameter you are passing. You have those in your example:
accept: application/json
X-Customer:
X-ApiKey:
X-ApiSecret:
Content-Type: application/json
You need to add those in your postman on the headers(image) tab. In this case you don't need to specify a auth method, once you're sending the ApiKey on the header. In addition to that, you can specify the authorization Type to be "Api Key" and put X-ApiKey as key and your apikey value on the value field(image). It'll generate the same request as shown in the headers image.
curl, at least the GNU one on Linux, uses GET method by default. If you want to change a HTTP method in your request, there's -X option, for example:
$ curl -X DELETE https://example.com
Postman has something called Postman Console which you can open by pressing Alt + Ctrl + C:
and where you can see more details about requests and responses.
Postman also lets you import curl commands, so you don't need to manually prepare the request, you can only paste the curl command in Postman.
There are many resources online on the specifics, e.g. how to import a curl command.

Post media entity documents to Drupal 8 via REST API

We are looking for a way to quickly post documents (pdfs) to a drupal 8.5.1 site via REST API module as media entity objects - the metadata associated with the post would need to include not just the name and description of the document but also the taxonomy term that the document belongs to.
For example, given a file in the current directory named "sample.pdf" (with a title "Sample Document"), the curl POST might look something like this (and sadly I am omitting anything to indicate the taxonomy term associated with the document):
curl --include \
--request POST \
--user <use>:<pass> \
--header 'Content-type: application/hal+json' \
--data-binary '#sample.pdf' \
http://<domain>/entity/node?_format=hal_json
Does anyone have any experience / example code to point us in the right direction?
Apache Tika is a great tool for extracting data from different file types.
You may want to extract metadata before posting the file, in this case you can make a script that takes your pdf and either posts :
JSON data to use with REST API
form-data to use with FORM API (use the curl option --form and change the url to match the appropriate entity form submit handler).
Or you can post the file content as a whole, then hook into Drupal entity save process to extract text and metadata from the content stream and alter the entity accordingly.
Since 8.6.x, You can use Rest API with the ressource FileUpload to upload your file, have a look here https://www.drupal.org/node/2941420
Once uploaded, you will get a file id to use with the endpoint entity/media (post) in your field.

Get multiple songs by foreing_ids

I'm building an spotify-echonest app using the web apis from both. I'm using spotify api to get as many songs as I can from user input, what I need now is to get information about these songs from echonest but as far as I can see you can only set one filter as foreing_id in the rest service.
http://developer.echonest.com/api/v4/artist/similar?api_key=YOUR_API_KEY&id=spotify:artist:4Z8W4fKeB5YxbusRsdQVPb&bucket=id:spotify
I'm using the Java API from Echonest, anyway any help is usefull.
You should query audio features from Spotify's Web API instead as Spotify doesn't support echonest anymore. I think you've already known how to get track IDs from the API, all you need to do is use the track IDs to query audio features.
Example:
Step 1: Get track id
curl -X GET "https://api.spotify.com/v1/search?q=track%3Anumb+artist%3Alinkin+park&type=track" -H "Accept: application/json"
Step 2: Get access token
curl H "Authorization: Basic YOUR_CLIENT_CREDENTIALS" -d grant_type=client_credentials https://accounts.spotify.com/api/token
Step 3: Get audio features
curl -X GET "https://api.spotify.com/v1/audio-features/YOUR_TRACK_ID" -H "Authorization: Bearer {YOUR_ACcess-TOKEN}"

Can I change a date on shopify blog using api?

I must be brief, not much time left...
I'm trying to backdate some blog posts that were written in the run-up to our store launch.
I'm using curl from the command line and I can POST new blog articles, and I can PUT changes to existing blog articles, but I can't adjust the date of the existing articles yet.
Can you help me?
Thanks!
Here's my curl request...
curl -i -H "Content-Type: application/json" -H "Accept: application/json" -X PUT -d '{ "article": {"id": xxxxxx, "created_at": "2012-08-25"}}' https://key:passwordlongstringhere#storename.myshopify.com/admin/blogs/#blogID/articles/#articleID.json
And yes, all the appropriate xxxx and #blogID have the right info in my request.
Created at dates can not be set through the API or admin.
The created_at field is read-only, as mentioned by John. However, you can change the published_at date to backdate the post as you desire.
The connection will fail with "curl: (35) Unknown SSL protocol error in connection to shopname.myshopify.com:443" unless you add --sslv3 to the curl parameters. I have successfully used your example with this parameter to change the published date on a blog post via the api.