I'm using Zapier's REST Hooks. In my Zap, I also have a trigger field that is used to trigger the zap when the condition is met. In my case, the trigger field is "segment" - so as to only trigger the zap when the selected segment is created.
The trouble I'm having is POSTING the selected trigger field to the REST Hook Subscribe URL.
My first thought is to update the "REST Hook Subscribe URL" to be: https://domain.com/api/v1/hooks?filter={{segment}}
Which does work to pass the trigger field as a URL paramater. However, this creates an Error for the other Triggers, because the "segment" field does not exist.
How is this best accomplished?
The trick here is to use Zapier scripting to manipulate the requests made to your App's API.
The trigger fields are available with the bundle.trigger_fields object. So I passed these in the params during pre_subscribe like so:
'use strict';
var Zap = {
pre_subscribe: function(bundle) {
return {
url: bundle.request.url,
method: bundle.request.method,
auth: bundle.request.auth,
headers: bundle.request.headers,
params: bundle.trigger_fields,
data: bundle.request.data
};
}
}
That did the trick for me...
Related
I am able to send events to Event Hub as a batch using the Nuget package Azure.Messaging.EventHubs.But I want to use REST API.
I am able to send single events to Event Hub using REST API using Postman. But as per documentation if I need to send batch events in REST API I need add header Content-Type:application/vnd.microsoft.servicebus.json and Also the message should be enclosed with the "Body"
like [{"Body":"Message1"},{"Body":"Message2"},{"Body":"Message3"}]
So if I need to send json as event then should I create a json string and send it?
Sample:
[
{
"Body":"{\"ID\":\"1\",\"Name\":\"abc1\"}"
},
{
"Body":"{\"ID\":\"2\",\"Name\":\"def1\"}"
},
{
"Body":"{\"ID\":\"3\",\"Name\":\"xyz1\"}"
}
]
OR is there any other option to send event as Batch using the REST API to Event Hub.
"Body" is a string content then yes, you must escape your JSON content first. Your sample looks OK to me.
Yes, you could create an events list -
List<Event> events = new List<Event>(){
new Event(1,"abc1"),
new Event(2,"def1"),
new Event(3,"xyz1"),
}
and send it via POST
The Google Cloud Build - Webhook Trigger create trigger documentation shows the proper URL to POST to invoke the build trigger. However the documentation does not describe the POST body, which seems to be required. I have successfully triggered the cloud build webhooks using content-type: application/json header with a POST body of {}, but it would be nice to know:
What is the POST body supposed to be?
Are we able to pass substitution variables in the POST body?
The Google Cloud Build - REST API documentation provides some additional hints that a HttpBody payload is accepted, but no additional information past that as for as I can tell.
The body is what you want! In fact, in your trigger you customize your substitution variable like this (from the documentation)
--subtitutions=\
_SUB_ONE='$(body.message.test)', _SUB_TWO='$(body.message.output)'
So, your body need to be like that
{
"message": {
"test": "test value",
"ourput": "my output"
}
}
The data are automatically extracted from your body content. So you can add more substitutions or change the format of your JSON and thus of your substitutions value.
We have many dozens of build pipelines and we want to pause and resume (re-enable) build pipelines from a simple webapp interface as we are making config changes frequently. Here is the MS doc explaining this API:
https://learn.microsoft.com/en-us/rest/api/azure/devops/build/builds/update%20build?view=azure-devops-rest-5.0#definitionqueuestatus
From this documentation, it appears I need to hit the REST API and change/toggle the DefinitionQueueStatus -- however, this documentation only shows a sample for a build specific operation, whereas I want to pause then re-enable the entire build pipeline. What is the proper way to make this call?
I'm using fetch - and I've tried many dozen formats in the call - the 'ourorg' and 'ourproject' are correct (we use this call structure for many other calls), but all fails for this call below. I grabbed the 'definitionID' from the URL I can visibly see when in the Azure devops portal on the specific build pipeline page, and I'm using it for the {buildID} as I don't know what else to put there. Any guidance to help here is appreciated - I don't need to use fetch btw - any working sample will help here:
fetch(https://dev.azure.com/our_org/our_projectname/_apis/build/builds/definitionId=1593?retry=true&api-version=5.0 {
method: 'PATCH ',
credentials: 'same-origin',
body: 'DefinitionQueueStatus: "Enabled"'
}).then(function(response) {
console.log(response);
})
It seems that the body is incorrect in your post. Here is sample about how to use POSTMAN to access Azure DevOps Services REST APIs.
Generate the PAT, and then record the token, it is important to use to authorization, please see this document.
Create a new request in POSTMAN, it is recommended to put the request in a collection for Azure DevOps Services REST API;
Select the authorization as Basic Auth, you can input the username as any value, and the password as the token which is generated in step1.
Basic Auth
Set the REST API which you want to use,and select the request method type(GET,POST,FETCH ....), here you use https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}?api-version=5.0.
In the Body tab, you can set the request body as raw in json format, and input the value as following:
{
"buildNumber":"#20190607.2",
"buildNumberRevision":1,
"definition":
{
"id":1,
"createdDate":null,
"queueStatus":"paused"
}
}
Everthing is ready now, you can send the request, if sccuess, you will get the response from the REST API.
In your post, the body content is incorrect, the Request Body should meet the format in the REST API document. The DefinitionQueueStatus is a type in definitions. In addition, if you send the request with parameter retry, you will get the message The request body must be empty when the retry parameter is specified..
I use this trick (thanks #Robban) to publish a Contentful entry through the API, without triggering the webhook.
However, I could not figure out how to UNpublish an entry through the API without triggering the webhook.
According to the Contentful documentation, to unpublish an entry through the API, it goes like this:
client.getSpace('<space_id>')
.then((space) => space.getEntry('<entry_id>'))
.then((entry) => entry.unpublish())
As <entry_id> is the only payload, how could I indicate to the webhook it should not proceed as usual, as it was an API call?
There is unfortunately, again, no difference between a call from the API directly or from the web app. The web app does exactly this call under the hood.
Further more, in the case of an unpublish the only thing your webhook would recieve is a deletion object which does not contain any fields. This means that the trick shown in the previous answer does not apply here.
The only way I can think of solving this would be to make another call to some data store (could be Contentful) and put the entry id and perhaps also some timestamp in there. Your webhook could then upon recieving an unpublish event query this datastore and see if processing should continue or if it seems the unpublish was made through the web app.
Basically something like this:
client.getSpace('<space_id>')
.then((space) => space.getEntry('<entry_id>'))
.then((entry) => {
otherService.SetUnpublishedThroughManualAPICall(entry.sys.id);
entry.unpublish();
})
Then in your webhook with some pseudo code:
function HandleUnpublish(object entry) {
if(OtherService.CheckIfManualUnpublish(entry.sys.id)){
//Do some processing...
}
}
You could opt to use a field in Contentful as your store for this. In that case you would just before unpublishing set this field. Something like this:
client.getSpace('<space_id>')
.then((space) => space.getEntry('<entry_id>'))
.then((entry) => {
entry.fields['en-US'].unpublishedTroughApi = true;
entry.update();
})
.then((entry) => entry.unpublish())
Then in your webhook you would have to fetch the entry again via the management API and inspect the field. Keep in mind that this would result in a number of extra API calls to Contentful.
I have 2 HTTP actions, one after another in a logic app, how do I read the response from a previous HTTP action in the second HTTP action?
First HTTP call (REST) returns a response in JSON format -
{
"authResult": {
"isPasswordExpired": true,
"authToken": "cxxcxcxc",
"message": "Login Successful"
}
}
I want to send authtoken from the result in second http action as authorization header.
As Derke Li mentioned that we could use exression or Parse Json to do that. I also do a demo about how to use the Parse JSON action.
1.Add the Parse Json action after the first Http action
2.Add the parse content and click on the button "Use sample payload to generate schema" and that will pop a new window. Paste in your "authResult" json. As seen in the below image.
3.Then we could pick the token from the dynamic content.
4.We could check the result.
There are two ways you can do this.
Use expression to directly reference the property. #body('NameOfFirstHTTPAction')?['authResult']?'[authToken]
Add a "Parse JSON" action in between the two HTTP action, and provide a sample response of the first HTTP action to generate a schema. Then, in the second HTTP action, you will see authToken as a token from the dynamic content picker for you to reference.