Sendgrid singlesend error with api : json could not be unmarshalled - html-email

I am trying to trigger a singlesend using sendgrid api but getting json could not be unmarshalled error.
Here is what I am trying to send in my payload
{
"name" : "this is a test api 2",
"send_at": "now",
"email_config": {
"sender_id": 4810***,
"design_id": "06daea5d-9470-4cb5-8dc6-******"
},
"send_to": {
"list_ids": [
"8a97936a-8cf8-4e60-bfd3-******"
],
"segment_ids": [],
"all" : false
}
}
I am following this doc : https://docs.sendgrid.com/api-reference/single-sends/create-single-send

Related

Wirecard refund request

I'm trying to integrate wirecard payments and got a problem with the refund transaction.
With test username "70000-APILUHN-CARD" and password "8mhwavKVb91T" i've created payment processing and could see that it's successful. But when it comes to refund i get "405 method not allowed" result.
So the payment request looks like this:
POST https://wpp-test.wirecard.com/api/payment/register
With auth header including encoded username/password, content-type header, and body:
{
"payment" :
{
"merchant-account-id" :
{
"value" : merchantId
},
"request-id" : generatedRequestId,
"transaction-type" : "auto-sale",
"requested-amount" :
{
"value" : 1,
"currency" : "EUR"
},
"payment-methods" :
{
"payment-method" :
[
{"name" : "creditcard"}
]
}
},
"options" :
{
"mode" : "seamless",
"frame-ancestor" : ancestorURL
}
}
After verification i could check that such transaction successfully completed and everything is fine, so i tried to make a refund request with the same headers:
POST https://api-test.wirecard.com/engine/rest/merchants/{merchantId}/payments/{transactionId}
and body:
{
"payment":{
"merchant-account-id":{
"value":merchantId
},
"request-id":generatedRequestId,
"requested-amount":{
"value":1,
"currency":"EUR"
},
"payment-methods":{
"payment-method":[
{
"name":"creditcard"
}
]
},
"card-token":{
"token-id":"4819253888096002"
},
"card":{
"expiration-month":"1",
"expiration-year":"2023",
"card-type":"visa"
},
"parent-transaction-id": parentTransactionId,
"transaction-type":"refund-request"
},
"options":{
"mode":"seamless",
"frame-ancestor":ancestorURL
}
}
Where all the data about card/card-token/etc were obtained from transaction state request.
Is there any mistakes in my refund request, or maybe there are some extra steps that i should perform?
There are a set of mistakes both in payment and in refund requests:
Payment request needs to have the "transaction-type" : "purchase" instead of "transaction-type" : "auto-sale"
Refund request should have the "transaction-type" : "refund-purchase" instead of "transaction-type" : "refund-request"
Also refund request should be sent at URL: "https://api-test.wirecard.com/engine/rest/payments/"
(From wirecard support answer)

Swagger 2.0 uploading a file to SP Online that doesn't send the extra content through

I'm hoping someone can point out my mistake here.
I have the following swagger definition which I use on swaggerhub that will upload a file to Sharepoint document library via the rest api
{
"swagger" : "2.0",
"info" : {
"description" : "defaultDescription",
"version" : "2",
"title" : "defaultTitle"
},
"host" : "someSite.sharepoint.com",
"schemes" : [ "https" ],
"paths" : {
"/sites/ms/_api/Web/GetFolderByServerRelativeUrl('doc/test/tt')/Files/Add(url='{filename}',overwrite=true)" : {
"post" : {
"consumes" : [ "multipart/form-data" ],
"produces" : [ "application/json" ],
"parameters" : [ {
"in" : "formData",
"name" : "upfile",
"type" : "file",
"required" : true,
"description" : "The file to upload."
},
{
"in" : "path",
"name" : "filename",
"type" : "string",
"required" : true
} ],
"responses" : {
"200" : {
"schema" : {
"type" : "string"
},
"description" : "Definition generated from Swagger Inspector"
}
}
}
}
}
}
Problem is I can't open any files on SP because they're broken, and I believe I found the reason when I tested with a txt file.
I'll send a text file only containing Sample text bu when I open it on SP doc library it contains all the following as well
-------------------------------28947758029299
Content-Disposition: form-data; name="upfile"; filename="myt.txt"
Content-Type: text/plain
Sample text
-------------------------------28947758029299--
Is the issue with my content type or should I use the parameter differently, I tried researching this but what I found just matched the original guid I found
https://swagger.io/docs/specification/2-0/file-upload/
We came across a similar issue in our project.
The root cause is that Swagger 2.0 won't let you specify a different Content-Type for type file. You have to use multipart/form-data. See details here: https://swagger.io/docs/specification/2-0/file-upload/
To resolve this, you have to change the type from file to generic object. For example:
paths:
/sharepoint_upload/:
post:
description: "This will uploads a document to SharePoint."
operationId: "uploadDocuments"
consumes:
- "application/octet-stream"
produces:
- "application/json"
parameters:
- name: "documentBody"
in: "body"
description: "The actual document"
required: true
schema:
type: "object"
responses:
200:
description: "OK - Your request was successfully completed."
400:

Spring Cloud Contract provider return same as request

I'm working with two microservices using Spring Cloud Contract. One providing its contract, and the other one consuming it. In one scenario the provider response is the same that the request.
So the provider contract is like this:
Contract.make {
request {
method 'POST'
url '/provider/foo'
body(
"foo": $(regex("[a-zA-Z0-9]{20}"))
)
}
response {
status 200
body(
"fooResponse": fromRequest().body("\$.foo")
)
}
And the generated wiremock mapping:
{
"id" : "a80c0871-f4c0-49e3-8cc1-94de39899669",
"request" : {
"url" : "/provider/foo",
"method" : "POST",
"bodyPatterns" : [ {
"matchesJsonPath" : "$[?(#.['foo'] =~ /[a-zA-Z0-9]{20}/)]"
} ]
},
"response" : {
"status" : 200,
"body" : "{\"fooResponse\":\"{{{jsonpath this '$.foo'}}}\"}",
"transformers" : [ "response-template" ]
},
"uuid" : "a80c0871-f4c0-49e3-8cc1-94de39899669",
"scenarioName" : "scenarioReturnSameAsRequest",
"requiredScenarioState" : "Started"
}
But when my code calls to the provider, with foo as any text, the wiremock returns:
{
"fooResponse" : "{{{jsonpath this '$.foo'}}}"
}
How can I build a contract that responses the same parameters as the request body?
Edit
I tried with a fixed value on the response and works fine:
Contract.make {
request {
method 'POST'
url '/provider/foo'
body(
"foo": $(regex("[a-zA-Z0-9]{20}"))
)
}
response {
status 200
body(
"fooResponse": "fooValue"
)
}
Now wiremock return:
{
"fooResponse" : "fooValue"
}
Maybe is not supported getting from request a regex value?
I think the mapping should contain request.body instead of this. Also I wonder if you need to use 3 times a { or just 2 times. Or do you need to escape these?
Possible mapping:
"response" : {
"status" : 200,
"body" : "{\"fooResponse\":\"{{jsonpath request.body '$.foo'}}\"}",
"transformers" : [ "response-template" ]
},
See also the chapter JSONPath helper on http://wiremock.org/docs/response-templating
I had the same problem once. You can try to use value() like this:
"fooResponse": value(fromRequest().body('$.foo'))

Guzzle 6, put request and description json

I use guzzle 6 with a json file to describe my methods to call.
Bellow, an example with a put request :
in the json descriptor file :
"putObjects" : {
"httpMethod": "PUT",
"uri": "objects",
"summary": "Send objects to the api",
"parameters": {
"objects" : {
"type" : "string",
"location" : "body"
}
}
}
in the symfony controller :
$clientResponse = $client->execute(
$client->getCommand("putObjects", array(
'objects' => $request->getContent()
))
);
Before, with guzzle 3 when the put request was sent, the data sent was formated like this (a valid json) :
{objects: [{....}]}
But now, with guzzle 6, the data is formated as :
objects = {objects: [{....}]}
And of course my api send me an error 'Invalid json message received'.
Someone has an idea about this issue ?
I have found the solution.
In symfony controller :
$content = json_decode($request->getContent(), true);
$clientResponse = $client->execute(
$client->getCommand("putObjects", array(
'objects' => $content['objects']
))
);
In the json descriptor file :
"putObjects" : {
"httpMethod": "PUT",
"uri": "objects",
"summary": "Send objects moderated",
"parameters": {
"objects" : {
"type" : "array",
"location" : "json"
},
}
}

exception- groovy connector : script is null

I'm using Bonita BPM Community Edition v.7.0
In my process, I made a service task and it has a connector. I used Groovy 2.4 connector to call external Restful service.
This restful service url return the response as
{
"RestResponse" : {
"messages" : [ "More webservices are available at http://www.groupkt.com/post/f2129b88/services.htm", "Total [249] records found." ],
"result" : [ {
"name" : "Afghanistan",
"alpha2_code" : "AF",
"alpha3_code" : "AFG"
}, {
"name" : "Åland Islands",
"alpha2_code" : "AX",
"alpha3_code" : "ALA"
}, {
"name" : "Albania",
"alpha2_code" : "AL",
"alpha3_code" : "ALB"
}, {
"name" : "Algeria",
"alpha2_code" : "DZ",
"alpha3_code" : "DZA"
}
}}
When I test at the Edit expression window using 'Evaluate' button, it works well.BUT.. when I test using 'Test' button, it prints as follows.
java.lang.reflect.InvocationTargetException
org.bonitasoft.engine.bpm.connector.ConnectorExecutionException: USERNAME=install | org.bonitasoft.engine.core.connector.exception.SConnectorException: org.bonitasoft.engine.connector.exception.SConnectorException: java.util.concurrent.ExecutionException: org.bonitasoft.engine.connector.exception.SConnectorValidationException: org.bonitasoft.engine.connector.ConnectorValidationException: Error validating connector org.bonitasoft.connectors.scripting.GroovyScriptConnector:
The script is null.
My script is as follows,
#Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )
import groovyx.net.http.RESTClient
//import groovy.json.JsonSlurper
//import groovy.json.JsonOutput
def client = new RESTClient( 'http://services.groupkt.com' )
def resp = client.get( path : '/country/get/all' ) // ACME boomerang
assert resp.status == 200 // HTTP response code; 404 means not found, etc.
def value= resp.getData()
def value1 = value.RestResponse.result
return value1[0].name
Response like: Afghanistan
while test it, Why it shows that error?
Any one please help me out from this issue,
It was a bug. Fixed in 7.3.1.
Best