Fetch ID of first response RestAssured - api

I am getting many responses via GET http request but I only want to fetch the ID of first student which I got in response how to do it in Rest Assured.
[
{
"id": 14114,
"name": "Pragyanshii",
},
{
"id": 14119,
"name": "ankit",
},
{
"id": 14122,
"name": "varun",
}
]
I want to fetch id: 14114

This is one way to achieve your goal.
Response response = ...;
int id = response.jsonPath().get("[0].id");
System.out.println(id); //14114

Related

GraphQL query - Query by ID

I have installed the strapi-starter-blog locally and I'm trying to understand how I can query article by ID (or slug). When I open the GraphQL Playground, I can get all the article using:
query Articles {
articles {
id
title
content
image {
url
}
category {
name
}
}
}
The response is:
{
"data": {
"articles": [
{
"id": "1",
"title": "Thanks for giving this Starter a try!",
"content": "\n# Thanks\n\nWe hope that this starter will make you want to discover Strapi in more details.\n\n## Features\n\n- 2 Content types: Article, Category\n- Permissions set to 'true' for article and category\n- 2 Created Articles\n- 3 Created categories\n- Responsive design using UIkit\n\n## Pages\n\n- \"/\" display every articles\n- \"/article/:id\" display one article\n- \"/category/:id\" display articles depending on the category",
"image": {
"url": "/uploads/blog_header_network_7858ad4701.jpg"
},
"category": {
"name": "news"
}
},
{
"id": "2",
"title": "Enjoy!",
"content": "Have fun!",
"image": {
"url": "/uploads/blog_header_balloon_32675098cf.jpg"
},
"category": {
"name": "trends"
}
}
]
}
}
But when I try to get the article using the ID with variable, like here github code in the GraphQL Playground with the following
Query:
query Articles($id: ID!) {
articles(id: $id) {
id
title
content
image {
url
}
category {
name
}
}
}
Variables:
{
"id": 1
}
I get an error:
...
"message": "Unknown argument \"id\" on field \"articles\" of type \"Query\"."
...
What is the difference and why can't I get the data like in the example of the Github repo.
Thanks for your help.
It's the difference between articles and article as the query. If you use the singular one you can use the ID as argument

Appstoreconnect Api user update

I can’t understand how to create the http body of the Modify User Account api:
PATCH
https://api.appstoreconnect.apple.com/v1/users/{id}
In particular the:
[UserUpdateRequest.Data.Relationships.VisibleApps.Data]
What are the required id and type properties of Data object? Could somebody provide a code or postman example of a request ?
This is the url of the topic:
Appstoreconnect Api - Update User
The PATCH request should look like this:
PATCH /v1/users/XXX
{
"data": {
"type": "users",
"id": "XXX",
"attributes": {
"allAppsVisible": false
},
"relationships": {
"visibleApps": {
"data": [
{"type": "apps", "id": "AAA"},
{"type": "apps", "id": "BBB"}
]
}
}
}
}
Where AAA and BBB are Apple IDs of your apps. You can find these on the App Information page, or in response to the /v1/apps API calls.

Is it possible to extend graphql response other than just data for pagination?

In GraphQL response normally looks like followings.
{
"data": [{
"id": 1,
"username": "Jon Snow",
"email": "crow#northofthew.all",
"age": 20
}, {
"id": 2,
"username": "Tyrion Lannister",
"email": "drunk#i.mp",
"age": 34
}, {
"id": 3,
"username": "Sansa Stark",
"email": "redhead#why.me",
"age": 17
}]
}
Is it possible to add meta data to your response such as pagination like this.
{
"pagination": {
"total": 14,
"count": 230,
},
"data": [{
"id": 1,
"username": "Jon Snow",
"email": "crow#northofthew.all",
"age": 20
}, {
"id": 2,
"username": "Tyrion Lannister",
"email": "drunk#i.mp",
"age": 34
}]
}
I'm using express-graphql and currently put those pagination to custom response header, which is fine but it can be better. Since GraphQL response is already wrapped with "data", it is not very strange to add more "data" to its response.
Reenforcing what #CommonsWare already stated, according to the specification that would a be an invalid GraphQL response. Regarding pagination, Relay has its own pagination approach called connections, but indeed, several other approaches are possible and even more suitable in some situtations (connections aren't a silver bullet).
I want to augment what was already said by adding that the hierarchical nature of GraphQL incites related data to be at the same level. An example is worth a thousands words, so here it goes:
query Q {
pagination_info { # what is this info related to? completely unclear
total
count
}
user {
friends {
id
}
}
}
Instead...
query Q {
user {
friends {
pagination_info { # fairly obvious that this is related to friends
total
count
}
friend {
id
}
}
}
}

How to get oldest message id GMAIL API

I'm using to get the list of message_ID users_messages->listusersmessages. Is there a way to get the oldest message_ID?
You can not specify the order in which to list messages, at this time. You will have to list every message until you get the last page of message ids:
Request 1
GET https://www.googleapis.com/gmail/v1/users/me/messages?access_token={YOUR_ACCESS_TOKEN}
Response 1
{
"messages": [
{
"id": "155fd69a74bceff0",
"threadId": "155fd69a74bceff0"
}, ...
],
"nextPageToken": "03259718007012574564",
"resultSizeEstimate": 103
}
Use the nextPageToken, and continue to list messages until there is no nextPageToken in the response.
Request 2
GET https://www.googleapis.com/gmail/v1/users/me/messages?pageToken=03259718007012574564&access_token={YOUR_ACCESS_TOKEN}
Response 2
{
"messages": [
{
"id": "155772ef5633f85b",
"threadId": "155772ef5633f85b"
},
...,
{
"id": "1557460c0e3b5a89",
"threadId": "1557460c0e3b5a89"
}
],
"resultSizeEstimate": 103
}
This response has no nextPageToken, so 1557460c0e3b5a89 is the last one.

How to add an Item to a quote/cart via API on Magento2

I have tried calling [POST] /carts/mine/items, headers with correct bearer, and body:
{
"cart_item": 1,
"sku": "MY_SKU",
"qty": 1
}
and I get the folowing response:
{
"message": "Invalid value of \"%value\" provided for the %fieldName field.",
"parameters": {
"fieldName": "qty",
"value": null
}
}
Two things, I do not understand what to put in cart_item (but it is required) and I do not why it keeps telling me qty is null?
First of all empty cart should be created using request with empty body:
[POST] {base URL}/rest/V1/carts/mine
In response you will get ID of your quote.
Now you can add items to your cart using:
[POST] {base URL}/rest/V1/carts/mine/items
{
"cart_item": {
"quote_id": <cart ID received from previous call>,
"sku": "product_sku",
"qty": 10
}
}
In response you should get your cart item data:
{
"item_id": 1,
"sku": "product_sku",
"qty": 10,
"name": "Simple Product",
"price": 123,
"product_type": "simple",
"quote_id": "1"
}
Be careful since you may accidentally update existing cart item quantity with POST request, if execute the same request several times.
It is an addition to #Alex Palirush's answer thanks to explain it clearly.
The quote id must be integer otherwise it will through an error unknown field cartId.
{
"message": "No such entity with %fieldName = %fieldValue",
"parameters": {
"fieldName": "cartId",
"fieldValue": "0"
}
}