How to test pagination in Postman API? - api

I am having API and testing in Postman. I can able test for one page, but not sure how to test other pages. Basically, wanted to do pagination in Postman.
Here is my response from the Postman API
{
"patient_stats": [
{
"last_appointment_date": "2022-09-14T11:30:00.000+01:00",
"last_exam_date": "2022-09-14T11:15:00.000+01:00",
"last_scale_and_polish_date": "2022-09-14T11:30:00.000+01:00",
"next_appointment_date": "2022-09-28T16:15:00.000+01:00",
"next_exam_date": "2023-09-20T16:15:00.000+01:00",
"next_scale_and_polish_date": "2023-09-20T16:30:00.000+01:00",
"created_at": "2020-07-28T16:25:04.762+01:00",
"updated_at": "2022-09-14T11:52:46.144+01:00",
"total_paid": "157.5",
"total_invoiced": "157.5",
"last_cancelled_appointment_date": "2022-11-23T12:30:00.000+00:00"
},
{
"last_appointment_date": "2006-11-02T12:30:00.000+00:00",
"last_exam_date": null,
"last_scale_and_polish_date": null,
"next_appointment_date": null,
"next_exam_date": null,
"next_scale_and_polish_date": null,
"created_at": "2020-07-31T01:10:10.733+01:00",
"updated_at": "2020-07-31T01:46:42.329+01:00",
"total_paid": "0.0",
"total_invoiced": "0.0",
"last_cancelled_appointment_date": null
}
],
"meta": {
"total": 13616,
"current_page": 1,
"total_pages": 545
}
}
It shows total 545 pages. Not sure how to loop second page in Postman.
I tried to give the current_page = 2 in the params. But it's not showing second page
Can anyone advise how to test in Postman?

Each API is different, the naming changes depending on how it was developed.For example, you can try just "page" instead of "current_page". I usually used it as "page".
?page=2

Related

Shopware 6 Admin Api - Updating existing record through patch method. Not working

shopware 6 admin api patch - why it's failing? I get error "Only single write operations are supported"
Following is api for rule-condition entity in the database, I update it with Id.
For same api get method is working!
url: api/rule-condition/dbb0d904c7c14860a9a94cf26b94eca6
method: patch
json body
[
{
"op": "replace",
"path": "/data/attributes/value/email",
"value": "test#gmail.com"
}
]
response:
{
"errors": [
{
"code": "0",
"status": "400",
"title": "Bad Request",
"detail": "Only single write operations are supported. Please send the entities one by one or use the /sync api endpoint.",
.......
I also tried changing json body to following
{
"data": {
"attributes": {
"value": {
"email": "test#gmail.com"
}
}
} }
Still it's not updating. Can somebody check and let me know what am i missing?
Documentation I followed:
https://shopware.stoplight.io/docs/admin-api/ZG9jOjEyMzA4NTQ5-writing-entities
This website has all apis and example methods. https://swagger.docs.fos.gg/,
rule-condition entity can also be found there.
Btw : I used postman for testing api
You're passing an array of objects in the request body, suggesting you want to update multiple records, but the endpoint only supports updating a single record. The correct payload in your case should look like this:
{
"value": {
"operator": "=",
"email": "test#gmail.com"
}
}
Notice that value is a json field and not only includes a single value. The exact content and the names of the properties of value depend on the type of condition used and usually it also includes the operator used in the condition.

Missing page content when using generator in Wikipedia API

I'm using the categorymembers generator in Wikipedia API to retrieve all pages in a category efficiently, for example:
https://en.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&generator=categorymembers&rvprop=content&rvslots=*&gcmtitle=Category%3AAirports%20in%20Chad&gcmlimit=5000
(sandbox link)
But some articles are missing content, for instance page id 40376021 "Tchagen Airport":
"40376021": {
"pageid": 40376021,
"ns": 0,
"title": "Tchagen Airport"
},
However, when I retrieve the individual page, it does have content:
https://en.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&titles=Tchagen%20Airport&formatversion=2&rvprop=content&rvslots=*
(sandbox link)
{
"batchcomplete": true,
"query": {
"pages": [
{
"pageid": 40376021,
"ns": 0,
"title": "Tchagen Airport",
"revisions": [
{
"slots": {
"main": {
"contentmodel": "wikitext",
"contentformat": "text/x-wiki",
"content": "page content here (long, ommited)"
}
}
}
]
}
]
}
}
I don't know what's going on here. It's not a recently created page so it can't be a caching issue. How to ensure that content for all pages can be seen in bulk results?
You only see the content of the first 50 pages.
Thus, it's best practice to set gcmlimit=50 in your request:
https://en.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&generator=categorymembers&rvprop=content&rvslots=*&gcmtitle=Category%3AAirports%20in%20Chad&gcmlimit=50
In the response, you will see a continue>gcmcontinue value. Use this value in a next request to get the content of another 50 pages:
https://en.wikipedia.org/w/api.php?action=query&format=json&prop=revisions&generator=categorymembers&rvprop=content&rvslots=*&gcmtitle=Category%3AAirports%20in%20Chad&gcmlimit=50&gcmcontinue=page|482a402a042a3a4c48464c50011001dcc2dc0a|21079773
If the response does not contain a continue value, you know that you retrieved all data.

How to replace session with stateless rest apis?

So, I am trying to make a shopping cart web architecture on rest framework where I am struggling to use browser storages to use as an alternative to maintaining the state.
I tried the window.localStorage and window.sessionStorage() APIs but it failed in the case of the private browsing mode in Safari and Opera.
So can anyone help out in the figuring other methods by which I can maintain states in rest based architecture?
You don't need sessions to store application state. User resources.
On approach would be to model every shopping cart as a resource with a unique ID:
/shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80
The client application in the browser would read this resource:
GET /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80
It would add an item to the cart:
POST /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items
{
"itemId": "1234",
"quantity": 1
}
It would list the contents of the shopping cart:
GET /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items
[
{
"itemId": "1234",
"title": "Some nice item",
"quantity": 1,
"price", 12.34,
"priceTotal": 12.34
},
{
"itemId": "9876",
"title": "Some other nice item",
"quantity": 2,
"price", 0.99,
"priceTotal": 1.98
}
]
The web application would remove an item from the cart:
DELETE /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items/9876
I think you get the idea.

How to get track ID from URL using the SoundCloud API

How can I get a track ID from a track URL using the SoundCloud API?
You didn't specify a language in your question, so I'm just going to provide a high-level answer.
Use the resolve endpoint. I'm using this URL as an example:
https://soundcloud.com/msmrsounds/ms-mr-hurricane-chvrches-remix
HTTP GET: https://api.soundcloud.com/resolve.json?url=https%3A%2F%2Fsoundcloud.com%2Fmsmrsounds%2Fms-mr-hurricane-chvrches-remix&client_id=[your_client_id]
The resulting JSON:
{
"status": "302 - Found",
"location": "https://api.soundcloud.com/tracks/147986343.json?client_id=[YOUR client_id]"
}
That numerical value is the track_id. You can just stop here or hit that endpoint you just got back for more information:
{
"kind": "track",
"id": 90787841,
"created_at": "2013/05/05 00:15:40 +0000",
"user_id": 7853935,
"duration": 188333,
"commentable": true,
"state": "finished",
"original_content_size": 35031144,
"last_modified": "2014/09/30 05:53:10 +0000",
"sharing": "public",
"tag_list": "MSMR CHVRCHES \"Secondhand Rapture\" Remix Hurricane",
"permalink": "ms-mr-hurricane-chvrches-remix",
"streamable": true,
"embeddable_by": "all",
"downloadable": true,
"purchase_url": null,
"label_id": null,
"purchase_title": null,
"genre": "",
"title": "MS MR - Hurricane (CHVRCHES remix)",
"description": "MS MR - Hurricane (CHVRCHES remix)\r\n\r\n\r\n",
"label_name": "",
"release": "",
"track_type": "",
"key_signature": "",
"isrc": "",
"video_url": null,
"bpm": null,
"release_year": null,
"release_month": null,
"release_day": null,
"original_format": "wav",
"license": "all-rights-reserved",
"uri": "https://api.soundcloud.com/tracks/90787841",
"user": {
"id": 7853935,
"kind": "user",
"permalink": "msmrsounds",
"username": "MSMR",
"last_modified": "2014/08/04 09:03:56 +0000",
"uri": "https://api.soundcloud.com/users/7853935",
"permalink_url": "http://soundcloud.com/msmrsounds",
"avatar_url": "https://i1.sndcdn.com/avatars-000037198343-2lptmy-large.jpg?86347b7"
},
"permalink_url": "http://soundcloud.com/msmrsounds/ms-mr-hurricane-chvrches-remix",
"artwork_url": null,
"waveform_url": "https://w1.sndcdn.com/56LCadzDEBZn_m.png",
"stream_url": "https://api.soundcloud.com/tracks/90787841/stream",
"download_url": "https://api.soundcloud.com/tracks/90787841/download",
"playback_count": 1672227,
"download_count": 18494,
"favoritings_count": 20426,
"comment_count": 464,
"attachments_uri": "https://api.soundcloud.com/tracks/90787841/attachments",
"policy": "ALLOW"
}
Since the SoundCloud API is indefinitely not accepting new registrations, here's one alternative solution. This URL will provide you with a wide/short embedded player:
https://w.soundcloud.com/player/?url= + URL of track
Example: https://w.soundcloud.com/player/?url=https://soundcloud.com/chrisbjerken/picking-up-the-pieces
This works for both a single track or a playlist.
So my final code looks like this. Thank you guys for the help to get this working.
include_once('../Services/Soundcloud.php');
$client = new Services_Soundcloud('CLIENT_ID', 'CLIENT_SECRET');
$track_url=$_POST['trackurl'];
$track_url=str_replace("https://soundcloud.com/USERNAME/","",$track_url);
$track = json_decode($client->get("tracks/".$track_url));
$track_id=$track->id;
echo $track_id;
In The Meantime Writing This Answer The CLIENT_ID Is Close
Due to the high amount of requests recently received, we will no longer be processing API application requests at this time. We are working to re-evaluate our process to make it more efficient.
See Here
I Solved This Issue With My Laravel Project Like This
first I Made This Function To Get The Real Content
public function getLessonUrl($lessonId = null)
{
//Get the SoundCloud URL
$validUrl = 'https://soundcloud.com/al-hazme';
$result = stripos($lessonId, $validUrl);
if (strpos($lessonId, $validUrl) !== false) {
//Get the JSON data details with embed code from SoundCloud oEmbed
$getValues = #file_get_contents('http://soundcloud.com/oembed?format=js&url=' . $lessonId . '&color=%234274e3&auto_play=false&hide_related=true&show_comments=false&show_user=false&show_reposts=false&show_teaser=true&show_artwork');
if ($getValues === false) {
return 'حدث خطأ اثناء تحميل الدرس نرجو منك التأكد من اتصال الانترنيت لديك او حدث الصفحة';
}
//Clean the Json to decode
$decodeiFrame = substr($getValues, 1, -2);
//json decode to convert it as an array
$jsonObj = json_decode($decodeiFrame);
//echo $jsonObj->html;
$lessons = str_replace('height="400"', 'height="90"', $jsonObj->html);
return $lessons;
} else {
return 'لايوجد استماع لهذا الدرس';
}
}
Then I Made Another Function To Crap The Id Using Str Facade Methods
use Illuminate\Support\Str;
public function soundCloudId($url) {
$do = $lesson->getLessonUrl($lesson->url_link);
$getTrickId = Str::after($do,'tracks%2F');
$substr = Str::substr($getTrickId,0,9);
echo $substr = // 367893857
}
It May Help Or Give You Clue
I know this is kinda late but i faced the same issue yesterday and found a new (undocumented) endpoint that you can use.
https://api-widget.soundcloud.com/resolve?url=SOUNDLCOUD_URL&format=json&client_id=CLIENT_ID
You can find your CLIENT_ID by looking at the Network Inspector in the DevTools and select the XHR filter while browsing the SoundCloud website.
I think this is sufficient until the official APIs are usable again.

Setting product published date via Shopify API doesn't work properly

When I set the published_at to a furture date by using the following JSON via Shopify product update API (https://ashop.myshopify.com/admin/products/product_id.json PUT).
{
"product": {
"id": 632910392,
"published": false,
"published_at": "2015-01-01T00:00:00+11:00"
}
}
It returned 200 and the following JSON
{
"product": {
"body_html": "something",
"created_at": "2014-01-07T14:49:00+11:00",
"handle": "test-product",
"id": 206281997,
"product_type": "MERCHANDISE",
"published_at": "2015-01-01T00:00:00+11:00",
"published_scope": "",
},
/* some other JavaScript properties*/
}
Shopify accepted the published date but the product was still visible. Below is the screenshot of the product Visibility
But if I removed "published_at": "2015-01-01T00:00:00+11:00" from the request JSON, the product changed to hidden.
How can I set the published date via Shopify API? Is it possible a Shopify API's bug?
Thanks for you help.
I have found a solution by using private API. And I tested it. Use publish_on instead of published_at. please refer to Shopify forums http://ecommerce.shopify.com/c/shopify-apis-and-technology/t/setting-product-published-date-via-shopify-api-doesn-t-work-properly-173469