How to get oldest message id GMAIL API - google-oauth

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.

Related

Google Analytics 4 - Measurement Protocol hits not recording

I'm sending events hits to GA using the Measurement Protocol for GA4 but the hits are not getting recorded (they are showing on the GA dashboard even after waiting for more then 24 hours).
The URL I'm sending the POST request to:
https://www.google-analytics.com/mp/collect?measurement_id=G-XXXXXXXXXX&api_secret=XXXXXXXXXXXX
The JSON body:
{
"client_id": "XXXXXXX.XXXXXXX",
"events": [
{
"name": "add_to_cart",
"params": {
"value": 50,
"currency": "USD",
"items": [
{
"item_id": "ITEM-SKU-001",
"item_name": "Product Name",
"item_variant": "Product Name",
"currency": "USD",
"price": "50",
"quantity": 1
}
]
}
}
]
}
The "client_id" is the value of the _ga cookie with "GA1.1." removed.
The above request returns an empty response body and a 204 http status code.
When I send the hit to the debug URL, I get the http status code 200 and the response body as:
{
"validationMessages": []
}
What am I doing wrong?

Bad Request: One or more of the contents is not owned by the author. All contents must be owned by the author

I've been trying to POST an image to linkedin via the API given by linkedin: https://api.linkedin.com/v2/ugcPosts
Here are some of the steps I followed according to their documentation:
Step 1: Register the image,
Response I get:
{
"value": {
"mediaArtifact": "urn:li:digitalmediaMediaArtifact:(urn:li:digitalmediaAsset:C4D22AQHnSETazVUUiw,urn:li:digitalmediaMediaArtifactClass:feedshare-uploadedImage)",
"uploadMechanism": {
"com.linkedin.digitalmedia.uploading.MediaUploadHttpRequest": {
"uploadUrl": "https://api.linkedin.com/mediaUpload/C4D22AQHnSETazVUUiw/feedshare-uploadedImage/0?ca=vector_feedshare&cn=uploads&m=AQKy8KTj9ZExhAAAAYUvD_6GEclpKOZdwJvPF682Ld1UUb6h0V7VvAtpuA&app=206373578&sync=0&v=beta&ut=3dh6EETZGM5WA1",
"headers": {
"media-type-family": "STILLIMAGE"
}
}
},
"asset": "urn:li:digitalmediaAsset:C4D22AQHnSETazVUUiw",
"assetRealTimeTopic": "urn:li-realtime:digitalmediaAssetUpdatesTopic:urn:li:digitalmediaAsset:C4D22AQHnSETazVUUiw"
}
}
Step 2: Upload the image using upload URL from Step 1
Response: 201 Created status code with no message
Checked the status, it's says available: https://api.linkedin.com/v2/assets/C4D22AQHnSETazVUUiw
{
"recipes": [
{
"recipe": "urn:li:digitalmediaRecipe:feedshare-image",
"status": "AVAILABLE"
}
],
"serviceRelationships": [
{
"relationshipType": "OWNER",
"identifier": "urn:li:userGeneratedContent"
}
],
"mediaTypeFamily": "STILLIMAGE",
"created": 1671531855410,
"id": "C4D22AQHnSETazVUUiw",
"lastModified": 1671531901231,
"status": "ALLOWED"
}
Now when I am trying to POST it to the endpoint: https://api.linkedin.com/v2/ugcPosts
It's giving 400 bad Request with the following Error:
{
"errorDetailType": "com.linkedin.common.error.BadRequest",
"message": "com.linkedin.content.common.exception.BadRequestResponseException: One or more of the contents is not owned by the author. All contents must be owned by the author",
"errorDetails": {
"inputErrors": [
{
"description": "Content(s) you provided must be owned by post author",
"input": {},
"code": "INVALID_CONTENT_OWNERSHIP"
}
]
},
"status": 400
}
I've given all permissions to it:
r_emailaddress, r_liteprofile, w_member_social

Fetch ID of first response RestAssured

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

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"
}
}

Detect the id of a sent mail

I would like to detect the message-id of an email
sent from the gmail interface?
what are your proposals?
Thanks.
One way of doing it would be to first list messages:
GET https://www.googleapis.com/gmail/v1/users/me/messages
Response:
{
"messages": [
{
"id": "14f60b097be71757",
"threadId": "14f60b097be71757"
},
{
"id": "14f603ead78aff97",
"threadId": "14f603ead78aff97"
}, ...
Then, get the message you want, and just ask for the Message-Id-header:
format = metadata
metadataHeaders = Message-Id
GET https://www.googleapis.com/gmail/v1/users/me/messages/14f60b097be71757?format=metadata&metadataHeaders=Message-Id
Response:
{
"id": "14f60b097be71757",
"threadId": "14f60b097be71757",
"labelIds": [
"INBOX",
"CATEGORY_PROMOTIONS",
"UNREAD"
],
"snippet": "Cool snippet...",
"historyId": "545168",
"internalDate": "1440436229000",
"payload": {
"mimeType": "multipart/alternative",
"headers": [
{
"name": "Message-Id",
"value": "<10342275.20150824171029.55db500501e9a7#example.com>" // Here it is!
}
]
},
"sizeEstimate": 73995
}