How do I delete a ShareFile folder using the v3 ShareFile API? - sharefile

I am trying to delete a folder in ShareFile using the v3 ShareFile Rest API. I'm migrating from the older v1 API, and the migration documentation cites /sf/v3/Items/BulkDeletePermanently as the replacement, but I cannot get it to work.
Here is my bulk delete call and result:
POST https://[ShareFileHost].sharefile.com/sf/v3/Items/BulkDeletePermanently?ids=[folder id]
Returns:
<code>BadRequest</code>
<message>
<lang>en-US</lang>
<value>Missing Item Id</value>
</message>
<reason>BadRequest</reason>
I've tried this call with ids as a parameter and also with it as the Post QueryString and as PostData.
I also tried the DELETE with /sf/v3/Items. Here is my call and the result:
DELETE https://[ShareFileHost].sharefile.com/sf/v3/Items([folder id])
Returns:
<code>Forbidden</code>
<message>
<lang>en-US</lang>
<value>Authorization failed: Item.You are not authorized to perform this operation.</value>
</message>
<reason>NotAuthorized</reason>
I verified with this call that my user has delete capability for the folder I'm trying to delete.
Any suggestions would be appreciated.

I found the answer to this. When looking at permissions, I was looking at my subfolder. The permissions needed to be on the parent folder. I created a parent folder and gave my user delete permissions. I then added a subfolder to it, and I was able to delete it using the DELETE with /sf/v3/Items.

Example Permanently delete multiple items:
curl -X POST https://[ShareFileHost].sharefile.com/sf/v3/Items/BulkDeletePermanently
-H "Content-Type: application/json"
-d "[\"id1\", \"id2\"]"
Example Delete Multiple Items (deletePermanently=true):
curl -X POST https://[ShareFileHost].sharefile.com/sf/v3/Items(parentid)/BulkDelete?forcesync=false&deletePermanently=true
-H "Content-Type: application/json"
-d "[\"id1\", \"id2\"]"
Where parentid is the ID of the parent folder; id1, id2 the ID of the
items or folders
Response 204 No Content.
API Ref

Related

category_list param for test page creation request

Having created a test user for my app, I intend to create a test page by sending the following POST request to the Facebook API (some parts obviously replaced with dummies):
https://graph.facebook.com/v7.0/<TEST_USER_ID>/accounts?access_token=<APP_TOKEN>&name=Dummypage&category_enum=BANK&about="Text"&picture=<URL_TO_IMAGE>&cover_photo={"url": "<URL_TO_OTHER_IMAGE>"}&location={"city": "SomeCity","state": "SomeState","country": "DE"}&address="<ADDRESS>"&phone="<PHONE>"&category_list=[{"id": "133576170041936"} ,{"id": "145988682478380"}]
The problematic part of this is the category_list parameter, which I have attempted to pass in many forms already. Arriving at
category_list=[{"id": "133576170041936"} ,{"id": "145988682478380"}]
I finally no longer get the error that the param has to be an array - instead I get the following error: (#100) Param category_list[0] must be a valid ID string (e.g., \"123\") .
This is fairly confusing, as the IDs are taken from the response of an API response containing the page categories:
https://graph.facebook.com/v7.0/fb_page_categories?access_token=<TOKEN>
How should the parameter be correctly passed?
What I tried so far:
category_list=["145988682478380"]
category_list=[145988682478380]
Result: (#100) Invalid parameter
category_list=[{"id": "145988682478380"}]
category_list=[{"id": "145988682478380", "name": "Kreditgenossenschaft", "api_enum": "CREDIT_UNION"}] #full entry as listed in page categories response
Result: (#100) Param category_list[0] must be a valid ID string (e.g., "123")
Documentation references
Page category
Creating a test page via POST request
This curl command worked by me:
curl -i -X POST -H "Content-Type: application/json" -d "{ \"category_list\": [192803624072087, 145988682478380]}" "https://graph.facebook.com/v8.0/me?access_token=[page_access_token]"
So with the following JSON Body:
{
"category_list": [192803624072087, 145988682478380]
}

Page creation with IFrame macro using Confluence API

I am using the following simple curl call to create a new Confluence page with an embedded IFrame macro that references an external site:
curl -u <username>:<password> -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"A Test Page", "space":{"key":"SPACE"}, "ancestors" : [ { "id": "115328548" } ],"body":{"storage":{"value":"<h1>IFrame Macro Test</h1><p>Foo Bar Blah</p><p><ac:structured-macro ac:schema-version=\"1\" ac:name=\"iframe\"><ac:parameter ac:name=\"URL\">https://www.example.com</ac:parameter><ac:parameter ac:name=\"Width\">100%</ac:parameter><ac:default-parameter>https://www.example.com</ac:default-parameter></ac:structured-macro></p>","representation":"storage"}}}' https://localhost:8080/confluence/rest/api/content | python -mjson.tool;
Whilst the page is being created with the embedded macro none of the macro parameters have been set, per the definitions in the request payload. "URL" is a mandatory parameter for the macro, however I am unclear if the element should be used, or alternatively the element (and hence set both - to no avail).
Thanks and regards,
Andrew
The Confluence XHTML content payload needs to be as follows:
<ac:structured-macro ac:name="iframe" ac:schema-version="1" ac:macro-id="f3b89c73-0096-409c-84fa-0158bf4e0f4f" xmlns:ac="http://www.atlassian.com/schema/confluence/4/ac/" xmlns:acxhtml="http://www.atlassian.com/schema/confluence/4/" xmlns:ri="http://www.atlassian.com/schema/confluence/4/ri/">
<ac:parameter ac:name="src">
<ri:url ri:value="https://example.com"/>
</ac:parameter>
<ac:parameter ac:name="width">100%</ac:parameter>
<ac:parameter ac:name="height">750</ac:parameter>
<ac:rich-text-body>
<p>
<br/>
</p>
</ac:rich-text-body>
</ac:structured-macro>
The easiest way to determine the correct payload is to manually create the page with macro and use the REST API to retrieve the XHTML content fragment
curl -u <user>:<password> -H 'Accept: application/json' --url 'https://<host:<port>/confluence/rest/api/content/<page-id>?expand=body.storage,version' | python -mjson.tool

Unable to query through elasticsearch

I am using Elasticsearch in my Django application. When i try to query my result using curl i get found = false. Can someone help me here !]1
I am following this tutorial and my code when i execute https://www.freecodecamp.org/news/elasticsearch-with-django-the-easy-way-909375bc16cb/ and my code fails when i execute
curl -XGET 'localhost:9200/blogpost-index/blog_post_index/1?pretty'
The above method is for fetching the document by its id. As per the JSON response of the ES server, document with id 4 doesn't exist. You can possibly try to fetch all documents by using match_all query on the index to fetch all the documents and see if the document you are trying to see exists.
Here's the CURL syntax:
curl -X GET "localhost:9200/_search" -H 'Content-Type: application/json' -d'
{
"query": {
"match_all": {}
}
}
'
Reference : Match All Query
You can also see the range of documents IDs to see if the document you are trying to fetch, exists.
Range Filter for IDs

Graphene Django "Must provide query string"

I have setup a Graphene server using Django. When I run my queries through GraphiQL (the web client), everything works fine. However, when I run from anywhere else, I get the error: "Must provide query string."
I did some troubleshooting. GraphiQL sends POST data to the GraphQL server with Content-Type: application/json. Here is the body of the request that I copied from Chrome network tab for GraphiQL:
{"query":"query PartnersQuery {\n partners{\n name\n url\n logo\n }\n}","variables":"null","operationName":"PartnersQuery"}
When I copy it to Postman with Content-Type: application/json, I get the following response:
{
"errors": [
{
"message": "Must provide query string."
}
]
}
What can be the cause of this problem? I have not done anything crazy with the schema. Just followed the tutorials from graphene's docs. What else can cause an issue like this?
This error is raised when parse_body is unable to parse the incoming data. I'd start there by looking at the data passed into this method and ensuring it's of the correct type.
For example, the multipart/form-data section naively returns request.POST, which may need to be overwritten to handle, for example, the request that apollo-upload-client sends for file upload handling.
In our case we created a view to both require a login and to support the apollo-upload-client use case and it works fine.
Here's how I was able to get a successful response from Postman using a graphene Django backend with a simple mutation:
Set method to POST
Add the URL to your graphQL endpoint, e.g. http://localhost:8000/api/
Add one header -- key: "Content-Type" , value: "application/json"
Set the body to "raw"
Paste in your query into the body window, e.g. {"query":"{myModels {id}}","variables":"null","operationName":null}
This sounds pretty much like what you did, so you must be close.
I faced the same problem when I try to used graphQl query using POSTMAN,
In POSTMAN send data in row with json type.
You have to make json data grapQl query and mutations data like this
Query Command:
{"query":"{user(id:902){id,username,DOB}}"}
Mutations Command:
{ "query": "mutation {createMutations(reviewer:36, comments:\"hello\",loan: 1659, approved: true ){id}}" }
#commnent: String Type
#data_id:Int Type
#approved:Boolean Type
Checkout sample apps and see how they do things,
e.g.
https://github.com/mjtamlyn/graphene-tutorial
they do the following:
from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import GraphQLView
url(r'^explore', GraphQLView.as_view(graphiql=True)),
url(r'^graphql', csrf_exempt(GraphQLView.as_view())),
I encountered exactly the same problem as the original poster, Gasim. Studying the code in 'graphiql.html' I see that they're converting the query string, that goes into the body, into the query parameter in the URL. Thus you end up with this URL being sent via Postman:
http://127.0.0.1:8000/graphql?query=%7B%0A%20%20allCategories%20%7B%0A%20%20%20%20edges%20%7B%0A%20%20%20%20%20%20node%20%7B%0A%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20ingredients%20%7B%0A%20%20%20%20%20%20%20%20%20%20edges%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20node%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20name%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A
It seems nonsensical to me to duplicate precisely what's in the body in the query string in the URL too but that appears to be the only way to get the Graphene server to return a valid response.
Surely this is a bug/shortcoming that will be fixed?
Robert
Enable graphine on django
url(r'^graphql', csrf_exempt(GraphQLView.as_view(graphiql=settings.DEBUG))),
Execute some query and see it is working
On Chrome browser, go to graphiQL endpoint: http://localhost:8000/graphql? open "Developer Tools" in browser and go to "Network" tab.
Execute your query again. Now it appears on list of requests. Now right mouse click on it and copy it "copy as CURL". Now you can strait copy paste it to linux terminal with curl installed. Or like in your case you can try to deduct what is what there, and try to reuse it in your IDE like client like Insomnia or Postman. For instance you may discover that authorisation that works with session on graphiQL enpoint, is not what you want at the end...
curl 'http://localhost:8000/graphql?' -H 'Origin: http://localhost:8000' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9,pl;q=0.8,de;q=0.7' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Cookie: _ga=GA1.1.1578283610.1528109563; _gid=GA1.1.920024733.1541592686; csrftoken=EGBeegFoyMVl8j1fQbuEBG587nOFP2INwv7Q0Ee6HeHHmsLOPUwRonzun9Y6pOjV; sessionid=4u9vngcnmjh927a9avpssvc4oq9qyqoe' -H 'Connection: keep-alive' -H 'X-CSRFToken: EGBeegFoyMVl8j1fQbuEBG587nOFP2INwv7Q0Ee6HeHHmsLOPUwRonzun9Y6pOjV' --data-binary '{"query":"{\n allStatistics(projectId: 413581, first:25) {\n pageInfo {\n startCursor\n endCursor\n hasPreviousPage\n hasNextPage\n }\n edges {\n cursor\n node {\n id\n clickouts\n commissionCanc\n commissionConf\n commissionLeads\n commissionOpen\n eventDate\n extractTstamp\n hash\n leads\n pageviews\n projectId\n transactionsCanc\n transactionsConf\n transactionsOpen\n }\n }\n }\n}\n","variables":null,"operationName":null}' --compressed
The problem in my code was that I had the URL improperly setup for graphQL. I had the following:
url(r'^graphql/', GraphQLView.as_view())
The forward slash was a huge difference. Removing it fixed the problem. The proper way to do it would be:
url(r'^graphql', GraphQLView.as_view())

Django POST sub-dictionaries

I'm making the following request through command-line cURL:
curl -X POST http://localhost:8000/api/places/ -vvvv -d "place[name]=Starbucks"
However, when I try to access the parameters by calling
request.POST.getlist('place')
I get an empty array as a response. How can I access the sub-dictionary which I can then pass to the ORM?
Thanks,
Jamie
HTTP data elements can't have sub-elements. The data you have posted - as shown in the querydict - has been interpreted as a single element with key "place[name]" and value "Starbucks". So you can get it with request.POST["place[name]"].
It looks like you are sending a string, in that case try:
request.POST.get('place[name]')
If your are simulating a dropdown list you should send "place=Starbucks", however if you are trying to send an array you should try to convert you string to an array inside your python script.
In your command you can get ride of "-X POST" as the parameter -d is already an HTTP POST:
curl --help
...
-d/--data <data> HTTP POST data (H)
curl manual:
http://curl.haxx.se/docs/manual.html