Am am currently using Postman to test the api results. I have been following the apostrophe headless docs, since am completely new to this. so what i need is to submit a post request in Postman to add a piece and its fields from REST api. I have got the bearer token and login was success. but when i insert a piece with body as JSON schema. am getting a error message.
May be the way am doing is wrong. so can one one help me in Making a post request to add piece and fields through POSTMAN atleast?
I did not understand the question quite right. You should add some of your inputs, error message, url, pics and etc. to clarify the problem.
However, if you need an example to how to use postman to make a POST request, it's like this:
Select the POST method and insert the API URL (The landing url for POST method not the view and etc.)
Go to headers Tab and add the Authorization token to header
Select the Body tab; Then raw type and finally JSON type. Now insert the Json body and click Send.
You can see the result of webservice call on the top of response window. If it returned 200, everything was OK.
Related
As you can check below screenshot I tried to make PUT api call in the Contentful to update the entry.
When I try to hit GET call, everything works fine but don't understand here what is reason of this below error while making PUT call.
Did I missed anything here or anything wrong here?
NOTE: I changed all the variable while making call, spaceId, env, entryId and authorisation(passing access_token)
From what I see in your URL, it looks like you are trying to hit the Contentful Preview API, which is read-only.
API Base URL https://preview.contentful.com
This is a read-only API
source
Therefore, updating an entry via a PUT request cannot be done with the url you are using.
However, I believe your PUT request should work if you update the base url to be https://api.contentful.com/ instead. This is the endpoint for the Content Management API.
Important note:
if you do this, you will need to use a different auth token for the Content Management API.
Using https://api.contentful.com/ hits the writable Content Management API, which has documentation for the PUT request you are making.
Importing the corresponding curl command into your Postman client will confirm this.
So in the end, the url would be this:
https://api.contentful.com/spaces/{space_id}/environments/{environment_id}/entries/{entry_id}
Again, the bearer token will have to come from the writable Content Management API.
Am am currently using Postman to test the api results. I have been following the apostrophe headless docs, since am completely new to this. so what i need is to submit a post request in Postman to add a piece and its fields from REST api. I have got the bearer token and login was success. but when i insert a piece with body as JSON schema. am getting a error message.
May be the way am doing is wrong. so can one one help me in Making a post request to add piece and fields through POSTMAN atleast?
I did not understand the question quite right. You should add some of your inputs, error message, url, pics and etc. to clarify the problem.
However, if you need an example to how to use postman to make a POST request, it's like this:
Select the POST method and insert the API URL (The landing url for POST method not the view and etc.)
Go to headers Tab and add the Authorization token to header
Select the Body tab; Then raw type and finally JSON type. Now insert the Json body and click Send.
You can see the result of webservice call on the top of response window. If it returned 200, everything was OK.
I have a form on a template on my domain1 and want to send a POST request to domain2. I am using Django as the framework. I only want domain2 to accept requests from domain1 and domain2 (itself). However, I run into csrf problems.
You need a RESTful API. That's a very large topic and would be dumb/impossible to do the work for you here with the info I've been given, so here's a summary.
I suggest Django Rest Framework for making api's.
What the above means, is that when you want to do this sort of stuff (POST requests from other domains), you need a token. This is usually done with a Json Web Token. Also known as JWT's.
The process goes like this:
Get access token from other site to have permission to use the API from that site. Certain http headers, passwords, etc, are often included with this every single time data is exchanged.
Once you get a response giving you permission, you can now perform the type of request you want, with the data you want.
The data format for all this is USUALLY done with JSON. So you will have to import json, then json.dumps(obj) to turn it into valid json, and json.loads(obj) to turn your response into a python dictionary, so you can use it in your template, or wherever you want.
If you want to see an example of this, I recently made a free GoFundMe clone on my guthub. In the donate() view at the bottom, it uses the requests library, and shows how a JWT is obtained and used. You can see it there.
Since some weeks now, I'm improving my knowledge in POSTMAN. Able to send GET, POST request, validating JSON schema, running test... and so on.
But, I'm loosing my hair trying to send DELETE request.
When you build a GET request, OAUTH1 parameters automatically sent to url parameters, but it is not the case when you select DELETE.
The problem is my API send me back "some parameter is missing" and the difference is based on these parameter in the URL.
I try to turn it to GET, and when parameters in url, get it back to DELETE, but there is issue timestamp, nonce and signature.
Rally appreciate help
Regards
I am trying to build a Django powered website. I want the website to be dynamic. For example, I want the profile page for a authenticated user to contain multiple resources (like a friends list, a group list, usage history etc) and these resources should be loaded in the same area on the page by making API calls without reloading the page.
Here is my understanding of the process:
Browser on the client side requests the profile page at www.example.com/user:id
The server returns a HTTP response and sends the html, css and javascript to the browser.
To load variable resources on the webpage, for example, the friend list, the javascript makes API calls using HTTP and sending context in JSON.
The API returns a JSON response which contain the data requested.
Javascript renders the data as html and the client is able to see new content on the same page.
I thought that in order to do this, some of my server side views need to be ordinary Django views which returns an HTTP response, while some others need to be API views which return JSON.
Now here's my confusion. Let's say www.example.com/user:id is processed using an ordinary django view, while www.example.com/user/:id/friendslist is processed using an API view. Now if the user inadvertently points the browser at www.example.com/user/:id/friendslist by typing the entire URL and hits go, what happens?
If I go with the flow of logic that I mentioned above, then the view will simply return a JSON. No html, css or javascript. In this case, how will the browser know what html to display?
I am just a beginner and I am sure I got the flow of logic wrong. Can someone please point out which part I got wrong?
Now if the user inadvertently points the browser at www.example.com/user/:id/friendslist by typing the entire URL and hits go, what happens?
It depends on how you coded your server. In Django you can use is_ajax to check whether the request was AJAX or not. You could return an HTTP error code when the request is not an AJAX one, if you wanted. So a user who inadvertently points the browser to your URL but does not take any further action will get an error.
Note here that a knowledgeable user could circumvent is_ajax by setting the request header field HTTP_X_REQUESTED_WITH to XMLHttpRequest manually.
If I go with the flow of logic that I mentioned above, then the view will simply return a JSON. No html, css or javascript. In this case, how will the browser know what html to display?
Setting your returned data type to application/json already tells the browser what it is dealing with. The least a browser would do this with this is display it as text.
Here's an example of an API call that returns JSON: https://api.zotero.org/users/475425/collections/9KH9TNSJ/items?format=json My browser just shows the JSON.