How to move an item from one parent to another? - api

I have a parent type call TaskList. A TaskList has many Tasks.
The simple case question that I have is how to move a Task from one TaskList to another.
I run a search query to find the set of Tasks that I want to move. The Tasks then are in the _embedded attribute of the JSON that comes back from that search. I want to then move those elements to a different TaskList. How would I do this?
Would I submit a POST to /tasklists/x with the _embedded Tasks as the body of that request?
Would I submit a PATCH to /tasks/y with a tasklist_id attribute already set?
What's the proper way to do this?
Thanks!

Moving a task implies that it already exists and has a URI. You POST that URI to the URI of the target task list.
The appropriate content type is text/uri.

As you suggested, you could submit a patch request according to : https://www.rfc-editor.org/rfc/rfc6902#section-4.4
Your json would look like something like this :
[
{
"op": "move",
"from": "/tasklists/id/tasks/id",
"path": "/tasklists/anotherId/tasks/id"
},
{
"op": "move",
"from": "/tasklists/id/tasks/id2",
"path": "/tasklists/anotherId/tasks/id2"
}
]
Hope it helps !

I'm using spring-data-rest on the server. What I ended up doing was sending a patch request to the item URL that looks like this:
{TaskList:"http:/host:port/tasklists/id"}
Here's a reference to a post which game me some insight.
https://stackoverflow.com/a/26426909/1174250
Thanks everyone for your comments :)

Related

Shopware 6 Store-API set newsletter recipient tags

I'm trying to add a newsletter recipient through store-api, which works. But when I try to add a tag inside the request, it fails. The documentation states that it is possible to add a tag as a string to the request, see here
My request looks like the following:
POST /store-api/newsletter/subscribe
{"option":"subscribe","email":"email#email.com","storefrontUrl":"http://myhost.test","tags":"men"}
I also tried to make the tags value an array, but this doesn't work either...
So my question is: how do I add a tag to the newsletter recipient through the store api?
As of Version 6.4.3.0 this seems not possible.
I tried the same request as you, as well as
"tags":["men"]
and
"tags":["uuidOfExistingTagGoesHere"]
all does not work.
Also the doc block for tags is wrong (it says "zip code" instead of a useful description).
In addition I tried to assign existing tags - this is what works via the admin API:
"tags": [
{
"id": "80df380188364f3c9bbaaa4d6b993dbd"
},
{
"id": "108428f0a37c4d11a66976adc5337c23"
}
]
Which still returns
"code": "FRAMEWORK__WRITE_MALFORMED_INPUT",
"title": "Bad Request",
"detail": "Expected data to be array.",
Also looking at the code there currently seems no handling of the tags. As far as I understand it, the tags would needed to be created on the fly
A possible fix would be the following code:
if (isset($data['tags']) { // inserted that lines
$data['tags'] = $data['tags']->all();
} // end inserted lines
$data = $this->completeData($data, $context);
Using that line, the last mentioned request works (you could then use the IDs of existing newsletter recipient tags).
Of course in this case the API docs have to be adapted.
TL;DR
In my opinion, this seems a flaw in the current Store API implementation.
I would suggest to create an issue on the Shopware 6 issue tracker.

Acumatica - Filter Generic Inquiry via REST

Trying to use this Generic Inquiry's REST API, I am able to retrieve all records though would like to filter them.
Can retrieve all data with PUT {{baseUrl}}/RawDataForReport?$expand=Result with an empty body request.
When I added a field Period to filter it's only showing the first row.
An empty request body also shows the first row when I added Period.
I am not at all familiar Acumatica any useful resources would be greatly appreciated.
To filter the Generic Inquiry result with REST API you need to add the filtering parameter to the GI itself. For instancce, you have your period filter defined in the Generic Inquiry. You can define more filters the same way.
You can learn about designing GIs here: https://openuni.acumatica.com/courses/reporting/s130-inquiries-reports-and-dashboards/
Another option would be to use OData instead of REST API. in that case you would be able to use $filter parameter to filter data.
You can read more about it here:
https://help-2020r2.acumatica.com/Help?ScreenId=ShowWiki&pageid=36beb9aa-f04d-4f63-a93b-a00b1c315be0
https://help-2020r2.acumatica.com/Help?ScreenId=ShowWiki&pageid=5d97a93d-45e0-466e-ba5e-77e1ccf96643
I've been struggling to find a solution to the same problem.
I just figured it out with the help of this stack overflow post.
Acumatica run Generic Inquiry via REST API
Take a look at the last response (not the accepted answer).
Basically when you define your object in the Web Service Endpoint screen, you can define the filters (Use Populate -> Filters). these are the Parameters for the GI.
You define the results the same as you have it.
Then in your PUT request body pass the parameters.
Example:
{
"Param1": {
"Value": "Value1"
},
"Param2": {
"Value": "Value2"
}
I just tested this with Postman, and it works well.

ImportXML google sheet for shipment package tracking

I want to track each FEDEX, DHL and UPS shipment status directly from google sheets. I am using importxml function:
=IMPORTXML("https://www.fedex.com/apps/fedextrack/?action=track&tracknumbers="&C2&"&locale=en_US&cntry_code=us","//h1/div[#class="redesignSnapshotTVC snapshotController_addr_label dest"]/title")
However it shows error.
Attaching my sheet link for this: https://docs.google.com/spreadsheets/d/1E1L0rn9-H4MCutI1On2uHDkkPo1pdjRpv014YREGIdU/edit?usp=sharing
Please tell what is best way to do it. I am from non tech background.
Thanks so much for help!
Common issue. You're trying to import html that is generated after loading. That means we have to look for how the data you want is generated.
Data source
Upon inspection of the site, I found that it was making an XHR to the URL https://www.fedex.com/trackingCal/track, and that it was doing so via POST with a long payload. The response was in JSON format. Of note, there is the scanEventList entry.
"scanEventList": [{
"date": "2020-07-15",
"time": "13:15:00",
"gmtOffset": "-07:00",
"status": "Delivery exception",
"statusCD": "DE",
"scanLocation": "SAN BERNARDINO, CA",
"scanDetails": "Future delivery requested",
"scanDetailsHtml": "",
"rtrnShprTrkNbr": "",
"statusExceptionCode": "17",
"isClearanceDelay": false,
"isDelivered": false,
"isDelException": true,
"isException": true
},
...
]
Solution
First, get the ImportJSON script from GitHub, and add it into your sheet's scripts (Tools > Script Editor). It's not the most amazing thing, but it will at least give us ImportJSONViaPost() to get the data we want:
=INDEX(ImportJSONViaPost("https://www.fedex.com/trackingCal/track","data=%7B%22TrackPackagesRequest%22%3A%7B%22appType%22%3A%22WTRK%22%2C%22appDeviceType%22%3A%22DESKTOP%22%2C%22supportHTML%22%3Atrue%2C%22supportCurrentLocation%22%3Atrue%2C%22uniqueKey%22%3A%22%22%2C%22processingParameters%22%3A%7B%7D%2C%22trackingInfoList%22%3A%5B%7B%22trackNumberInfo%22%3A%7B%22trackingNumber%22%3A%22"&A2&"%22%2C%22trackingQualifier%22%3A%22%22%2C%22trackingCarrier%22%3A%22%22%7D%7D%5D%7D%7D&action=trackpackages&locale=en_US&version=1&format=json",,"/TrackPackagesResponse/packageList/scanEventList,/TrackPackagesResponse/packageList/trackingCarrierDesc","noHeaders"),1)
Arguments:
URL for the tracker
The POST payload. Cell A2 Holds your tracking number.
Leave empty
Query - Lets us select the data that we want. In this example, I chose to select the carrier description and the entire scanEventList entry, but you can specify particular elements of that as well.
"noHeaders" means just the data.
Just using the JSON import gives us an entry for each element of scanEventList, but the first is the most recent, so, we use INDEX to retrieve the first entry, which should contain what you need.
For additional help on the ImportJSON package, see here.

Retrieving image files from referenced items in filtered items

Being new to REST APIs (and APIs in general), I ran into some problems while trying to retrieve some Podio data using the Klipfolio web service, where I want to setup a simple dashboard with a list containing a name field from collected Podio and a image field from a reference field from the collected items.
So far I was led in the direction of 'bundling' and 'nesting', but I am not quite sure if this is the way forward.
In order to retrieve the filtered items, I have used the following POST method:
POST /item/app/11821547/filter/
Body:
{
"from": -1mr,
"to": -0mr
}
And then, from the items I here retrieve, I want to GET the referenced items, for instance using:
GET /reference/{ref_type}/{ref_id}
And finally, I want to get the image URL from the respective field in these referenced items, for instance using:
GET /item/{item_id}/value/{field_id}
Any help is much appreciated!!
To accomplish this you only need to use one API call to the Podio filter items endpoint in which you wrote above; POST /item/app/11821547/filter/.
In your POST body, you can filter down your results with the created to and from dates. For example, if you only want the items for the past month, you can use Klipfolio's date parameters. Your POST body will look like this:
{
"filters": {
"created_on": {
"from": "{date.addMonths(-1).format()}",
"to": "{date.today}"
}
}
}
This will return an API reponse of all items that were created within the past month. From here you can build a klip and manipulate the JSON with xpath expressions to extract the image urls and names. All this information will be within the #item/fields array in your API response. You'll have to determine which field ID is used for the name and image url field. These are unique to each account.
An example of xpath to extract these values would be like so:
#/items/fields[field_id='id_number']/values/value
Where id_number is the exact id number for the field.
If you are unfamiliar with xpath expressions within Klipfolio, here is a document that walks through this.

Which fields are required to create an event through Social Tables API

I have the following questions that I was not clear on from the API documentation:
Which fields are required to create an event?
What does "Invalid field: 0" mean? (this was an error message received when trying to create an event)
The sample body includes "spaces" as string -- is this the space name or ID?
Is this required? If yes, to create a space I need an event ID but to create an event do I need a space?
Hey thanks for using our API. It looks like the developer docs on our portal got kind of mangled. We'll be working on fixing that soon.
In the meantime, let me try to help.
So, the actual required fields for that endpoint are very minimal, here is a small sample post I made for a room here at Social Tables:
{
"name": "Dan's Office Party",
"category": "Other",
"spaces": [
{
"name": "st test"
}
]
}
The key thing here is that spaces is an array, with at least a name property attached.
The error message you referred to is a failing validation check on the type of one of the fields you submitted.
You do need a space to create an event, but as you can see, only the name is absolutely required. However, if you want to do any diagramming with that event, you'll probably want to attach a venue_id with one of our floorplan IDs in addition to the name property.
I have created an issue to update the mangled doc located at https://developer.socialtables.com/api-console#!/Events/post_4_0_legacyvm3_teams_team_events and will comment here when it is updated.