prefect, how to trigger prefect flow using python requests - prefect

I really need my external process to trigger a flow to run immediately with some paramaters.
My script:
import sys
import datetime
import uuid
import requests
import json
ep = 'http://127.0.0.1:4200/api/flow_runs/'
headers = {}
headers['accept']= 'application/json'
headers['Content-Type']= 'application/json'
# Get a deployment using the name of the flow and the deployment.
resp=requests.get('http://127.0.0.1:4200/api/deployments/name/create_toko/create_toko', headers=headers)
rDict = resp.json()
print(f'RESPONSE: {rDict}')
pl= {}
pl['name']=f'{sys.argv[1]}-{str(uuid.uuid1())}'
pl['flow_id']=rDict['flow_id']
pl['deployment_id']=rDict['id']
pl['parameters']={'domain':sys.argv[1]}
pl['state']={}
pl['state']['type']='SCHEDULED'
pl['state']['state_details']={}
scheduled_time=datetime.datetime.now()
#scheduled_time = scheduled_time.isoformat()
pl['state']['state_details']['scheduled_time']=str(scheduled_time)
print('PAYLOAD:\n')
print(json.dumps(pl,indent=4))
print('-------\n')
resp = requests.post(ep, json=pl, headers=headers)
rjson = resp.json()
print(f'\nRESPONSE:{json.dumps(rjson, indent=4)}')
print(f'Payload Schedule:{scheduled_time}')
rscheduled=rjson['state']['state_details']['scheduled_time']
print(f'Response. Scheduled:{rscheduled}')
print(f'UTC NOW: {datetime.datetime.utcnow()}')
Script test command :
python ./reqtest.py test08.test
Request body sent by python :
{
"name": "test08.test-bfd82a2a-21cb-11ed-9565-2fb0ca17a3f9",
"flow_id": "8532eff0-d706-4275-a029-f4728208bb07",
"deployment_id": "07e12983-168c-4fbb-a503-bfddce704406",
"parameters": {
"domain": "test08.test"
},
"state": {
"type": "SCHEDULED",
"state_details": {
"scheduled_time": "2022-08-22 10:37:29.904669"
}
}
}
Response of above request:
{
"id": "28b9173c-2462-454f-b7d1-4dfb6089de40",
"created": "2022-08-22T03:37:29.909204+00:00",
"updated": "2022-08-22T03:37:29.921000+00:00",
"name": "test08.test-bfd82a2a-21cb-11ed-9565-2fb0ca17a3f9",
"flow_id": "8532eff0-d706-4275-a029-f4728208bb07",
"state_id": "49d007c2-f4ec-4829-86ac-abab11f2d258",
"deployment_id": "07e12983-168c-4fbb-a503-bfddce704406",
"flow_version": null,
"parameters": {
"domain": "test08.test"
},
"idempotency_key": null,
"context": {},
"empirical_policy": {
"max_retries": 0,
"retry_delay_seconds": 0.0
},
"tags": [],
"parent_task_run_id": null,
"state_type": "SCHEDULED",
"state_name": "Scheduled",
"run_count": 0,
"expected_start_time": "2022-08-22T10:37:29.904669+00:00",
"next_scheduled_start_time": "2022-08-22T10:37:29.904669+00:00",
"start_time": null,
"end_time": null,
"total_run_time": 0.0,
"estimated_run_time": 0.0,
"estimated_start_time_delta": 0.0,
"auto_scheduled": false,
"infrastructure_document_id": null,
"state": {
"id": "49d007c2-f4ec-4829-86ac-abab11f2d258",
"type": "SCHEDULED",
"name": "Scheduled",
"timestamp": "2022-08-22T03:37:29.908984+00:00",
"message": null,
"data": null,
"state_details": {
"flow_run_id": "28b9173c-2462-454f-b7d1-4dfb6089de40",
"task_run_id": null,
"child_flow_run_id": null,
"scheduled_time": "2022-08-22T10:37:29.904669+00:00",
"cache_key": null,
"cache_expiration": null
}
}
}
Flow Runs check using API (via browser)
http://127.0.0.1:4200/api/flow_runs/28b9173c-2462-454f-b7d1-4dfb6089de40
{
"id": "28b9173c-2462-454f-b7d1-4dfb6089de40",
"created": "2022-08-22T03:37:29.909204+00:00",
"updated": "2022-08-22T03:37:29.921000+00:00",
"name": "test08.test-bfd82a2a-21cb-11ed-9565-2fb0ca17a3f9",
"flow_id": "8532eff0-d706-4275-a029-f4728208bb07",
"state_id": "49d007c2-f4ec-4829-86ac-abab11f2d258",
"deployment_id": "07e12983-168c-4fbb-a503-bfddce704406",
"flow_version": null,
"parameters": {
"domain": "test08.test"
},
"idempotency_key": null,
"context": {},
"empirical_policy": {
"max_retries": 0,
"retry_delay_seconds": 0.0
},
"tags": [],
"parent_task_run_id": null,
"state_type": "SCHEDULED",
"state_name": "Scheduled",
"run_count": 0,
"expected_start_time": "2022-08-22T10:37:29.904669+00:00",
"next_scheduled_start_time": "2022-08-22T10:37:29.904669+00:00",
"start_time": null,
"end_time": null,
"total_run_time": 0.0,
"estimated_run_time": 0.0,
"estimated_start_time_delta": 0.0,
"auto_scheduled": false,
"infrastructure_document_id": null,
"state": {
"id": "49d007c2-f4ec-4829-86ac-abab11f2d258",
"type": "SCHEDULED",
"name": "Scheduled",
"timestamp": "2022-08-22T03:37:29.908984+00:00",
"message": null,
"data": null,
"state_details": {
"flow_run_id": "28b9173c-2462-454f-b7d1-4dfb6089de40",
"task_run_id": null,
"child_flow_run_id": null,
"scheduled_time": "2022-08-22T10:37:29.904669+00:00",
"cache_key": null,
"cache_expiration": null
}
}
}
http://127.0.0.1:4200/api/deployments/07e12983-168c-4fbb-a503-bfddce704406 give me:
{
"id": "07e12983-168c-4fbb-a503-bfddce704406",
"created": "2022-08-20T01:59:36.144207+00:00",
"updated": "2022-08-20T01:59:36.141261+00:00",
"name": "create_toko",
"version": "b419c81a5b4060fc3605ced026a18289",
"description": null,
"flow_id": "8532eff0-d706-4275-a029-f4728208bb07",
"schedule": null,
"is_schedule_active": true,
"infra_overrides": {},
"parameters": {},
"tags": ["semua"],
"parameter_openapi_schema": {
"title": "Parameters",
"type": "object",
"properties": {
"domain": {
"title": "domain",
"default": "namatoko.namadomain.com",
"type": "string"
},
"cpu": {
"title": "cpu",
"default": 1,
"type": "number"
},
"ram": {
"title": "ram",
"default": 1,
"type": "number"
},
"dbsize": {
"title": "dbsize",
"default": 1,
"type": "number"
},
"uploadssize": {
"title": "uploadssize",
"default": 1,
"type": "number"
}
}
},
"path": "/home/bino/gitjece/jece/prefect",
"entrypoint": "flows/create_toko.py:create_toko",
"manifest_path": null,
"storage_document_id": null,
"infrastructure_document_id": "6a0cd762-6c28-4854-a996-2a48700058e7"
}
and I run my agent with : prefect agent start --api http://127.0.0.1:4200/api -t semua
Here is my flow script
from prefect import flow
#flow(name='create_toko')
def create_toko(domain: str = 'namatoko.namadomain.com',
cpu: float = 1,
ram: float = 1,
dbsize: float = 1,
uploadssize: float = 1) -> str:
print(locals())
But, My agent never run that flow.
Never got anything from server
Kindly please tell me how to do it properly
Note: My system timezone is GMT+7
Sincerely
-bino-

Related

#pnp/sp list request returns different objects on SharePoint Site view/edit mode

I use the #pnp/sp library to get list data in a SPFX web part.
The crucial code for my issue looks as follows:
const list = await sp.web.lists
.getByTitle("ListTitle")
.fields.getByTitle("Category")
.get();
return list.Choices.results;
When I open the SharePoint page, where the web part is located, in view mode, it loads the correct object:
{
"__metadata": {
"id": "...",
"uri": "...",
"type": "SP.FieldChoice"
},
"DescriptionResource": {
"__deferred": {
"uri": "..."
}
},
"TitleResource": {
"__deferred": {
"uri": "..."
}
},
"AutoIndexed": false,
"CanBeDeleted": true,
"ClientSideComponentId": "00000000-0000-0000-0000-000000000000",
"ClientSideComponentProperties": null,
"ClientValidationFormula": null,
"ClientValidationMessage": null,
"CustomFormatter": null,
"DefaultFormula": null,
"DefaultValue": "SocialEvent",
"Description": "",
"Direction": "none",
"EnforceUniqueValues": false,
"EntityPropertyName": "...",
"Filterable": true,
"FromBaseType": false,
"Group": "Benutzerdefinierte Spalten",
"Hidden": false,
"Id": "...",
"Indexed": false,
"IndexStatus": 0,
"InternalName": "...",
"IsModern": false,
"JSLink": "clienttemplates.js",
"PinnedToFiltersPane": false,
"ReadOnlyField": false,
"Required": true,
"SchemaXml": "<Field Type=\"Choice\" DisplayName=\"Category\" Required=\"TRUE\" EnforceUniqueValues=\"FALSE\" Indexed=\"FALSE\" Format=\"Dropdown\" FillInChoice=\"FALSE\" ID=\"{...}\" SourceID=\"{{listid:...}}\" StaticName=\"...\" Name=\"...\" ColName=\"nvarchar4\" RowOrdinal=\"0\" CustomFormatter=\"\" Version=\"2\"><Default>SocialEvent</Default><CHOICES><CHOICE>SocialEvent</CHOICE><CHOICE>Schulung</CHOICE><CHOICE>Fachbesprechung</CHOICE><CHOICE>Messe</CHOICE></CHOICES></Field>",
"Scope": "/sites/.../Lists/...",
"Sealed": false,
"ShowInFiltersPane": 0,
"Sortable": true,
"StaticName": "...",
"Title": "Category",
"FieldTypeKind": 6,
"TypeAsString": "Choice",
"TypeDisplayName": "Auswahl",
"TypeShortDescription": "Auswahl (Menü)",
"ValidationFormula": null,
"ValidationMessage": null,
"FillInChoice": false,
"Mappings": null,
"Choices": {
"__metadata": {
"type": "Collection(Edm.String)"
},
"results": [
"SocialEvent",
"Schulung",
"Fachbesprechung",
"Messe"
]
},
"EditFormat": 0
}
But when I change the mode to edit, the same code gives me the following result (I shortened it, because the result is 10.000+ lines):
{
"user": {
"#odata.context": "...",
"#odata.type": "#SP.User",
"#odata.id": "...",
"#odata.editLink": "Web/GetUserById(17)",
"Id": 17,
"IsHiddenInUI": false,
"LoginName": "...",
"Title": "...",
"PrincipalType": 1,
"Email": "...",
"Expiration": "",
"IsEmailAuthenticationGuestUser": false,
"IsShareByEmailGuestUser": false,
"IsSiteAdmin": true,
"UserId": {
"NameId": "...",
"NameIdIssuer": "urn:federation:microsoftonline"
},
"UserPrincipalName": "..."
},
"item": {
"#odata.context": "...",
"#odata.type": "#SP.Data.SitePagesItem",
"#odata.id": "...",
"#odata.etag": "\"363\"",
"#odata.editLink": "...",
"FileSystemObjectType": 0,
"Id": 1,
"ContentTypeId": "...",
"OData__ModerationComments": null,
"ComplianceAssetId": null,
"Title": "Homepage",
"PageLayoutType": "Home",
"BannerImageUrl": {
"Description": "...",
"Url": "..."
},
"Description": "...",
"PromotedState": 0,
"FirstPublishedDate": null,
"LayoutWebpartsContent": null,
"OData__AuthorBylineId": null,
"OData__TopicHeader": null,
"OData__SPSitePageFlags": null,
"OData__SPCallToAction": null,
"OData__OriginalSourceUrl": null,
"OData__OriginalSourceSiteId": null,
"OData__OriginalSourceWebId": null,
"OData__OriginalSourceListId": null,
"OData__OriginalSourceItemId": null,
"ID": 1,
"Created": "2022-07-30T16:11:23-07:00",
"AuthorId": 0,
"Modified": "2022-09-28T00:45:46-07:00",
"EditorId": 0,
"OData__ModerationStatus": 3,
"CheckoutUserId": 0,
"UniqueId": "...",
"owshiddenversion": 363,
"OData__UIVersionString": "41.5",
"GUID": "..."
},
"itemProperties": {}
...
}
The following versions are installed:
"#pnp/common": "1.3.9",
"#pnp/logging": "1.3.9",
"#pnp/odata": "1.3.9",
"#pnp/sp": "1.3.9",
Update:
I installed the web part in different site collections within the tenant, which resulted in the same error. Now I have installed the web part in another tenant, where the problem don't occur. Unfortunately, I still cannot determine where the error is.

Need to get data from fixture JSON

I am struggling hard since yesterday getting the data from JSON, I don't understand why the fixture is not accessible. When I tried to get the ID, it gives me an error saying id isn't defined.
This gives me an error saying ID is not defined:
res.send(data.response["fixture"].id)
This code returns nothing:
res.send(data.response.fixture);
This code gives me the JSON data:
res.send(data.response
My JSON data:
// 20220714200426
// http://localhost:9090/
[
{
"fixture": {
"id": 822924,
"referee": "Jhon Alexander Hinestroza Romana, Colombia",
"timezone": "UTC",
"date": "2022-07-15T01:10:00+00:00",
"timestamp": 1657847400,
"periods": {
"first": 1657847400,
"second": 1657851000
},
"venue": {
"id": 375,
"name": "Estadio Manuel Murillo Toro",
"city": "Ibagué"
},
"status": {
"long": "Second Half",
"short": "2H",
"elapsed": 90
}
},
"league": {
"id": 239,
"name": "Primera A",
"country": "Colombia",
"logo": "https://media.api-sports.io/football/leagues/239.png",
"flag": "https://media.api-sports.io/flags/co.svg",
"season": 2022,
"round": "Clausura - 2"
},
"teams": {
"home": {
"id": 1142,
"name": "Deportes Tolima",
"logo": "https://media.api-sports.io/football/teams/1142.png",
"winner": true
},
"away": {
"id": 1127,
"name": "Deportivo Cali",
"logo": "https://media.api-sports.io/football/teams/1127.png",
"winner": false
}
},
"goals": {
"home": 2,
"away": 0
},
"score": {
"halftime": {
"home": 0,
"away": 0
},
"fulltime": {
"home": null,
"away": null
},
"extratime": {
"home": null,
"away": null
},
"penalty": {
"home": null,
"away": null
}
},
"events": [
{
"time": {
"elapsed": 1,
"extra": null
},
"team": {
"id": 1127,
"name": "Deportivo Cali",
"logo": "https://media.api-sports.io/football/teams/1127.png"
},
"player": {
"id": 13398,
"name": "Y. Congo"
},
"assist": {
"id": null,
"name": null
},
"type": "Card",
"detail": "Yellow Card",
"comments": null
},
{
"time": {
"elapsed": 26,
"extra": null
},
"team": {
"id": 1127,
"name": "Deportivo Cali",
"logo": "https://media.api-sports.io/football/teams/1127.png"
},
"player": {
"id": 13592,
"name": "T. Gutierrez"
},
"assist": {
"id": null,
"name": null
},
"type": "Card",
"detail": "Yellow Card",
"comments": null
},
{
"time": {
"elapsed": 27,
"extra": null
},
"team": {
"id": 1142,
"name": "Deportes Tolima",
"logo": "https://media.api-sports.io/football/teams/1142.png"
},
"player": {
"id": 13304,
"name": "B. Rovira"
},
"assist": {
"id": null,
"name": null
},
"type": "Card",
"detail": "Yellow Card",
"comments": null
},
{
"time": {
"elapsed": 40,
"extra": null
},
"team": {
"id": 1127,
"name": "Deportivo Cali",
"logo": "https://media.api-sports.io/football/teams/1127.png"
},
"player": {
"id": 13592,
"name": "T. Gutierrez"
},
"assist": {
"id": null,
"name": null
},
"type": "Card",
"detail": "Red Card",
"comments": null
},
{
"time": {
"elapsed": 56,
"extra": null
},
"team": {
"id": 1127,
"name": "Deportivo Cali",
"logo": "https://media.api-sports.io/football/teams/1127.png"
},
"player": {
"id": null,
"name": "O. Acosta"
},
"assist": {
"id": null,
"name": null
},
"type": "Card",
"detail": "Yellow Card",
"comments": null
},
{
"time": {
"elapsed": 59,
"extra": null
},
"team": {
"id": 1142,
"name": "Deportes Tolima",
"logo": "https://media.api-sports.io/football/teams/1142.png"
},
"player": {
"id": 283830,
"name": "L. Riascos"
},
"assist": {
"id": null,
"name": null
},
"type": "Card",
"detail": "Yellow Card",
"comments": null
},
{
"time": {
"elapsed": 61,
"extra": null
},
"team": {
"id": 1142,
"name": "Deportes Tolima",
"logo": "https://media.api-sports.io/football/teams/1142.png"
},
"player": {
"id": 13348,
"name": "L. Miranda"
},
"assist": {
"id": null,
"name": null
},
"type": "Var",
"detail": "Goal Disallowed - offside",
"comments": null
},
{
"time": {
"elapsed": 64,
"extra": null
},
"team": {
"id": 1127,
"name": "Deportivo Cali",
"logo": "https://media.api-sports.io/football/teams/1127.png"
},
"player": {
"id": 10328,
"name": "Y. Gonzalez"
},
"assist": {
"id": null,
"name": "O. Acosta"
},
"type": "subst",
"detail": "Substitution 1",
"comments": null
},
{
"time": {
"elapsed": 66,
"extra": null
},
"team": {
"id": 1142,
"name": "Deportes Tolima",
"logo": "https://media.api-sports.io/football/teams/1142.png"
},
"player": {
"id": 6632,
"name": "A. Renteria"
},
"assist": {
"id": 13348,
"name": "L. Miranda"
},
"type": "subst",
"detail": "Substitution 1",
"comments": null
},
{
"time": {
"elapsed": 69,
"extra": null
},
"team": {
"id": 1142,
"name": "Deportes Tolima",
"logo": "https://media.api-sports.io/football/teams/1142.png"
},
"player": {
"id": 13596,
"name": "M. Rangel"
},
"assist": {
"id": 13298,
"name": "J. Lucumi"
},
"type": "Goal",
"detail": "Normal Goal",
"comments": null
},
{
"time": {
"elapsed": 70,
"extra": null
},
"team": {
"id": 1127,
"name": "Deportivo Cali",
"logo": "https://media.api-sports.io/football/teams/1127.png"
},
"player": {
"id": 59887,
"name": "A. Gutierrez"
},
"assist": {
"id": null,
"name": null
},
"type": "Card",
"detail": "Yellow Card",
"comments": null
},
{
"time": {
"elapsed": 72,
"extra": null
},
"team": {
"id": 1142,
"name": "Deportes Tolima",
"logo": "https://media.api-sports.io/football/teams/1142.png"
},
"player": {
"id": 13298,
"name": "J. Lucumi"
},
"assist": {
"id": 6632,
"name": "A. Renteria"
},
"type": "Goal",
"detail": "Normal Goal",
"comments": null
},
{
"time": {
"elapsed": 78,
"extra": null
},
"team": {
"id": 1127,
"name": "Deportivo Cali",
"logo": "https://media.api-sports.io/football/teams/1127.png"
},
"player": {
"id": 31691,
"name": "A. Vuletich"
},
"assist": {
"id": 51135,
"name": "H. Mosquera"
},
"type": "subst",
"detail": "Substitution 2",
"comments": null
},
{
"time": {
"elapsed": 78,
"extra": null
},
"team": {
"id": 1127,
"name": "Deportivo Cali",
"logo": "https://media.api-sports.io/football/teams/1127.png"
},
"player": {
"id": 200150,
"name": "J. C. Caldera Alvis"
},
"assist": {
"id": 51165,
"name": "A. Rodriguez"
},
"type": "subst",
"detail": "Substitution 3",
"comments": null
},
{
"time": {
"elapsed": 82,
"extra": null
},
"team": {
"id": 1127,
"name": "Deportivo Cali",
"logo": "https://media.api-sports.io/football/teams/1127.png"
},
"player": {
"id": 200150,
"name": "J. C. Caldera Alvis"
},
"assist": {
"id": null,
"name": null
},
"type": "Card",
"detail": "Yellow Card",
"comments": null
},
{
"time": {
"elapsed": 84,
"extra": null
},
"team": {
"id": 1142,
"name": "Deportes Tolima",
"logo": "https://media.api-sports.io/football/teams/1142.png"
},
"player": {
"id": 59758,
"name": "A. Melendez"
},
"assist": {
"id": 35757,
"name": "Y. Orozco"
},
"type": "subst",
"detail": "Substitution 2",
"comments": null
}
]
},
{
"fixture": {
"id": 896998,
"referee": null,
"timezone": "UTC",
"date": "2022-07-15T02:00:00+00:00",
"timestamp": 1657850400,
"periods": {
"first": 1657850400,
"second": 1657854000
},
"venue": {
"id": 1087,
"name": "Estadio Universitario de Nuevo León",
"city": "San Nicolás de los Garza"
},
"status": {
"long": "Second Half",
"short": "2H",
"elapsed": 46
}
},
"league": {
"id": 927,
"name": "World Cup - Women - Qualification Concacaf",
"country": "World",
"logo": "https://media.api-sports.io/football/leagues/927.png",
"flag": null,
"season": 2022,
"round": "Semi-finals"
},
"teams": {
"home": {
"id": 1717,
"name": "Canada W",
"logo": "https://media.api-sports.io/football/teams/1717.png",
"winner": true
},
"away": {
"id": 1785,
"name": "Jamaica W",
"logo": "https://media.api-sports.io/football/teams/1785.png",
"winner": false
}
},
"goals": {
"home": 1,
"away": 0
},
"score": {
"halftime": {
"home": 1,
"away": 0
},
"fulltime": {
"home": null,
"away": null
},
"extratime": {
"home": null,
"away": null
},
"penalty": {
"home": null,
"away": null
}
},
"events": [
{
"time": {
"elapsed": 10,
"extra": null
},
"team": {
"id": 1785,
"name": "Jamaica W",
"logo": "https://media.api-sports.io/football/teams/1785.png"
},
"player": {
"id": null,
"name": "C. Swaby"
},
"assist": {
"id": null,
"name": "J. C. Pelaia-Hylton"
},
"type": "subst",
"detail": "Substitution 1",
"comments": null
},
{
"time": {
"elapsed": 18,
"extra": null
},
"team": {
"id": 1717,
"name": "Canada W",
"logo": "https://media.api-sports.io/football/teams/1717.png"
},
"player": {
"id": null,
"name": "J. Fleming"
},
"assist": {
"id": null,
"name": null
},
"type": "Goal",
"detail": "Normal Goal",
"comments": null
}
]
},
{
"fixture": {
"id": 868553,
"referee": null,
"timezone": "UTC",
"date": "2022-07-15T02:05:00+00:00",
"timestamp": 1657850700,
"periods": {
"first": 1657850700,
"second": null
},
"venue": {
"id": 1844,
"name": "Estadio Olímpico Carlos Iturralde Rivero",
"city": "Mérida"
},
"status": {
"long": "Halftime",
"short": "HT",
"elapsed": 45
}
},
"league": {
"id": 263,
"name": "Ascenso MX",
"country": "Mexico",
"logo": "https://media.api-sports.io/football/leagues/263.png",
"flag": "https://media.api-sports.io/flags/mx.svg",
"season": 2022,
"round": "Apertura - 3"
},
"teams": {
"home": {
"id": 2311,
"name": "Venados FC",
"logo": "https://media.api-sports.io/football/teams/2311.png",
"winner": true
},
"away": {
"id": 2308,
"name": "Celaya",
"logo": "https://media.api-sports.io/football/teams/2308.png",
"winner": false
}
},
"goals": {
"home": 2,
"away": 1
},
"score": {
"halftime": {
"home": 2,
"away": 1
},
"fulltime": {
"home": null,
"away": null
},
"extratime": {
"home": null,
"away": null
},
"penalty": {
"home": null,
"away": null
}
},
"events": [
{
"time": {
"elapsed": 11,
"extra": null
},
"team": {
"id": 2308,
"name": "Celaya",
"logo": "https://media.api-sports.io/football/teams/2308.png"
},
"player": {
"id": null,
"name": "D. Gonzalez"
},
"assist": {
"id": null,
"name": null
},
"type": "Goal",
"detail": "Normal Goal",
"comments": null
},
{
"time": {
"elapsed": 17,
"extra": null
},
"team": {
"id": 2311,
"name": "Venados FC",
"logo": "https://media.api-sports.io/football/teams/2311.png"
},
"player": {
"id": null,
"name": "M. Perez"
},
"assist": {
"id": null,
"name": null
},
"type": "Goal",
"detail": "Normal Goal",
"comments": null
},
{
"time": {
"elapsed": 36,
"extra": null
},
"team": {
"id": 2311,
"name": "Venados FC",
"logo": "https://media.api-sports.io/football/teams/2311.png"
},
"player": {
"id": 36091,
"name": "M. Perez"
},
"assist": {
"id": null,
"name": null
},
"type": "Goal",
"detail": "Normal Goal",
"comments": null
}
]
}
]
My Node.js code:
const express = require('express');
const Router = express.Router();//router will be used now to route
require('dotenv').config();
const fetch = require('cross-fetch');
const axios = require('axios');
const request = require('request');
const endpoint = 'fixtures';
Router.get('/', (req, res) => {
var options = {
method: 'GET',
url: `https://v3.football.api-sports.io/${endpoint}`,
qs: {live: 'all'},
headers: {
'x-rapidapi-host': 'v3.football.api-sports.io',
'x-rapidapi-key': `${process.env.API_KEY}`
}
};
request(options, function (error, resp, body) {
if (error) throw new Error(error);
const data = JSON.parse(body);
res.send(data.response);
});
})
module.exports = Router;
What I want is to access fixture ID and all other keys as well but I am not able to reach the fixture. Can anyone able to guide me on what's wrong I am doing?
From the json data response body above, data.response is an array of objects of multiple fixtures. So, data.response.fixture would always return undefined. To access a particular fixture, depending on what you want to do to with, you'd have to access the index of the response first. As such:
console.log(data.response[0].fixture)
this should return:
"fixture": {
"id": 822924,
"referee": "Jhon Alexander Hinestroza Romana, Colombia",
"timezone": "UTC",
"date": "2022-07-15T01:10:00+00:00",
"timestamp": 1657847400,
"periods": {
"first": 1657847400,
"second": 1657851000
},
"venue": {
"id": 375,
"name": "Estadio Manuel Murillo Toro",
"city": "Ibagué"
},
"status": {
"long": "Second Half",
"short": "2H",
"elapsed": 90
}
}
To access its id:
console.log(data.response[0].fixture.id)
The important thing is to access the properties through the array index of the element you want.

How do one should set a custom agent pool in DevOps release definition?

I create release definitions using DevOps REST APIs. Due to lack of documentation I used to capture HTTP requests and examine JSON payload.
I'm able to set a release using Azure agent pools. It follows only the relevant node:
"deploymentInput": {
"parallelExecution": {
"parallelExecutionType": 0
},
"agentSpecification": {
"identifier": "windows-2019"
},
"skipArtifactsDownload": false,
"artifactsDownloadInput": {},
"queueId": 749,
"demands": [],
"enableAccessToken": false,
"timeoutInMinutes": 0,
"jobCancelTimeoutInMinutes": 1,
"condition": "succeeded()",
"overrideInputs": {},
"dependencies": []
}
I want to set a custom defined agent pool, but if I try to capture the request I still can't undertand how to set it. This is the full JSON of an empty release with custom agent set:
{
"id": 0,
"name": "New release pipeline",
"source": 2,
"comment": "",
"createdOn": "2020-10-31T10:02:19.034Z",
"createdBy": null,
"modifiedBy": null,
"modifiedOn": "2020-10-31T10:02:19.034Z",
"environments": [
{
"id": -1,
"name": "Stage 1",
"rank": 1,
"variables": {},
"variableGroups": [],
"preDeployApprovals": {
"approvals": [
{
"rank": 1,
"isAutomated": true,
"isNotificationOn": false,
"id": 0
}
],
"approvalOptions": {
"executionOrder": 1
}
},
"deployStep": {
"tasks": [],
"id": 0
},
"postDeployApprovals": {
"approvals": [
{
"rank": 1,
"isAutomated": true,
"isNotificationOn": false,
"id": 0
}
],
"approvalOptions": {
"executionOrder": 2
}
},
"deployPhases": [
{
"deploymentInput": {
"parallelExecution": {
"parallelExecutionType": 0
},
"agentSpecification": null,
"skipArtifactsDownload": false,
"artifactsDownloadInput": {},
"queueId": 1039,
"demands": [],
"enableAccessToken": false,
"timeoutInMinutes": 0,
"jobCancelTimeoutInMinutes": 1,
"condition": "succeeded()",
"overrideInputs": {},
"dependencies": []
},
"rank": 1,
"phaseType": 1,
"name": "Agent job",
"refName": null,
"workflowTasks": [],
"phaseInputs": {
"phaseinput_artifactdownloadinput": {
"artifactsDownloadInput": {},
"skipArtifactsDownload": false
}
}
}
],
"runOptions": {},
"environmentOptions": {
"emailNotificationType": "OnlyOnFailure",
"emailRecipients": "release.environment.owner;release.creator",
"skipArtifactsDownload": false,
"timeoutInMinutes": 0,
"enableAccessToken": false,
"publishDeploymentStatus": true,
"badgeEnabled": false,
"autoLinkWorkItems": false,
"pullRequestDeploymentEnabled": false
},
"demands": [],
"conditions": [
{
"conditionType": 1,
"name": "ReleaseStarted",
"value": ""
}
],
"executionPolicy": {
"concurrencyCount": 1,
"queueDepthCount": 0
},
"schedules": [],
"properties": {
"LinkBoardsWorkItems": false,
"BoardsEnvironmentType": "unmapped"
},
"preDeploymentGates": {
"id": 0,
"gatesOptions": null,
"gates": []
},
"postDeploymentGates": {
"id": 0,
"gatesOptions": null,
"gates": []
},
"environmentTriggers": [],
"owner": {
"displayName": "Giacomo Stelluti Scala",
"id": "3617734a-1751-66f2-8343-c71c1398b5e6",
"isAadIdentity": true,
"isContainer": false,
"uniqueName": "giacomo.stelluti#dev4side.com",
"url": "https://dev.azure.com/dev4side/"
},
"retentionPolicy": {
"daysToKeep": 30,
"releasesToKeep": 3,
"retainBuild": true
},
"processParameters": {}
}
],
"artifacts": [],
"variables": {},
"variableGroups": [],
"triggers": [],
"lastRelease": null,
"tags": [],
"path": "\\test-poc",
"properties": {
"DefinitionCreationSource": "ReleaseNew",
"IntegrateJiraWorkItems": "false",
"IntegrateBoardsWorkItems": false
},
"releaseNameFormat": "Release-$(rev:r)",
"description": ""
}
Where do this is agent is set? Anyone knows how to do it properly?
Any help really appreciated.
Giacomo S. S.
I've found the solution in this question.
"deploymentInput": {
"parallelExecution": {
"parallelExecutionType": 0
},
"agentSpecification": null,
"skipArtifactsDownload": false,
"artifactsDownloadInput": {},
"queueId": 1039,
"demands": [],
"enableAccessToken": false,
"timeoutInMinutes": 0,
"jobCancelTimeoutInMinutes": 1,
"condition": "succeeded()",
"overrideInputs": {},
"dependencies": []
}
agentSpecification must be null and queueId must be set.

convert json schema to avro schema in python

I want to convert json schema to avro schema using python because I'm building my microservice in Python Fastapi.
json-schema
{
"type":"object",
"properties":{
"IsNonPO":{
"title":"IsNonPO",
"type":[
"boolean",
"null"
],
"precision":null,
"scale":null,
"size":null,
"allowedValues":null
},
"ApprovedState":{
"title":"ApprovedState",
"type":[
"number",
"null"
],
"precision":null,
"scale":null,
"size":null,
"allowedValues":[
{
"key":"8",
"value":"Invalid"
},
{
"key":"1",
"value":"Composing"
},
{
"key":"2",
"value":"Submitted"
},
{
"key":"4",
"value":"Approved"
},
{
"key":"16",
"value":"Denied"
}
]
},
"CreateDate":{
"title":"CreateDate",
"type":[
"string",
"null"
],
"precision":null,
"scale":null,
"size":null,
"allowedValues":null,
"format":"date-time"
},
"RemitToAddress": {
"type": ["object", "null"],
"properties": {
"State": {
"title": "RemitToAddress.State",
"type": ["string", "null"],
"precision": null,
"scale": null,
"size": 50,
"allowedValues": null
},
"Phone": {
"title": "RemitToAddress.Phone",
"type": ["string", "null"],
"precision": null,
"scale": null,
"size": 70,
"allowedValues": null
},
"Country": {
"type": ["object", "null"],
"properties": {
"UniqueName": {
"title": "RemitToAddress.Country.UniqueName",
"type": ["string", "null"],
"precision": null,
"scale": null,
"size": 50,
"allowedValues": null
}
}
},
"PostalCode": {
"title": "RemitToAddress.PostalCode",
"type": ["string", "null"],
"precision": null,
"scale": null,
"size": 50,
"allowedValues": null
},
"City": {
"title": "RemitToAddress.City",
"type": ["string", "null"],
"precision": null,
"scale": null,
"size": 50,
"allowedValues": null
},
"Fax": {
"title": "RemitToAddress.Fax",
"type": ["string", "null"],
"precision": null,
"scale": null,
"size": 70,
"allowedValues": null
},
"UniqueName": {
"title": "RemitToAddress.UniqueName",
"type": ["string", "null"],
"precision": null,
"scale": null,
"size": 50,
"allowedValues": null
},
"Lines": {
"title": "RemitToAddress.Lines",
"type": ["string", "null"],
"precision": null,
"scale": null,
"size": 1024,
"allowedValues": null
},
"Name": {
"title": "RemitToAddress.Name",
"type": ["string", "null"],
"precision": null,
"scale": null,
"size": 128,
"allowedValues": null
}
}
}
}
}
Avro schema
{
"type":"record",
"name":"invoice",
"namespace":"com.xyz.com",
"fields":[
{
"name":"IsNonPO",
"type":[
"null",
"boolean"
]
},
{
"name":"ApprovedState",
"type":[
"null",
"long"
]
},
{
"name":"CreateDate",
"type":[
"null",
{
"type":"string",
"logicalType":"timestamp-micros"
}
]
},
{
"name":"RemitToAddress",
"type":[
{
"type":"record",
"name":"RemitToAddress",
"namespace":"com.xyz.com.invoice",
"fields":[
{
"name":"City",
"type":[
"null",
"string"
]
},
{
"name":"Country",
"type":[
{
"type":"record",
"name":"Country",
"namespace":"com.xyz.com.invoice.RemitToAddress",
"fields":[
{
"name":"UniqueName",
"type":[
"null",
"string"
]
}
]
},
"null"
]
},
{
"name":"Fax",
"type":[
"null",
"string"
]
},
{
"name":"Lines",
"type":[
"null",
"string"
]
},
{
"name":"Name",
"type":[
"null",
"string"
]
},
{
"name":"Phone",
"type":[
"null",
"string"
]
},
{
"name":"PostalCode",
"type":[
"null",
"string"
]
},
{
"name":"State",
"type":[
"null",
"string"
]
},
{
"name":"UniqueName",
"type":[
"null",
"string"
]
}
]
},
"null"
]
}
]
}
I tried to find the converter in python but I can't. I found a converter but does it in java. Please let me know if there are any Python converter exists or do I write of my own library?

How to update a subscription (adding a pricing plan) by Stripe in Node.js?

I'm building a web app which sells several products, each product corresponds to a pricing plan. All the payment system is managed by Stripe.
It happens very often that a user has a subscription that contains Product A (i.e., one pricing plan), and then he wants to add Product B (i.e., another pricing plan) to the same subscription. I want to know how to achieve this by APIs of Stripe.
There is a webpage of Stripe to update a subscription (e.g., https://dashboard.stripe.com/test/subscriptions/sub_H4pQGW8nnc80vF/edit where sub_H4pQGW8nnc80vF is the subscription ID). Let's assume this customer already has 1 Verificator in the subscription, and then he wants to add 1 Pretty Formula to the same subscription. I do this update via the website. Here is the log:
Here is the full Request POST body:
{
"items": {
"0": {
"billing_thresholds": "",
"deleted": "false",
"id": "si_H4pQal4ZxGzLbW",
"quantity": "1",
"tax_rates": ""
},
"1": {
"billing_thresholds": "",
"plan": "plan_Gz6i9yPVIjrDPX",
"deleted": "false",
"quantity": "1"
}
},
"off_session": "true",
"prorate": "true",
"cancel_at": "",
"days_until_due": "30",
"default_tax_rates": "",
"collection_method": "send_invoice",
"billing_thresholds": "",
"enable_incomplete_payments": "false",
"invoice_settings": {
"description": "",
"send_hosted_payment_email": "true",
"supported_payment_methods": {
"ach_credit_transfer": "false",
"au_becs_debit": "false",
"bancontact": "false",
"card": "true",
"fpx": "false",
"giropay": "false",
"ideal": "false",
"jp_credit_transfer": "false",
"paper_check": "false",
"sepa_credit_transfer": "false",
"sofort": "false"
},
"custom_fields": "",
"footer": ""
},
"default_payment_method": "",
"default_source": ""
}
Here is the full Response body:
{
"id": "sub_H4pQGW8nnc80vF",
"object": "subscription",
"application_fee_percent": null,
"billing_cycle_anchor": 1586597833,
"billing_thresholds": null,
"cancel_at": null,
"cancel_at_period_end": false,
"canceled_at": null,
"collection_method": "send_invoice",
"created": 1586597833,
"current_period_end": 1589189833,
"current_period_start": 1586597833,
"customer": "5e575130651c5721d808d25b",
"customer_email": "sdtikply#gmail.com",
"customer_name": "Thomas Joseph",
"days_until_due": 30,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [
],
"discount": null,
"ended_at": null,
"invoice_settings": {
"send_hosted_payment_email": true,
"supported_payment_methods": {
"ach_credit_transfer": false,
"au_becs_debit": false,
"bancontact": false,
"card": true,
"fpx": false,
"giropay": false,
"ideal": false,
"jp_credit_transfer": false,
"paper_check": false,
"sepa_credit_transfer": false,
"sofort": false
}
},
"items": {
"object": "list",
"data": [
{
"id": "si_H4pQal4ZxGzLbW",
"object": "subscription_item",
"billing_thresholds": null,
"created": 1586597833,
"metadata": {
},
"plan": {
"id": "plan_Ga6n9yMYCDnHCu",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 500,
"amount_decimal": "500",
"billing_scheme": "per_unit",
"created": 1579512574,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"name": "Verificator",
"nickname": "Verificator",
"owning_merchant": "acct_1CiOQBEV4K2GahYL",
"owning_merchant_info": "acct_1CiOQBEV4K2GahYL",
"product": "prod_Ga6mVdA8KXyZ8I",
"tiers": null,
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"quantity": 1,
"subscription": "sub_H4pQGW8nnc80vF",
"tax_rates": [
]
},
{
"id": "si_H82ES9BdIKZCNG",
"object": "subscription_item",
"billing_thresholds": null,
"created": 1587337381,
"metadata": {
},
"plan": {
"id": "plan_Gz6i9yPVIjrDPX",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 500,
"amount_decimal": "500",
"billing_scheme": "per_unit",
"created": 1585278262,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"name": "Pretty Formula",
"nickname": "Pretty Formula",
"owning_merchant": "acct_1CiOQBEV4K2GahYL",
"owning_merchant_info": "acct_1CiOQBEV4K2GahYL",
"product": "prod_GxqkRFdI08DvyR",
"tiers": null,
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"quantity": 1,
"subscription": "sub_H4pQGW8nnc80vF",
"tax_rates": [
]
}
],
"has_more": false,
"total_count": 2,
"url": "/v1/subscription_items?subscription=sub_H4pQGW8nnc80vF"
},
"latest_invoice": "in_1GWfm1EV4K2GahYLlmtUEISo",
"livemode": false,
"metadata": {
},
"next_pending_invoice_item_invoice": null,
"owning_merchant": "acct_1CiOQBEV4K2GahYL",
"owning_merchant_info": "acct_1CiOQBEV4K2GahYL",
"pause_collection": null,
"pending_invoice_item_interval": null,
"pending_setup_intent": null,
"pending_update": null,
"plan": null,
"quantity": null,
"schedule": null,
"start_date": 1586597833,
"status": "active",
"tax_percent": null,
"trial_end": null,
"trial_start": null
}
So my question is, how can I code in my backend (Node.js) to achieve exactly the same thing?
You just need to use the Update Subscription API and provide the items portion just as you're seeing above:
"items": {
"0": {
"billing_thresholds": "",
"deleted": "false",
"id": "si_H4pQal4ZxGzLbW",
"quantity": "1",
"tax_rates": ""
},
"1": {
"billing_thresholds": "",
"plan": "plan_Gz6i9yPVIjrDPX",
"deleted": "false",
"quantity": "1"
}
},
The first item is the existing Subscription Item (si_), and the second one is the new one you want to add.

Resources