Google Recommendations AI sample rest request - google-cloud-ml

I am trying to build a simple recommendation engine using Google Recommendations AI and referring their official documentation. currently I have build a simple curl request and whenever I execute it i get different errors, but all the time error code is 404,i have given sample curl request i have sent
DATA='{
"id": "1234",
"category_hierarchies": [ { "categories": [ "athletic wear", "shoes" ] } ],
"title": "ABC sneakers",
"description": "Sneakers for the rest of us",
"language_code": "en",
"tags": [ ],
"product_metadata": {
"exact_price": {
"display_price": 99.98,
"original_price": 111.99 },
"costs": {
"manufacturing": 35.99,
"other": 20
},
"currency_code": "USD",
"canonical_product_uri": "https://www.example.com/products/1234",
"images": [ ]
}
}'
curl -X POST \
-H "Authorization: Bearer access toke is given here" \
-H "Content-Type: application/json; charset=utf-8" \
-d "${DATA}" \
"https://recommendationengine.googleapis.com/v1beta1/projects/[PROJECT_ID]/locations/global/catalogs/default_catalog/catalogItems:import"
Many times i get as string lent is not specified or sometimes blank 404 error message, Any elp would be appreciated.
Thank you

Related

WSO2 APIM: Calling service APIs through cURL gives no response

I'm using APIM 4.1.0. I am following this and another tutorial to create an API through publisher service API. After generating the access token I use the below command but there is no response. No error code even. Are these URLs correct?
curl -k -H "Authorization: Bearer <access-token>" -H "Content-Type: application/json" -X POST -d #data.json https://127.0.0.1:9443/api/am/publisher/v2/apis
data.json file contains:
{
"policies": [
"Unlimited"
],
"visibility": "PUBLIC",
"visibleRoles": [],
"visibleTenants": [],
"cacheTimeout": 300,
"endpointConfig": {
"endpoint_type": "http",
"sandbox_endpoints": {
"url": "http://maps.google.com/maps/api/directions/"
},
"production_endpoints": {
"url": "http://maps.google.com/maps/api/directions/"
}
},
"subscriptionAvailability": null,
"subscriptionAvailableTenants": [],
"operations": [
{
"id": "postapiresource",
"target": "string",
"verb": "POST",
"authType": "string",
"throttlingPolicy": "Unlimited",
"scopes": [
"apim:api_view"
],
"usedProductIds": [
"string"
]
}
],
"responseCachingEnabled": false,
"isDefaultVersion": true,
"businessInformation": {
"technicalOwner": "ApiCreator",
"technicalOwnerEmail": "ApiCreator#pizzashack.com",
"businessOwner": "ApiPublisher",
"businessOwnerEmail": "ApiPublisher#pizzashack.com"
},
"transport": [
"http",
"https"
],
"tags": [
"phone",
"multimedia",
"mobile"
],
"provider": "admin",
"version": "Beta",
"description": "Calculates directions between locations",
"name": "GoogleDirectionsAPI",
"context": "/googledirections"
}
You have to use v3 version as follows.
curl -k -H "Authorization: Bearer <access-token>" -H "Content-Type: application/json" -X POST -d #data.json https://127.0.0.1:9443/api/am/publisher/v3/apis

Invalid JSON payload received. Unknown name \"row\" at 'payload': Cannot find field on google automl api

I am trying to implement google automl api:
https://cloud.google.com/automl-tables/docs/predict
The api docs says I need to post data in following format:
{
"payload": {
"row": {
"values": [value1, value2,...]
}
}
}
But when I to post data in same format I get the following error:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"row\" at 'payload': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "payload",
"description": "Invalid JSON payload received. Unknown name \"row\" at 'payload': Cannot find field."
}
]
}
]
}
}
Here is my curl request:
curl --location --request POST 'https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/TBLID:predict' \
--header 'Content-Type: application/json; charset=utf-8;' \
--header 'Accept-Charset: utf-8' \
--header 'Authorization: Bearer token here' \
--data-raw '{
"payload": {
"row": {
"values": [
"",
"4.900000",
""
]
}
}
}'
I am not sure what is causing this error.
Can anyone help with this problem thanks
I have a project with AutoML tables and this is an example prediction request sent in which works fine and returns results without error:
{
"payload": {
"row": {
"values": [
"2",
"test text",
"test text",
"21",
"0",
"0",
"test text",
"10",
"",
"S"
]
}
}
}
If you're not sure how to submit data or you are getting errors, go to your project in the console and to your AutoML Tables model and click "Test and Use". Then, follow these directions for getting an online prediction from console. Pay attention to the JSON Code View which will give you the exact input and let you test your JSON input as well.
To test, I submitted the following curl request (with some identifying characters changed)
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d #request.json \
https://automl.googleapis.com/v1beta1/projects/this-isnt-a-real-project-id/locations/us-central1/models/TBL123451234512345:predict
My request.json file in the same directory that I sent the request from was:
{
"payload": {
"row": {
"values": [
"yes",
"-1",
"primary",
"jul",
"51",
"0",
"yes",
"no",
"88",
"cellular",
"blue-collar",
"unknown",
"10",
"620",
"married"
]
}
}
}
The response was:
{
"payload": [
{
"tables": {
"score": 0.9999906,
"value": "no"
}
},
{
"tables": {
"score": 9.42341e-06,
"value": "yes"
}
}
]
}
I also repeated this same request in postman successfully below:
curl --location --request POST 'https://automl.googleapis.com/v1beta1/projects/this-isnt-a-real-project-id/locations/us-central1/models/TBL123451234512345:predict' \
--header 'Accept-Charset: utf-8' \
--header 'Authorization: Bearer abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd' \
--header 'Content-Type: application/json' \
--data-raw '{
"payload": {
"row": {
"values": [
"yes",
"-1",
"primary",
"jul",
"51",
"0",
"yes",
"no",
"88",
"cellular",
"blue-collar",
"unknown",
"10",
"620",
"married"
]
}
}
}'
I replicated the Quickstart and I did some successful curl requests and your issue seems to be related to the format of your json request; therefore, I recommend the following tests:
Remove the line breaks from your json, and make the request again:
curl --location --request POST 'https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/TBLID:predict' \
--header 'Content-Type: application/json; charset=utf-8;' \
--header 'Accept-Charset: utf-8' \
--header 'Authorization: Bearer token-here' \
--data-raw '{ "payload": { "row": { "values": [ "", "4.900000", "" ] } } }'
Save the json in a file and make the request again:
curl --location --request POST 'https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/TBLID:predict' \
--header 'Content-Type: application/json; charset=utf-8;' \
--header 'Accept-Charset: utf-8' \
--header 'Authorization: Bearer token-here' \
-d #request.json
If after performing them you still have the issue, I recommend you contact the GCP support so they can analyze your issue within your project.

Google FHIR API - Patient $everything

I am trying to use this api . https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Patient/PATIENT_ID/$everything
I am getting this error
{
"issue": [
{
"code": "not-supported",
"details": {
"text": "bad_resource_type"
},
"diagnostics": "unsupported resource type",
"severity": "error"
}
],
"resourceType": "OperationOutcome"
}
The correct command according to the documentation should be:
curl -X GET \
-H "Authorization: Bearer "$(gcloud auth print-access-token) \
"https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/Patient/PATIENT_ID/\$everything"
Notice that a "\" sign is missing before the $everything".

How to use Google Data Prep API using Python

Google Just launched the new API. Link is here.
I want to know what is the host in this case as they are using example.com and using the port 3005.
I am also following this article. But this does not provide example code.
If you open the Dataprep Console and navigate to Settings > Access Tokens you can click on Generate New Token. This will bring up the token, that you can copy to clipboard, but also the instructions on which base endpoint to use:
Then, clicking on a particular Recipe (see image below) will modify the browser URL to be in the form of:
https://clouddataprep.com/flows/<FLOW_ID>?recipe=<RECIPE_ID>&tab=recipe
We'll keep RECIPE_ID> so that our request body (dataprep-request.json) is something like this:
{
"wrangledDataset": {
"id": <RECIPE_ID>
}
}
Then, we can call JobGroups Create:
curl https://api.clouddataprep.com/v4/jobGroups \
-X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d #dataprep-request.json
The response will be similar to this output (I used python3 -m json.tool to pretty print the JSON):
{
"sessionId": "<SESSION_ID>",
"reason": "JobStarted",
"jobGraph": {
"vertices": [
4479390,
4479391
],
"edges": [
{
"source": 4479390,
"target": 4479391
}
]
},
"id": <JOB_GROUP_ID>,
"jobs": {
"data": [
{
"id": 4479390
},
{
"id": 4479391
}
]
}
}
Now, with the retrieved <JOB_GROUP_ID> we can use the JobGroups Get endpoint:
curl https://api.clouddataprep.com/v4/jobGroups/<JOB_GROUP_ID> \
-H "Authorization: Bearer $TOKEN"
Response:
{
"id": <JOB_GROUP_ID>,
"name": null,
"description": null,
"ranfrom": "ui",
"ranfor": "recipe",
"status": "InProgress",
"profilingEnabled": true,
"runParameterReferenceDate": "2019-12-08T21:49:33.000Z",
"createdAt": "2019-12-08T21:49:35.000Z",
"updatedAt": "2019-12-08T21:49:36.000Z",
"workspace": {
"id": REDACTED
},
"creator": {
"id": REDACTED
},
"updater": {
"id": REDACTED
},
"snapshot": {
"id": 4226057
},
"wrangledDataset": {
"id": <RECIPE_ID>
},
"flowRun": null
}

Go-CD: How to use API to trigger a pipeline?

Is there an API can be used to trigger a pipeline, I did not find one in the API manual. Or, is there any other way I can trigger a pipeline using linux command?
Thanks
link to the docs: https://api.gocd.org/current/#scheduling-pipelines
POST /go/api/pipelines/:pipeline_name/schedule
in the request you can override the environmental variables, the material to use and choose to update the material before the start.
command example as taken from the documentation:
$ curl 'https://ci.example.com/go/api/pipelines/pipeline1/schedule' \
-u 'username:password' \
-H 'Accept: application/vnd.go.cd.v1+json' \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"environment_variables": [
{
"name": "USERNAME",
"secure": false,
"value": "bob"
},
{
"name": "SSH_PASSPHRASE",
"value": "some passphrase",
"secure": true,
},
{
"name": "PASSWORD",
"encrypted_value": "YEepp1G0C05SpP0fcp4Jh+kPmWwXH5Nq",
"secure": true,
}
],
"materials": [
{
"fingerprint": "b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c",
"revision": "123"
},
{
"fingerprint": "7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730",
"revision": "1058e75b18e8a645dd71702851994a010789f450"
}
],
"update_materials_before_scheduling": true
}'
/go/api/pipelines/${pipelineName}/schedule works