Creating a basic REST API in PolicyCenter - guidewire

I am trying to create a basic HelloWorld REST API in PolicyCenter. I am getting an Internal Server Error from the GET /apis's endpoint (from the com.guidewire.pl.rest.docs.ApiListGenerator) and my new endpoint returns 404 Not Found. I am not sure what is missing and I don't see any clues in the logs. Any hints are welcome.
GET http://localhost:8180/pc/rest/apis
{
"status": 500,
"errorCode": "java.lang.IllegalArgumentException",
"cause": {
"class": "java.lang.IllegalArgumentException",
"message": "Keys in JsonObject cannot be null"
},
"stackTrace": [
"gw.api.json.JsonObject.validateKey(JsonObject.java:898)",
"gw.api.json.JsonObject.put(JsonObject.java:849)",
"com.guidewire.pl.rest.docs.ApiListGenerator.lambda$createApiListJson$2(ApiListGenerator.java:37)",
"java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)",
...
GET http://localhost:8180/pc/rest/helloworld
{
"status": 404,
"errorCode": "gw.api.rest.exceptions.NotFoundException",
"userMessage": "No resource was found at path /helloworld"
}
[modules\configuration\gsrc\myorg\pc\integration\restapi\helloworld\HelloWorldHandler.gs]
package myorg.pc.integration.restapi.helloworld
class HelloWorldHandler {
public function getHelloWorld() : String {
return 'Hello, World!'
}
}
[modules\configuration\config\integration\apis\myorg\pc\helloworld\helloworld-1.0.swagger.yaml]
swagger: "2.0"
info:
version: "1.0"
title: "Hello World API"
x-gw-apihandlers:
- myorg.pc.integration.restapi.helloworld.HelloWorldHandler
paths:
/helloworld:
get:
summary: "Says 'Hello World'"
description: "Says 'Hello World'"
operationId: getHelloWorld
produces:
- text/plain
responses:
'200':
description: |
Successful operation
schema:
type: string
[modules\configuration\config\integration\apis\published-apis.yaml]
apis:
- name: myorg.pc.helloworld.helloworld-1.0
defaultTemplate:
- name: gw.pl.framework.dev_template-1.0

After some digging I was able to find the documentation on the Swagger format, which mentioned basePath as a required property. After adding this, my API started working (with a different URL).

Related

Azure assign group and device to script using Graph API

I am trying to assign groups and devices to a PowerShell script in Microsoft Intune using the following POST request:
URL: https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts/%7Bid%7D/Assign
Body:
{
"deviceManagementScriptGroupAssignments": [
{
"#odata.type": "#microsoft.graph.deviceManagementScriptGroupAssignment",
"id": "{ScriptId:GroupId}",
"targetGroupId": "{GroupId}"
}
],
"deviceManagementScriptAssignments": [
{
"#odata.type": "#microsoft.graph.deviceManagementScriptAssignment",
"id": "{ScriptID:DeviceID}",
"target": {
"#odata.type": "#microsoft.graph.allDevicesAssignmentTarget",
"deviceAndAppManagementAssignmentFilterId": null,
"deviceAndAppManagementAssignmentFilterType": "none"
}
}
]
}
However, I am getting a 400 error with the following message:
"{ "_version": 3, "Message": "An error has occurred - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: 615c3437-bd99-2193-9d4b-d9a61deb0340 - Url: https://fef.amsua0102.manage.microsoft.com/DeviceFE/StatelessDeviceFEService/deviceManagement/deviceManagementScripts('{id}')/microsoft.management.services.api.assign?api-version=5022-11-08", "CustomApiErrorPhrase": "", "RetryAfter": null, "ErrorSourceService": "", "HttpHeaders": "{}"}"
I base on this document of Microsoft https://learn.microsoft.com/en-us/graph/api/intune-shared-devicemanagementscript-assign?view=graph-rest-beta
I tried to reproduce the same in my environment.
Received the same error:
{
"error": {
"code": "UnknownError",
"message": "{\"ErrorCode\":\"Forbidden\",\"Message\":\"{\\ \\\"_version\\\": 3,\\ \\\"Message\\\": \\\"An error has occurred - Operation ID (for customer support): xxxx –
}
When I followed the url in the error and queried, I got that the api version is not supported.
Make sure the authorization header is given with bearer token which has proper permissions to work with intune and device management
Omit the parameter #odata.type in the post request body.
{
"#odata.type": "#microsoft.graph.deviceManagementScript",
…
"runAs32Bit": true
}
Make sure you have DeviceManagementConfiguration.ReadWrite.All Application and delegated permissions.
Note that Intune requires an active Intune license for the tenant.

Deploying ARM Template for an API Connection that uses OnPrem Data Gateway succeeds but the authType and gateway parameters are missing

I've been banging my head against a brick wall on this.
I'm trying to deploy via Azure DevOps pipeline, a bicep/ARM Template an API Connection that uses a Custom Connector that is linked to an On-prem API via a Data Gateway.
Here is my bicep file...
param connectionName string
param displayName string
param gatewayResourceGroup string
param gatewayName string
param connectorName string
param location string = resourceGroup().location
resource connector 'Microsoft.Web/customApis#2016-06-01' existing = {
name: connectorName
}
resource gatewayApi 'Microsoft.Web/connectionGateways#2016-06-01' existing = {
name: gatewayName
scope: resourceGroup(gatewayResourceGroup)
}
resource apiConnection 'Microsoft.Web/connections#2016-06-01' = {
name: connectionName
location: location
properties: {
displayName: displayName
nonSecretParameterValues: {
authType: 'anonymous'
#disable-next-line BCP036
gateway: {
name: gatewayName
id: gatewayApi.id
type: 'Microsoft.Web/connectionGateways'
}
}
api: {
name: connector.name
displayName: 'CONNECTOR ${connectorName}'
id: connector.id
type: 'Microsoft.Web/customApis'
}
}
}
I issue is the nonSecretParameterValues.
They don't go anywhere.
The API Connection is deployed like...
What makes this a little worse is the deployment is successful...
But if I drill into the Operation details I can see there were two issues...
"overallStatus": "Error",
"statuses": [
{
"status": "Error",
"target": "authType",
"error": {
"code": "ConfigurationNeeded",
"message": "Parameter value missing."
}
},
{
"status": "Error",
"target": "gateway",
"error": {
"code": "ConfigurationNeeded",
"message": "Parameter value missing."
}
}
],
Very frustrating.
Now I can manually add the values I intended to be there for the authType and gateway parameters after the deployment is "successful". Then my logic app that uses this API Connection and Custom Connector to Onprem Gateway works as expected.
But the exported template for the API Connection does not change between the connection having missing parameters (in the UI) or after I manually enter the values.
I have also tried added some Powershell after the deployment to pick up the connection and to try settings the "missing" values and updating the resource from there.
I can see another API Connection via Powershell which is correctly set with the authType and gateway parameters.
But when I try, to set these on the resource I need to "fix" it also complains...
I would really like to have the API Connection deployment fully via Azure DevOps pipeline.
NOTE: I find it very odd to have to use the #disable-next-line BCP036 to disable the warning in VSCode. And even opening the built ARM Template will give a warning on the "gateway" property name. I even tried replacing the "object" with just the resource id and that didn't help.
The parameters should be in a parameterValues property object:
resource apiConnection 'Microsoft.Web/connections#2016-06-01' = {
name: connectionName
location: location
properties: {
displayName: displayName
parameterValues: {
authType: 'anonymous'
gateway: {
id: gatewayApi.id
}
}
...
}
}
Suggestion:
The nonSecretParameterValues object must be in the format of a dictionary. I cannot find any hard documentation about this as a data structure, but it's mentioned several times.
nonSecretParameterValues: {
authType: 'anonymous'
gateway-name: gatewayName
gateway-id: gatewayApi.id
gateway-type: 'Microsoft.Web/connectionGateways'
}
Hope this helps.

Shopify NodeJS: Error creating Metafields: error 422 "type can't be blank"

I'm trying to create metafields using the Shopify Admin REST API (with NodeJS).
This is a simplified version of the call I'm trying to make (see documentation):
const data = await client.post({
path: 'metafields',
data: {
"metafield": {
"namespace": "namespace123",
"key": "key123",
"value": 42,
"type": "number_integer"
}
},
type: DataType.JSON,
});
But I get this error:
HttpResponseError: Received an error response (422 Unprocessable Entity) from Shopify:
{
"type": [
"can't be blank"
]
}
I've checked that the type attributes are set properly:
The root-level type is set correctly to application/json, and data.metafield.type is set following the rules here.
I've also tried other types, but I get the same error.
Problem: I was using an old API version to initialize my Shopify Context:
Shopify.Context.initialize({
// ... other stuff ... //
API_VERSION: ApiVersion.October20,
});
None of my other API calls relied on old breaking behaviour, so updating my API version fixed the issue without too much hassle:
Shopify.Context.initialize({
// ... other stuff ... //
API_VERSION: ApiVersion.January22,
});

OpenAPI can't connected

I'm trying to build a API base on https://github.com/coinbase/rosetta-specifications/blob/master/api.yaml specification.
Now i have run this yaml file in openapi generator for nodejs-express-server (https://openapi-generator.tech/docs/generators/nodejs-express-server)
When i want try to access the endpoint /network/list it give me error:
{
"message": "request should have required property 'headers'",
"errors": [
{
"path": ".headers",
"message": "should have required property 'headers'",
"errorCode": "required.openapi.validation"
}
]
}
I have add the following header in postman: Content-Type: application/json (as specify in yaml file).
can anyone please let me know what i'm doing wrong?

Translator Text API endpoint returning 404 code with message "Resource not found" as a JSON Object

After creating a service for Text Translator of Azure service, the end point when tried with the one of the keys provided returns a json object with 404 error code and Message "Resource not found"
{
"error": {
"code": "404",
"message": "Resource not found"
}
}
Postman Parameters used are:
URL:
https://agro.cognitiveservices.azure.com/translate?api-version=3.0&to=ta,en
Body JSON:
{
[
"Text" : "Hello World"
]
}
With Ocp-Apim-Subscription-Key parameter in header, is that which was given as the subscription key for cognitive service of Azure when registering.
NOTE: HTTP POST Method used.
Please suggest a solution to resolve the problem and THANK YOU for this.
Screenshot Shared below as link:
enter image description here
Looking at Microsoft docs, your endpoint seems to be invalid. See https://learn.microsoft.com/en-us/azure/cognitive-services/translator/quickstart-translate?pivots=programming-language-javascript
HTTP POST Endpoint: https://api.cognitive.microsofttranslator.com/?api-version=3.0&to=ta,en
headers: {
'Ocp-Apim-Subscription-Key': subscriptionKey,
'Content-type': 'application/json',
'X-ClientTraceId': uuidv4().toString()
}
Body:
body: [{
'text': 'Hello World!'
}]

Resources