Shippo - Python Package Async Issue - shippo

I have imported the Shippo python package and I am trying to get their sample to work but I am running into the following error message (see below). I am running Python 3.7.2 on the most current API version.
Here is the error -
Traceback (most recent call last):
File "c:/Users/tom/Documents/PyProjects/goShippo/goShippoCreateLabels.py", line 1, in <module>
import shippo
File "C:\Python\lib\site-packages\shippo\__init__.py", line 8, in <module>
from shippo.resource import (
File "C:\Python\lib\site-packages\shippo\resource.py", line 303
def get_rates(cls, object_id, async=False, api_key=None, currency=None, **params):
^
SyntaxError: invalid syntax
Here is the code -
import shippo
shippo.api_key = "shippo_test_123456789"
address_from = {
"name": "Shawn Ippotle",
"company": "Shippo",
"street1": "215 Clayton St.",
"city": "San Francisco",
"state": "CA",
"zip": "94117",
"country": "US",
"phone": "+1 555 341 9393",
"email": "shippotle#goshippo.com"
}
address_to = {
"name": "Mr Hippo",
"company": "",
"street1": "Broadway 1",
"street2": "",
"city": "New York",
"state": "NY",
"zip": "10007",
"country": "US",
"phone": "+1 555 341 9393",
"email": "mrhippo#goshippo.com",
"metadata": "Hippos dont lie"
}
parcel = {
"length": "5",
"width": "5",
"height": "5",
"distance_unit": "in",
"weight": "2",
"mass_unit": "lb"
}
shipment = {
"address_from": address_from,
"address_to": address_to,
"parcels": [parcel]
}
transaction = shippo.Transaction.create(
shipment = shipment,
carrier_account = "b741b99f95e841639b54272834bc478c",
servicelevel_token = "usps_priority"
)

This package has Python version coverage up to 3.3. In versions 3.6+, "async" became a reserved keyword causing the syntax error you're getting.
Since "async" is a default parameter, the best workaround would be to explicitly change the "async" parameter to "asynchronous". This should at least avoid the syntax error until the package is updated for 3.6+ support.

Related

Posting address to Sharepoint list via REST

maybe I'm blind but I can't find a documentation how I post an address to an address field on a Sharepoint list via REST.
I always receive an "invalid Request" error. If I remove the address part of my JSON I'm able to fill out the other fields w/o problems. Just struggling with the address.
My request looks like that:
POST:
https://graph.microsoft.com/v1.0/sites/test.sharepoint.com,{siteid}/lists/{listid}/items/
Data:
{
"__metadata": {
"type": "SP.Data.listname.ListItem"
},
"fields":{
"Title": "API Test Project",
"Projekt_ID": "25",
"Typ": "Hinzugefügt",
"MengeNeu": "50/40/330",
"PosNr": "5/4/1",
"Adresse": {
"address": {
"city": "city",
"countryOrRegion": "DE",
"postalCode": "55512",
"state": "test",
"street": "test street 3"
},
"coordinates": {
"latitude": 44.72789001464844,
"longitude": 10.132317543029785
},
"displayName": "Test",
"locationUri": "https://www.bingapis.com/api/v6/localbusinesses/xxx?setLang=de",
"uniqueId": "https://www.bingapis.com/api/v6/localbusinesses/xxx?setLang=de"
}
}
}
Thanks

LiteDB Studio: Unexpected token {

I'm trying to use LiteDB Studio 1.0.2 to import a JSON file. I've created a database and selected the menu option "Import from JSON". I selected a sample file that I found in a post related to NoSQL. It contains:
{
"Contact": [
{
"_id": 1,
"FullName": "Lucy",
"Email": "lucy#gmail.com",
"Phone": "4584656970",
"Address": "223 Str"
},
{
"_id": 2,
"FullName": "Tom",
"Email": "tom#gmail.com",
"Phone": "4375588889",
"Address": "123 Str"
}
]
}
The menu option produces a query template that I updated to:
SELECT $
INTO new_col
FROM $file('Sample.json');
Upon running the query, I immediately receive an error:
Unexpected token { in position 0.
SELECT $ INTO ^
Can anyone shed light on this error?
It seems that LiteDB expects an array of document, so your file should start by [ and end by ] and the documents inside { } in the middle
LiteDB expects an array of json elements, so your file should look like this example
[
{
"_id": 1,
"FullName": "fullname_1",
"Email": "a#example1.com",
"Phone": "0123456789",
"Address": "123 Street"
},
{
"_id": 2,
"FullName": "fullname_2",
"Email": "fullname_2#example1.com",
"Phone": "9876543210",
"Address": "321 Street"
}
]
and your Insert statement will be like that
SELECT $
INTO contacts
FROM $file('Contacts.json');

Generic Sub-Document API in Couchbase

I want to update specific fields in below document stored in Couchbase :
"name": "Douglas Reynholm",
"email": "douglas#reynholmindustries.com",
"addresses": {
"billing": {
"line1": "123 Any Street",
"line2": "Anytown ",
"country": "United Kingdom"
},
"delivery": {
"line1": "123 Any Street",
"line2": "Anytown ",
"country": "United Kingdom"
}
},
"purchases": {
"complete": [
339, 976, 442, 666
],
"abandoned": [
157, 42, 999
]
}
}
How can I write a generic query using Java SDK to handle all possible combinations of subdocument update ? For example one user wants to update "addresses.delivery.country" field and other user wants to update "name" field.
It would be tough to right customized query for each possible case of subdocument update.. is that correct ?

POST request with webmethods

i am using webmethods platform 10.1 and i developed a service that is supposed to receive data as Post request.
when i try to run it on IDE it works fine, but when i publish it and try to access it through API Portal, it does not work.
i am not sure how to map my JSON to my Document. Can anyone please guide me in this regard?
I have attached my Document screen shot as well as the json i am trying to Post.
Can anyone explain how both are not related, because when i post the below JSON to my service, i do not get the values.
{
"EventCompanyId": "443",
"PositionTitleEn": "New post",
"PositionTitleAr": "New post",
"ReportsTo": "Manager",
"KnowledgeRequiredEn": "Basic knowlege",
"KnowledgeRequiredAr": "Basic knowledge",
"ExperienceRequired": "7 years",
"Gender": "1",
"EducationLevel": "4",
"CreatedBy": "1",
"UpdatedBy": "1",
"StartSalary": "35000",
"EndSalary": "35000",
"Status": "0",
"Certificate": "BS",
"YearsOfExperience": "7",
"Major": "5",
"Age": "30",
"JobType": "1",
"TrainingCourse": "",
"Weekdays": "",
"WorkingHours": "",
"Language": "1",
"Shift": "",
"JobLocations": [
{
"EmiratesId": 3,
"NumberOfVacancies": 3,
"EmiratesArea": "United Arab Emirates",
"Latitude": ,
"Longitude": ,
"EmirateEn": null,
"EmirateAr": null,
"EmirateName": null
},
{
"EmiratesId": 6,
"NumberOfVacancies": 23,
"EmiratesArea": " Dubai - United Arab Emirates",
"Latitude": 25.20447520001559,
"Longitude": 55.28122901916504,
"EmirateEn": null,
"EmirateAr": null,
"EmirateName": null
},
{
"EmiratesId": 1,
"NumberOfVacancies": 5,
"EmiratesArea": "Dubai - United Arab Emirates",
"Latitude": ,
"Longitude": ,
"EmirateEn": null,
"EmirateAr": null,
"EmirateName": null
},
{
"EmiratesId": 2,
"NumberOfVacancies": 3,
"EmiratesArea": "D72 - Dubai - United Arab Emirates",
"Latitude": ,
"Longitude": ,
"EmirateEn": null,
"EmirateAr": null,
"EmirateName": null
}
]
}
i have found a solution for it, the problem was i needed to remove Job Properties from under Job Document, they should not be inside any other property.

How do I get user's checked-in places' categories?

I want to get logged in user's Check-ins along with the category of the place he has checked-in.
I tried to fetch the user likes and their categories and this is what worked for me - "/me/likes?fields=category"
Following is the response returned:
{
"data": [{
"name": "11 East Street Cafe",
"category": "Restaurant/Cafe",
"id": "94871278677"
},{
"name": "ABC DEF",
"category": "Politician",
"id": "177526890164"
}],
"paging": {
"cursors": {
"before": "NDkyMzg4OTc3NTYyMjk3",
"after": "MTc3NTI2ODkwMTY0"
}
}
}
For check-ins, I tried "/me/feed?with=location&fields=place,story" and it returns the checked in places list. It returns me following:
{
"data": [{
"place": {
"id": "117586118328311",
"name": "Carraba's",
"location": {
"city": "Ellicott City",
"country": "United States",
"latitude": 39.27153726574,
"longitude": -76.800542073324,
"state": "MD",
"zip": "21043"
}
},
"story": "ABC was at Carraba's.",
"id": "1533836476934935_1546360939015822"
}, {
"place": {
"id": "876737405718973",
"name": "Chipotle Mexican Grill",
"location": {
"city": "Baltimore",
"country": "United States",
"latitude": 39.2866707,
"longitude": -76.6196671,
"state": "MD",
"street": "300 W Pratt St",
"zip": "21201"
}
},
"story": "Aadya Extentia was at Chipotle Mexican Grill.",
"id": "1533836476934935_1546360502349199"
}],
"paging": {
"next": "https://graph.facebook.com/v2.5/1533836476934935/feed?fields=place,story&wi…WzlgXDpe8ZCV8kHWcO2aNxlARSpwIZByS9OWkU8VC3nj2E3VoiLkJNpy2ESOI1R7fHIOJQZDZD"
}
}
But it does not return the category of checked-in place. i.e. I want know if it is a restaurant, museum or stadium, etc.
How do I do it?
Thanks.
You can do this using Field Expansion:
/me/feed?with=location&fields=place{name,category},story
Edit: Looks like this is working for API version <= 2.4 only, but not any more with v2.5.
Edit #2: I filed a bug report to ask if this was deliberately removed, or if it is a bug. https://developers.facebook.com/bugs/1550467468600884/
Even though a Place is a Page, I can't successfully retrieve the category field through Field Expansion...
This can be done with a batch request, by using the output of the first query as input for the second query:
curl \
-F 'access_token={USER_ACCESS_TOKEN}' \
-F 'include_headers=false' \
-F 'batch=[{ "method":"GET","name":"get-places","relative_url":"me/feed?with=location&fields=place{id,name,location},story&limit=100", "omit_response_on_success": false },{"method":"GET","relative_url":"?ids={result=get-places:$.data.*.place.id}&fields=id,name,category"}]' \
https://graph.facebook.com
See
https://developers.facebook.com/docs/graph-api/reference/place/
https://developers.facebook.com/docs/graph-api/making-multiple-requests/