I am wondering how to get this item description / information from transactions on Square. For me, even using:
'/v2/locations/{0}/transactions/{1}'.format(LOC_ID, tid)
Does not return any item names, instead I get completely anonymous/useless information:
{
"transaction": {
"id": "BZDxxxxxx",
"location_id": "3PBxxxxx",
"created_at": "2016-10-14T22:55:33Z",
"tenders": [
{
"id": "VJO1rxxxxx",
"location_id": "3PBxxxx",
"transaction_id": "BZDxxxxxx",
"created_at": "2016-10-14T22:55:31Z",
"amount_money": {
"amount": 2800,
"currency": "USD"
},
"processing_fee_money": {
"amount": 0,
"currency": "USD"
},
"type": "OTHER"
}
],
"product": "REGISTER",
"client_id": "1E7xxxx"
}
}
How do I go from what is returned above to the item name that is shown on the website transaction list?
You can itemize your transactions with the Orders Endpoints Have you tried using the /v1/{location_id}/payments endpoint? You can get some more information about the items there.
https://docs.connect.squareup.com/api/connect/v1/#updatingorderstate
Related
We are new to Here Api,
Our team is working on one transportation project in which we required to get max speed limit of road using vehicle (latitude ,longitude).
From last few days we are trying to figure out which api should we use in HereApi to achieve what we want.
Regarding this documentation of HERE Route Matching 8: https://developer.here.com/documentation/route-matching/api-reference.html
Send please POST request like:
https://routematching.hereapi.com/v8/match/routelinks?apikey=LXX1Axs75efnlFAlgbPxVekPDR0Hz6rTcRHQMT0EvQs&routeMatch=1&mode=fastest;car;traffic:disabled;&attributes=SPEED_LIMITS_FCn(*),LINK_ATTRIBUTE_FCn(*),TRAFFIC_PATTERN_FCn(*),TRUCK_SPEED_LIMITS_FCn(*),SPEED_LIMITS_VAR_FCn(*),SPEED_LIMITS_COND_FCn(*)
With in body:
LATITUDE,LONGITUDE
37.4201866,15.049515
See please attached the Postman collection for test of HERE Rote Match API v8 https://developer.here.com/documentation/route-matching/dev_guide/index.html :
{
"info": {
"_postman_id": "2563b7cc-2d62-4485-bb64-2f9561318aa2",
"name": "RMEspeed_limit",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "1051680"
},
"item": [
{
"name": "speed_limit",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "LATITUDE,LONGITUDE\r\n37.4201866,15.049515"
},
"url": {
"raw": "https://routematching.hereapi.com/v8/match/routelinks?apikey=LXX1Axs75efnlFAlgbPxVekPDR0Hz6rTcRHQMT0EvQs&routeMatch=1&mode=fastest;car;traffic:disabled;&attributes=SPEED_LIMITS_FCn(*),LINK_ATTRIBUTE_FCn(*),TRAFFIC_PATTERN_FCn(*),TRUCK_SPEED_LIMITS_FCn(*),SPEED_LIMITS_VAR_FCn(*),SPEED_LIMITS_COND_FCn(*) ",
"protocol": "https",
"host": [
"routematching",
"hereapi",
"com"
],
"path": [
"v8",
"match",
"routelinks"
],
"query": [
{
"key": "apikey",
"value": "LXX1Axs75efnlFAlgbPxVekPDR0Hz6rTcRHQMT0EvQs"
},
{
"key": "routeMatch",
"value": "1"
},
{
"key": "mode",
"value": "fastest;car;traffic:disabled;"
},
{
"key": "attributes",
"value": "SPEED_LIMITS_FCn(*),LINK_ATTRIBUTE_FCn(*),TRAFFIC_PATTERN_FCn(*),TRUCK_SPEED_LIMITS_FCn(*),SPEED_LIMITS_VAR_FCn(*),SPEED_LIMITS_COND_FCn(*) "
}
]
}
},
"response": []
}
]
}
An apikey and coordinate you specify your own for sure.
About all layers attributes you can see this example: https://demo.support.here.com/pde/maps?url_root=pde.api.here.com
In Python you should use normal POST request using some http libraries developed for Python:
https://www.geeksforgeeks.org/get-post-requests-using-python/
i have this document in mongodb
{
"_id": {
"$oid": "62644af0368cb0a46d7c2a95"
},
"insertionData": "23/04/2022 19:50:50",
"ipfsMetadata": {
"Name": "data.json",
"Hash": "Qmb3FWgyJHzJA7WCBX1phgkV93GiEQ9UDWUYffDqUCbe7E",
"Size": "431"
},
"metadata": {
"sessionDate": "20220415 17:42:55",
"dataSender": "user345",
"data": {
"height": "180",
"weight": "80"
},
"addtionalInformation": [
{
"name": "poolsize",
"value": "30m"
},
{
"name": "swimStyle",
"value": "mariposa"
},
{
"name": "modality",
"value": "swim"
},
{
"name": "gender-title",
"value": "schoolA"
}
]
},
"fileId": {
"$numberLong": "4"
}
}
I want to update nested array document, for instance the name with gender-tittle. This have value schoolA and i want to change to adult like the body. I give the parameter number of fileId in the post request and in body i pass this
post request : localhost/sessionUpdate/4
and body:
{
"name": "gender-title",
"value": "adultos"
}
flask
#app.route('/sessionUpdate/<string:a>', methods=['PUT'])
def sessionUpdate(a):
datas=request.json
r=str(datas['name'])
r2=str(datas['value'])
print(r,r2)
r3=collection.update_one({'fileId':a, 'metadata.addtionalInformation':r}, {'$set':{'metadata.addtionalInformation.$.value':r2}})
return str(r3),200
i'm getting the 200 but the document don't update with the new value.
As you are using positional operator $ to work with your array, make sure your select query is targeting array element. You can see in below query that it is targeting metadata.addtionalInformation array with the condition that name: "gender-title"
db.collection.update({
"fileId": 4,
"metadata.addtionalInformation.name": "gender-title"
},
{
"$set": {
"metadata.addtionalInformation.$.value": "junior"
}
})
Here is the Mongo playground for your reference.
I'm pretty new to Python so forgive me here.
I'm trying to call/print/log JSON from a GET request. I need to get the id's following this tree: items > track > artists > id.
Basically im trying to just get the ID's from each track on this JSON file/list. I keep getting errors no matter how I format them. Again im new so im not sure how to call it let also run it in a loop to get all the ID's as an array. I have done it with other JSON files in the past but this one is farther in and I get the error : TypeError: list indices must be integers or slices, not str
I figured out it works when you do it by adding the [0] like this:
artists = response["items"][0]["track"]["artists"] BUT I want to loop it and get all of the Id's for each one and that option picks just one.
here is the beginning of the json so you can see the layout.
{
"href": "https://api.spotify.com/v1/me/tracks?offset=0&limit=15&market=US",
"items": [
{
"added_at": "2021-12-15T22:26:25Z",
"track": {
"album": {
"album_type": "single",
"artists": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/6MlPT0WxdWnrYcpXT8GZF8"
},
"href": "https://api.spotify.com/v1/artists/6MlPT0WxdWnrYcpXT8GZF8",
"id": "6MlPT0WxdWnrYcpXT8GZF8",
"name": "PARKFORD",
"type": "artist",
"uri": "spotify:artist:6MlPT0WxdWnrYcpXT8GZF8"
}
],
"external_urls": {
"spotify": "https://open.spotify.com/album/4o2d8uBTyMfJeaJqSXn9tP"
},
"href": "https://api.spotify.com/v1/albums/4o2d8uBTyMfJeaJqSXn9tP",
"id": "4o2d8uBTyMfJeaJqSXn9tP",
"images": [
{
"height": 640,
"url": "https://i.scdn.co/image/ab67616d0000b27332bcd9e1b2234c6cd6b2b2ec",
"width": 640
},
{
"height": 300,
"url": "https://i.scdn.co/image/ab67616d00001e0232bcd9e1b2234c6cd6b2b2ec",
"width": 300
},
{
"height": 64,
"url": "https://i.scdn.co/image/ab67616d0000485132bcd9e1b2234c6cd6b2b2ec",
"width": 64
}
],
"name": "There's Nothing in the Rain",
"release_date": "2021-11-25",
"release_date_precision": "day",
"total_tracks": 1,
"type": "album",
"uri": "spotify:album:4o2d8uBTyMfJeaJqSXn9tP"
},
"artists": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/6MlPT0WxdWnrYcpXT8GZF8"
},
"href": "https://api.spotify.com/v1/artists/6MlPT0WxdWnrYcpXT8GZF8",
"id": "6MlPT0WxdWnrYcpXT8GZF8",
"name": "PARKFORD",
"type": "artist",
"uri": "spotify:artist:6MlPT0WxdWnrYcpXT8GZF8"
here is the code I have written out
uri = MY_LIKED_SONGS
headers = {
"Authorization": f'Bearer {tokens["access_token"]}',
"Content-Type": "application/json",
}
r = requests.get(uri, headers=headers)
response = r.json()
# return response
artist_ids = {}
data = json.dumps(response)
for artist_ids in data["items"]["track"]:
logger.info(artist_ids["items"]["track"]["artists"]["id"])
print(artist_ids["_source"]["items"][0]["track"]["id"])
tracks = response["items"]["track"][0]["artists"]["id"]
Here when you do json.dumps(), it converts a Python object into a json string. In order to iterate through json object you need to convert it into json object. For that you have to use json.loads() then you can get artist id from that.
data = json.loads(json.dumps(response))
for item in data["items"]:
for artist in item['track']['album']['artists']:
print(artist['id'])
This might be helpful.
This question already has answers here:
Python list of dictionaries search
(24 answers)
Finding the index of an item in a list
(43 answers)
Closed 6 years ago.
I have a site that I'm working on using Django that makes API requests to get information about cars. These requests are triggered by JS events, which go to a created URL that connects to a view. In my view, I make the actual API request and use the .json() method to get the returned JSON from the response.
What I'm having trouble doing however is getting a certain index/value from this response.
Here is an example of a response I would receive:
{
"equipment": [{
"id": "20047746549",
"name": "Specifications",
"equipmentType": "OTHER",
"availability": "STANDARD",
"attributes": [{
"name": "Aerodynamic Drag (cd)",
"value": "0.26"
}, {
"name": "Ege Highway Mpg",
"value": "29"
}, {
"name": "Epa Combined Mpg",
"value": "23"
}, {
"name": "Epa City Mpg",
"value": "20"
}, {
"name": "Curb Weight",
"value": "3957"
}, {
"name": "Turning Diameter",
"value": "39.0"
}, {
"name": "Manufacturer 0 60mph Acceleration Time (seconds)",
"value": "6.6"
}, {
"name": "Epa Highway Mpg",
"value": "29"
}, {
"name": "Tco Curb Weight",
"value": "3957"
}, {
"name": "Ege Combined Mpg",
"value": "23"
}, {
"name": "Fuel Capacity",
"value": "19.8"
}, {
"name": "Ege City Mpg",
"value": "20"
}]
}],
"equipmentCount": 1
}
What I'm trying to get is the "value": "3957" that corresponds to the "name": "Curb Weight" attribute
The way I thought about doing so (in Python) was jsonResponse['equipment'][0]['attributes'][4]['value'] however the index is not always the same for this Curb Weight attribute. Sometimes the index is 5, sometimes 6, etc.
Is there anyway to get this Curb Weight attribute, or any other attribute, by the value of it's "name" key?
This question already has an answer here:
Paypal PHP REST service - "access token does not have required scope"
(1 answer)
Closed 7 years ago.
I'm now putting a paypal subscription button on my site using python paypal-sdk
To subscribe payment, I'm following these steps.
create billing plan
activate it
create billing agreement
execute it.
But creating billing plan has been failed and sent me REQUIRED SCOPE MISSING error. I copied billing plan arguments from paypal official dev site. So I don't think I missed something on request.
Here is my code to create billing plan
billing_plan = paypalrestsdk.BillingPlan({
"name": "T-Shirt of the Month Club Plan",
"description": "Monthly plan for getting the t-shirt of the month.",
"type": "fixed",
"payment_definitions": [
{
"name": "Trial Plan",
"type": "TRIAL",
"frequency_interval": "1",
"frequency": "MONTH",
"cycles": "1",
"amount": {
"currency": "USD",
"value": "9.99"
},
"charge_models": [
{
"type": "TAX",
"amount": {
"currency": "USD",
"value": "1.65"
}
},
{
"type": "SHIPPING",
"amount": {
"currency": "USD",
"value": "9.99"
}
}
]
},
{
"name": "Standard Plan",
"type": "REGULAR",
"frequency_interval": "1",
"frequency": "MONTH",
"cycles": "11",
"amount": {
"currency": "USD",
"value": "19.99"
},
"charge_models": [
{
"type": "TAX",
"amount": {
"currency": "USD",
"value": "2.47"
}
},
{
"type": "SHIPPING",
"amount": {
"currency": "USD",
"value": "9.99"
}
}
]
}
],
"merchant_preferences": {
"setup_fee": {
"currency": "USD",
"value": "1"
},
"cancel_url": "http://www.cancel.com",
"return_url": "http://www.return.com",
"max_fail_attempts": "0",
"auto_bill_amount": "YES",
"initial_fail_amount_action": "CONTINUE"
}
})
if billing_plan.create():
return billing_plan.id
and here is my configuration for paypal
PAYPAL_CONF = {
'mode': 'sandbox',
'client_id': CLIENT_ID_IN_SANDBOX_ACCOUNT,
'client_secret': SECRET_IN_SANDBOX_ACCOUNT,
}
paypalrestsdk.configure(settings.PAYPAL_CONF)
and error message
ForbiddenAccess: Failed. Response status: 403. Response message: Forbidden. Error message: {"name":"REQUIRED_SCOPE_MISSING","message":"Access token does not have required scope","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#REQUIRED_SCOPE_MISSING","debug_id":"bf845229ca125"}
I've searched a few of articles, but no luck.
EDIT: I've tried about app settings, but the problem is different.
My co-worker solved this for me. Actually I'm using default sandbox facilitator app which paypal created for me. You can access those app like this. (*it doesn't show apps on Dashboard)
sandbox > accounts > account-facilitator > profile > API credentials tab > apps
But It wasn't working. So he made a new app using Dashboard > My Apps & credencials > create app(sandbox) and replaced client id and secret of new one.
It works like magic.
ps. When I was struggling with it, I found #tamak's comment. "gave me a really weird feeling about using paypal at all to be honest." in https://stackoverflow.com/a/26393932/4476298
SO TRUE.