Can not update data with POST request in Postman - json

I have an API token from digikala.com and I want to make a POST request for Updating variant.
So as the documentation says, I have to send this kind of data as Body raw:
{
"site": "digikala",
"shipping_type": "both",
"seller_stock": 10,
"max_per_order": 10,
"digikala_lead_time": 2,
"ship_by_seller_lead_time": 48,
"is_archived": false,
"is_active": true,
"price": 12000,
"gold_wage": null,
"non_gold_parts_cost": null,
"non_gold_parts_wage": null,
"gold_profit": null
}
But I get 404 Not Found error:
So what's going wrong here? How can I properly get the data in this situation?
Not that I have properly defined the API_KEY because I tested it with another GET request and it was working fine.

so this is strange but changing the post to a put method allowed the request and also adding an extra forward slash after the request worked. I just think the api is not very well documented

Related

How to pass access tokens from REST client in Apache Drill?

I've setup Apache Drill, created http storage plugin and set its configuration as here:
{
"type": "http",
"cacheResults": false,
"connections": {
"accounts": {
"url": "https://my.datasource.url",
"method": "GET",
"headers": {
"Authorization": "Bearer access_token...",
"Accept": "application/json"
},
"authType": "none",
"userName": null,
"password": null,
"postBody": null,
"params": null,
"dataPath": "QueryResponse/Account",
"requireTail": false,
"inputType": "json"
}
},
"timeout": 0,
"proxyHost": null,
"proxyPort": 0,
"proxyType": "direct",
"proxyUsername": null,
"proxyPassword": null,
"enabled": true
}
I am able to run queries through rest call (as well as from web ui and odbc) as here:
{
"queryType": "SQL",
"query": "select * from myds.accounts"
}
The problem is, access token is short lived and multiple users need to access these data sources with their own access tokens, so saving token withing connection doesn't work for me.
Is there any way I could send access token from the client at the time of sending query? I have no preference of using either Rest API or ODBC, any of them would be good as far as it solves my problem. Thanks
It may be possible to specify some of the configuration at query time. The example below demonstrates, in the file system plugin, how to use the table() function to alter the configuration options at runtime. In this case, we're specifying which sheet to query in an excel file.
SELECT *
FROM table(dfs.`excel/test_data.xlsx` (type => 'excel', sheetName =>'secondSheet'))
I don't know if this will work for the REST plugin or not, but it's worth a try. (It is admittedly a bit of a hack)
Another option, which would require modification to the plugin, would be to create special variables that could be specified at query time. For instance, we could create a _headers variable so that you could insert items into the headers at query time. Thus, a query might look like:
SELECT...
FROM ...
WHERE _headers="Authorization=1234"
I'm really wondering what the best way to accomplish this is. I'm sure you're not the only one with this issue.

Create Bucket in Couchbase using Http Post Request

I want to create a bucket in couchbase on runtime using a simple http post request. I have used the following link to do the task link
Raw request I generated on postman is as follows:-
http://:8091/pools/default/buckets?name=newbucket&bucketType=membase&ramQuotaMB=20&authType=none&replicaNumber=2&proxyPort=11215
But its giving me error:-
{
"errors": {
"authType": "invalid authType"
},
"summaries": {
"ramSummary": {
"total": 20191379456,
"otherBuckets": 16710107136,
"nodesCount": 2,
"perNodeMegs": 0,
"thisAlloc": 0,
"thisUsed": 0,
"free": 3481272320
},
"hddSummary": {
"total": 158247145472,
"otherData": 11366997180,
"otherBuckets": 68794932977,
"thisUsed": 0,
"free": 78085215315
}
}
}
I have used the basic auth as the username and password of the couchbase console.
Any idea whats wrong with the call.
I think the problem is that you're passing the parameters in the URL and not as part of the POST body. Since you're using Postman, check the "x-www-form-urlencoded" option and enter the various values there.
Here's a screenshot of an example, which returns a 202 (Accepted) response:

FineUploader Failing to parse incoming JSON

I'm using play/scala for a webapp and a scala API, currently running simply on two different ports on localhost:9000 and localhost:8080 respectively. I have the basic page from the fine-uploader.com website docs, and a simple test page build in Play. (FWIW, i don't think much of the above is relevant)
When i post a file, chunked or not, Fine uploader receives a 200 from the API and valid JSON, but JSON.parse returns a failure. The logging from fine-uploader is below. If i take this output and run it through (in the console)
JSON.parse(JSON.stringify(json))
a valid object is returned. I can't just JSON.parse(json) directly in the browser tools b/c its already an object. I have checked the types by console.log'ing typeOf json in the qq.parseJson method and it returns string, so no conversion should be required, though i have tried it with the same results.
fine-uploader console logs:
[Fine Uploader 5.5.1] Sending simple upload request for 0 fine-uploader.js:251
[Fine Uploader 5.5.1] xhr - server response received for 0 fine-uploader.js:251
[Fine Uploader 5.5.1] responseText = {"code":"UPLOAD_COMPLETE","response":{"MediaModel":{"id":1103,"publicUri":"http://localhost:8080/media/Archive.zip","fileLocation":"/src/services/api/src/main/webapp/media/Archive.zip","mediaDate":{"year":2016,"month":2,"day":28},"mediaOrder":1,"viewName":"","caption":"","altText":"","isPublic":1,"fileSize":1107080,"created":"2016-02-28T14:58:43Z"},"UserMediaModel":{"id":1,"userId":24,"mediaId":3,"created":"2016-02-17T12:48:18Z"}},"errors":[]} fine-uploader.js:251
[Fine Uploader 5.5.1] Received response status 200 with body: {"code":"UPLOAD_COMPLETE","response":{"MediaModel":{"id":1103,"publicUri":"http://localhost:8080/media/Archive.zip","fileLocation":"/src/services/api/src/main/webapp/media/Archive.zip","mediaDate":{"year":2016,"month":2,"day":28},"mediaOrder":1,"viewName":"","caption":"","altText":"","isPublic":1,"fileSize":1107080,"created":"2016-02-28T14:58:43Z"},"UserMediaModel":{"id":1,"userId":24,"mediaId":3,"created":"2016-02-17T12:48:18Z"}},"errors":[]} fine-uploader.js:251
[Fine Uploader 5.5.1] Simple upload request failed for 0
The server is responding with a 200 per the API logs and i can see the exact response object in the Response tab of Chrome Dev tools.
I added a custom error handler, but not more more information was provided, just that the error is the text output
Error on file number 0 - Archive.zip. Reason: {"code":"UPLOAD_COMPLETE",....same as above
Lastly, all rows are propery inserted into the database as you see from the id's created above. And all logging points to an equally successful action.
Thanks for any pointers. I've also put this output in http://jsonlint.com/ and it parses fine.
Thanks! (sorry for the lack of JSON formatting, i can change it, but this seemed long enough already)
EDIT
It seems that i have satisfied the requirements stated in the other question with "success":true and Content-Type=text/plain. The following, per request is the JSON output and the headers
Headers:
Key: Access-Control-Allow-Origin Value: http://localhost:9000
Key: Date Value: Mon, 29 Feb 2016 00:55:19 GMT
Key: Access-Control-Allow-Credentials Value: true
Key: Content-Type Value: text/plain; charset=UTF-8
{
"code": "UPLOAD_COMPLETE",
"response": {
"MediaModel": {
"id": 1169,
"publicUri": "http://localhost:8080/media/Archive.zip",
"fileLocation": "/src/services/api/src/main/webapp/media/Archive.zip",
"mediaDate": {
"year": 2016,
"month": 2,
"day": 28
},
"mediaOrder": 1,
"viewName": "",
"caption": "",
"altText": "",
"isPublic": 1,
"fileSize": 1107080,
"created": "2016-02-29T00:55:19Z"
},
"UserMediaModel": {
"id": 1,
"userId": 24,
"mediaId": 3,
"created": "2016-02-17T12:48:18Z"
}
},
"errors": [],
"success": true
}
I'm sure this will end up being something silly, so i appreciate the input.
Based on the error reported by Fine Uploader, your response is not properly formatted. If you look closely at the response in your browser's network tab (such as with Chrome dev tools), you'll likely see a JSON string that, once parsed using JSON.parse results in another JSON string instead of a JavaScript object containing the expected properties. I can't confirm this as you haven't posted the exact response from your server, but I'm certain that this is the case. This is most likely caused by an encoding issue server-side. For example, your server should return this: {"foo": "bar", "success": true} instead of this: "{\"foo\": \"bar\", \"success\": true}". I suspect your server is returning the latter.

JSON.stringify URLEncoding my JSON cookie causing "Invalid JSON primitive"

I have a site cookie where the value is a JSON object. I serialize this to a specific type in my server code and back to JSON when passing back as a cookie. Everything works fine but now i need to write to the cookie in javascript.
The problem i am having is JSON.stringify is URLEncoding the RAW value which is causing an "Invalid JSON primitive" when calling JavascriptSerializer.Deserialize on the server side. It does not know how to handle the URLEncoding.
I'd much rather get this figured out on the client side because all existing users have cookies that are NOT urlencoded.
I need a JS JSON serializer that does not URLencode!
RAW data looks like:
%7B%0A%20%20%22ClientGuid%22%3A%20%222bb1c08a-0813-4739-8f09-9e9576e6f626%22%2C%0A%20%20%22UserId%22%3A%203601%2C%0A%20%20%22OrganizationId%22%3A%20null%2C%0A%20%20%22OrganizationName%22%3A%20null%2C%0A%20%20%22CampaignId%22%3A%2087%2C%0A%20%20%22EmailAddress%22%3A%20null%2C%0A%20%20%22LastCommodityId%22%3A%20157%2C%0A%20%20%22LastRegionId%22%3A%201%2C%0A%20%20%22LastCategoryId%22%3A%205%2C%0A%20%20%22LastSpmId%22%3A%200%2C%0A%20%20%22LastSpmCategoryId%22%3A%200%2C%0A%20%20%22ShowDetailsAllCommodities%22%3A%20false%0A%7D
should look like:
{
"ClientGuid": "2bb1c08a-0813-4739-8f09-9e9576e6f626",
"UserId": 3601,
"OrganizationId": null,
"OrganizationName": null,
"CampaignId": 87,
"EmailAddress": null,
"LastCommodityId": 157,
"LastRegionId": 1,
"LastCategoryId": 5,
"LastSpmId": 0,
"LastSpmCategoryId": 0,
"ShowDetailsAllCommodities": false
}
Use decodeURIComponent on the raw data before sending it to the server:
decodeURIComponent("%7B%0A%20%20%22ClientGuid%22%3A%20%222bb1c08a-0813-4739-8f09-9e9576e6f626%22%2C%0A%20%20%22UserId%22%3A%203601%2C%0A%20%20%22OrganizationId%22%3A%20null%2C%0A%20%20%22OrganizationName%22%3A%20null%2C%0A%20%20%22CampaignId%22%3A%2087%2C%0A%20%20%22EmailAddress%22%3A%20null%2C%0A%20%20%22LastCommodityId%22%3A%20157%2C%0A%20%20%22LastRegionId%22%3A%201%2C%0A%20%20%22LastCategoryId%22%3A%205%2C%0A%20%20%22LastSpmId%22%3A%200%2C%0A%20%20%22LastSpmCategoryId%22%3A%200%2C%0A%20%20%22ShowDetailsAllCommodities%22%3A%20false%0A%7D")

d3.json call always gets null data

If I make this call to the server from a browser:
http://localhost:8080/api/items/number/all.json
Or from curl:
curl -G http://localhost:8080/api/items/number/all.json
I get back the following json:
{
"language": null,
"number": 10,
"queryId": 0,
"from": null,
"to": null,
"percentage": 33,
"dataInfoSet": null
}
However when I use d3.json call:
d3.json("http://localhost:8080/api/items/number/all.json", function(jsondata) {
console.log(jsondata);
});
The output from console.log is null.
If instead the http call, I save the json in a file (fileWithData.json) and do:
d3.json("fileWithData.json", function(jsondata) {
console.log(jsondata);
});
Everything works as expected. Does anyone know what might be the problem?
Solved with the help of d3-js Goole group.
The problem was that the page loading the json was not being served from localhost:8080, thus, there were cross domain restrictions. I just deployed the file within the same application.
In case cross domain calls have to be made, the group suggested the use of jasonp and specially and CORS (
http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/
)