I tried to create a model, and connect to my API test server.
Here's the REST datasource configuration :
"postsREST": {
"name": "postsREST",
"connector": "rest",
"operations": [{
"template": {
"method": "GET",
"url": "http://localhost:3001/posts"
},
"functions": {
"find": []
}
}, {
"template": {
"method": "POST",
"url": "http://localhost:3001/posts",
"headers": {
"accept": "application/json",
"content-type": "application/json"
},
"query": {
"title": "{^title}",
"author": "{^author}"
},
"body": {
"title": "{^title}",
"author": "{^author}"
}
},
"functions": {
"create": [
"title",
"author"
]
}
}]
}
The problem is, that when I use the explorer, the generated request url is this:
http://localhost:3000/api/posts/create?title=f&author=f
Instead of:
http://localhost:3000/api/posts
What am I doing wrong? Maybe there is new documentation?
Thanks.
You should use form instead of req or body, if you want the params not to be part of the request-url. req or body will append your parameters to the request URL.
Using form will send your parameters just like a form is submitted using POST method and hence as part of the request body.
So, try the following way for the template section in your code:
"template": {
"method": "POST",
"url": "http://localhost:3001/posts",
"headers": {
"accept": "application/json",
"content-type": "application/json"
},
"form": {
"title": "{^title}",
"author": "{^author}"
}
},
Additionally, I do not see any point in adding the same parameters to the req and body attributes both.
Related
I want to get the token information for ADP Client through Azure Logic App. I have the Client Certificate from ADP so I decided to use HTTP trigger from Logic App and selected authentication type "Client Certificate".
Since I cant directly use certificate in Logic app so I converted certificate into base64Encoded .pfx format, and certificate is not having any password.
below is the sample code for the request
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {},
"contentVersion": "1.0.0.0",
"outputs": {},
"triggers": {
"HTTP": {
"inputs": {
"authentication": {
"pfx": "convertedbase64string",
"type": "ClientCertificate"
},
"body": "grant_type=client_credentials&client_id=ClientId&client_secret=client_secret",
"headers": {
"content-type": "application/x-www-form-urlencoded"
},
"method": "POST",
"uri": "https://accounts.adp.com/auth/oauth/v2/token"
},
"recurrence": {
"frequency": "Month",
"interval": 15
},
"type": "Http"
}
}
},
"kind": "Stateful"
}
above request returns me bad request, can anyone help me what is going wrong here?
For converting into base64 I used below steps in power shell
$pfx_cert = get-content 'C:\sample\adpcertificate.pfx' -Encoding Byte
$output =[Convert]::ToBase64String($pfx_cert)
$output
I tried same request with client certificate using postman which is working fine, but not able to get succeed with Logic App.
Any help is much appreciated.
There are only few differences between the headers sent from Postman and the Logic App. The main difference is that Postman also sends the accept-header: "Accept": "*/*" and leaves out alle the x-ms-* headers from the logic app.
I created a Logic App with http-trigger, which I post to from Postman and Logic App to inspect the changes:
With Postman
{
"headers": {
"Connection": "keep-alive",
"Accept": "*/*",
"Accept-Encoding": "br,gzip,deflate",
"Host": "....westeurope.logic.azure.com:443",
"User-Agent": "PostmanRuntime/7.28.4",
"Postman-Token": "...-baea-4e89-9bf6-490a63968b5d",
"Content-Length": "76",
"Content-Type": "application/x-www-form-urlencoded"
},
"body": {
"$content-type": "application/x-www-form-urlencoded",
"$content": "Z3JhbnRfdHlwZT1jbGllbnRfY3JlZGVudGlhbHMmY2xpZW50X2lkPUNsaWVudElkJmNsaWVudF9zZWNyZXQ9Y2xpZW50X3NlY3JldA==",
"$formdata": [
{
"key": "grant_type",
"value": "client_credentials"
},
{
"key": "client_id",
"value": "ClientId"
},
{
"key": "client_secret",
"value": "client_secret"
}
]
}
}
With Logic App
{
"headers": {
"Connection": "Keep-Alive",
"Accept-Encoding": "gzip,deflate",
"Accept-Language": "en",
"Host": "...westeurope.logic.azure.com",
"User-Agent": "azure-logic-apps/1.0,(workflow ...; version ...)",
"x-ms-trigger-callback-url": "https://....westeurope.logic.azure.com/ <...>",
"x-ms-trigger-type": "Http",
"x-ms-workflow-id": "...",
"x-ms-workflow-version": "...",
"x-ms-workflow-name": "myworkflowname",
"x-ms-workflow-system-id": "/locations/westeurope/scaleunits/...",
"x-ms-workflow-run-id": "...",
"x-ms-workflow-operation-name": "HTTP",
"x-ms-execution-location": "westeurope",
"x-ms-workflow-subscription-id": "...",
"x-ms-workflow-resourcegroup-name": "..",
"x-ms-tracking-id": "...",
"x-ms-correlation-id": "...",
"x-ms-client-request-id": "...",
"x-ms-activity-vector": "...",
"Content-Length": "76",
"Content-Type": "application/x-www-form-urlencoded"
},
"body": {
"$content-type": "application/x-www-form-urlencoded",
"$content": "Z3JhbnRfdHlwZT1jbGllbnRfY3JlZGVudGlhbHMmY2xpZW50X2lkPUNsaWVudElkJmNsaWVudF9zZWNyZXQ9Y2xpZW50X3NlY3JldA==",
"$formdata": [
{
"key": "grant_type",
"value": "client_credentials"
},
{
"key": "client_id",
"value": "ClientId"
},
{
"key": "client_secret",
"value": "client_secret"
}
]
}
}
Solution
My solution would be to manually add the Accept-Header in the post request in the Logic App.
"headers": {
"Accept": "*/*",
// ...
},
I sadly don't have an ADP account to verify this, but I've seen other APIs break when no accept header is sent.
I'm using Loopback4 as an Central API. I'm trying to call a method of the 3rd party API through a remote method in Loopback. I'm using Strapi as 3rd party API and communicate this to loopback4
With Loopback, I have a datasource which looks like the following:
const strapiConfig = {
name: 'strapi',
connector: 'rest',
baseURL: appConfig.strapi.host,
crud: false,
options: {
headers: {
"accept": "application/json",
"content-type": "application/json",
"cache-control": "no-cache",
"Authorization" : `Bearer ${appConfig.strapi.token}`
}
},
operations: [
{
"template": {
"method": "GET",
"url": `${strapiUrl}/pages/{pageId}`
},
"functions": {
"getOnePage": ["pageId"]
}
},
{
"template": {
"method": "GET",
"url": `${strapiUrl}/pages`
},
"functions": {
"getPages": ""
}
},
{
"template": {
"method": "GET",
"url": `${strapiUrl}/glossary/{id}`
},
"functions": {
"getOneGlossary": ['id']
}
},
{
"template": {
"method": "GET",
"url": `${strapiUrl}/glossary`
},
"functions": {
"getGlossary": ""
}
},
{
"template": {
"method": "GET",
"url": `${strapiUrl}/faq`
},
"functions": {
"getFaqs": ""
}
},
{
"template": {
"method": "GET",
"url": `${strapiUrl}/faq/{id}`
},
"functions": {
"getOneFaq": ['id']
}
}
]
};
the only endpoint that are working is the pages
Any advice is welcome. Thanks!
What kind of error/status code do you get when calling the other Endpoints?
Have you set the Roles & Permissions within Strapi?
Example (depending on the Strapi version):
Navigate to SETTINGS - Users & Permissions Plugin.
Click the Public Role.
Scroll down under Permissions, open the Application tab and find the collection type you want to edit.
i.e. Click the checkbox next to find and findone.
Click Save
Check: https://strapi.io/documentation/developer-docs/latest/getting-started/quick-start.html#_7-set-roles-and-permissions
When there are multiple headers in the interaction, pact-jvm-provider-maven_2.12 version 3.5.25 throws an exception when I run mvn pact:verify to verify the contract at the provider side
Caused by: java.lang.NullPointerException: Cannot set property 'text' on null object
at org.codehaus.groovy.runtime.NullObject.setProperty (NullObject.java:80)
at org.codehaus.groovy.runtime.InvokerHelper.setProperty (InvokerHelper.java:197)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty (ScriptBytecodeAdapter.java:484)
at au.com.dius.pact.provider.reporters.JsonReporter.finaliseReport (JsonReporter.groovy:49)
at org.codehaus.groovy.vmplugin.v7.IndyInterface.selectMethod (IndyInterface.java:232)
at au.com.dius.pact.provider.ProviderVerifier$_finialiseReports_closure32.doCall (ProviderVerifier.groovy:367)
My interaction is
"interactions": [
{
"description": "Consumer interaction of Put Person Algorithm",
"request": {
"method": "PUT",
"path": "model/v0/algorithm/person",
"headers": {
"Authorization": "Bearer ACCESS_TOKEN",
"Content-Type": "application/json"
},
"query": {
"crn": [
"TENANT_NAME"
]
},
"body": {
"standardizers": {},
"encryption": {},
"entity_types": {},
"locale": "en_us"
}
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
}
},
"providerStates": [
{
"name": "B Put Person Algorithm"
}
]
}
],
If I remove "Content-Type": "application/json" from the request headers, this error will be gone. Is this a bug in the plugin?
Absolutely it supports multiple headers. It may be a big with that specific version or some other artifact of the test process. Could you please file a bug report and ideally a reproducible example?
Worth checking you're on the latest version of the maven plugin also.
Is it possible to create users in bulk via the REST API. Same as we do for single user in the below URL.
https://graph.windows.net/{MYADB2C}.onmicrosoft.com/users?api-version=1.6
We have the provision via the Azure portal but could'nt find anything with REST API.
UPDATED
Sample request for Batch processing
POST https://graph.windows.net/{}.onmicrosoft.com/$batch?api-version=1.6
Headers :
Authorization : {token}
Content-Type : multipart/mixed; boundary=changeset_***********
Body :
{
"requests": [
{
"id": "1",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"creationType": "LocalAccount",
"displayName": "test1#gamil.com",
"passwordPolicies": "DisablePasswordExpiration, DisableStrongPassword",
"passwordProfile": {
"password": "***",
"forceChangePasswordNextLogin": false
},
"signInNames": [
{
"type": "emailAddress",
"value": "test1#gamil.com"
}
]
},
"headers": {
"Content-Type": "application/json"
}
},
{
"id": "2",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"creationType": "LocalAccount",
"displayName": "test2#gmail.com",
"passwordPolicies": "DisablePasswordExpiration, DisableStrongPassword",
"passwordProfile": {
"password": "***",
"forceChangePasswordNextLogin": false
},
"signInNames": [
{
"type": "emailAddress",
"value": "test1#gamil.com"
}
]
},
"headers": {
"Content-Type": "application/json"
}
}
]
}
Yes. You can batch operations by referring to Batch processing | Graph API concepts.
But we recommend you use Microsoft Graph API JSON Batching instead of Azure AD Graph Batch processing because Azure AD Graph content is no longer updated.
An example using Microsoft Graph API here:
POST https://graph.microsoft.com/v1.0/$batch
Accept: application/json
Content-Type: application/json
{
"requests": [
{
"id": "1",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"displayName": "at1",
"mailNickname": "at1",
"userPrincipalName": "at1#**.onmicrosoft.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "password-value"
}
},
"headers": {
"Content-Type": "application/json"
}
},
{
"id": "2",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"displayName": "at2",
"mailNickname": "at2",
"userPrincipalName": "at2#**.onmicrosoft.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "password-value"
}
},
"headers": {
"Content-Type": "application/json"
}
},
{
"id": "3",
"method": "POST",
"url": "/users",
"body": {
"accountEnabled": true,
"displayName": "at3",
"mailNickname": "at3",
"userPrincipalName": "at3#**.onmicrosoft.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": true,
"password": "password-value"
}
},
"headers": {
"Content-Type": "application/json"
}
}
]
}
You can have a quick test in Microsoft Graph Explorer.
I created an API endpoint like:
GET /etablissementDetails/{id}
Here is my datasources.json file:
"etablissementDetailsREST": {
"name": "etablissementDetailsREST",
"crud": false,
"connector": "rest",
"debug": false,
"options": {
"headers": {
"accept": "application/json",
"content-type": "application/json"
},
"strictSSL": false
},
"operations": [
{
"template": {
"method": "GET",
"url": "https://data.education.gouv.fr/api/records/1.0/search/?dataset=fr-en-adresse-et-geolocalisation-etablissements-premier-et-second-degre",
"headers": {
"accepts": "application/json",
"content-type": "application/json"
},
"query": {
"q": "{id}"
},
"options": {
"strictSSL": true,
"useQuerystring": true
},
"responsePath": "$.records.*"
},
"functions": {
"{id}": ["id"]
}
}
]}
In loopback explorer, if I enter as an idea and click on Try me out (Run the GET), I am getting the following:
http://localhost:3000/api/v1/etablissementDetails/{id}?id=0593904Y
I would like the {id} to be replaced by 0593904Y directly in the URL to become http://localhost:3000/api/v1/etablissementDetails/0593904Y