How do use REST API in Marketo to add leads as members into Programs? - marketo

How do you use REST API in Marketo to add leads as members into programs?
I have created folders, programs and leads using REST API.
Now I want to add specific leads by using their ID into Programs as members.
How do I do it using REST API or do I need to use a different method?
Please let me know.

Use the "Change Lead Program Status" End point: http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Leads/changeLeadProgramStatusUsingPOST
Example call:
POST /rest/v1/leads/programs/{programId}/status.json
data={
"status": "Registered",
"input": [
{"id": 123}
]
}
So you can add up to 300 Lead IDs, but only 1 status at a time (for 1 Program).

Related

bitbucket API Rest - Getting branches from a repository

I am looking for the list of endpoints available for bitbucket API regarding get the branches from a repository and a specific branch.
I was expecting to see something like:
GET /2.0/repositories/{workspace}/{repo_slug}/branches/
GET /2.0/repositories/{workspace}/{repo_slug}/branches/{branch}
So I can get the commits from a specific branch. 
I know I can get commits but with this endpoint, its scope is under repository perspective. 
Do you know if there are endpoints to work with branches and recursively into its hierarchy?
I looked over the documentation for API 2.0 but I did not see what I was looking for so that is why I am posting this question here.
In addition, I see some time ago that was not possible according to this answer, but it belongs to the version 1.0 of the API. Is it still true? 
When hitting this endpoint:
https://api.bitbucket.org/2.0/repositories/<workspace>/<repository-name>`
# GET /2.0/repositories/{workspace}/{repo_slug}
You get as a result a JSON document. In the links attribute you got a key called branches. It is something like this:
{
"scm": "git",
"has_wiki": false,
"links": {
"watchers": {
"href": "https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/watchers"
},
"branches": {
"href": "https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches"
},
....
So you can hit the endpoint and get the branches:
https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches
# GET /2.0/repositories/{workspace}/{repo_slug}/refs/branches
And get a specific branch with
https://api.bitbucket.org/2.0/repositories/{workspace}/{repo_slug}/refs/branches/<branch-name>
# GET /2.0/repositories/{workspace}/{repo_slug}/refs/branches/<branch-name>

Why use DELETE/POST instead of PUT for 'unfollowing/following' a user?

Referencing this API tutorial/explanation:
https://thinkster.io/tutorials/design-a-robust-json-api/getting-and-setting-user-data
The tutorial explains that to 'follow a user', you would use:
POST /api/profiles/:username/follow.
In order to 'unfollow a user', you would use:
DELETE /api/profiles/:username/follow.
The user Profile initially possesses the field "following": false.
I don't understand why the "following" field is being created/deleted (POST/DELETE) instead of updated from true to false. I feel as though I'm not grasping what's actually going on - are we not simply toggling the value of "following" between true and false?
Thanks!
I think that the database layer have to be implemented in a slightly more complex way than just having a boolean column for "following".
Given that you have three users, what would it mean that one of the users has "following": true? Is that user following something? That alone cannot mean that the user is following all other users, right?
The database layer probably consists of (at least) two different concepts: users and followings; users contain information about the user, and followings specify what users follow one another.
Say that we have two users:
[
{"username": "jake"},
{"username": "jane"}
]
And we want to say that Jane is following Jake, but not the other way around.
Then we need something to represent that concept. Let's call that a following:
{"follower": "jane", "followee": "jake"}
When the API talks about creating or deleting followings, this is probably what they imagine is getting created. That is why they use POST/DELETE instead of just PUT. They don't modify the user object, they create other objects that represent followings.
The reason they have a "following": true/false part in their JSON API response is because when you ask for information about a specific user, as one of the other users, you want to know if you as a user follows that specific user.
So, given the example above, when jane would ask for information about jake, at GET /api/profiles/jake, she would receive something like this:
{
"profile": {
"username": "jake",
"bio": "...",
"image": "...",
"following": true
}
}
However, when jake would ask for the profile information about jane, he would instead get this response:
{
"profile": {
"username": "jane",
"bio": "...",
"image": "...",
"following": false
}
}
So, the info they list as the API response is not what is actually stored in the database about this specific user, it also contains some information that is calculated based on who asked the question.
Using a microPUT would certainly be a reasonable alternative. I don't think anybody is going to be able to tell you why a random API tutorial made certain design decisions. It may be that they just needed a contrived example to use POST/DELETE.
Unless the author sees this question, I expect it's unanswerable. It's conceivable that they want to store meta information, such as the timestamp of the follow state change, but that would be unaffected by POST/DELETE vs. PUT.

Is there any way I can get a list of all possible responses from the google vision api?

I am using the google cloud vision api to analyze pictures. Is there a list of all the possible responses for the labelAnnotations method?
The API reference of Vision API gives an overview of all the possible JSON responses for the different image annotation requests.
The labelAnnotation request returns a generic EntityAnnotation response, you can find the JSON representation here, also containing more information about the JSON representation of BoundingPoly, LocationInfo and Property:
{
"mid": string,
"locale": string,
"description": string,
"score": number,
"confidence": number,
"topicality": number,
"boundingPoly": {
object(BoundingPoly)
},
"locations": [
{
object(LocationInfo)
}
],
"properties": [
{
object(Property)
}
],
}
I think you're asking whether you can get a look at the list of possible labels/entities that the Cloud Vision API will detect. If that's the case, the short answer is no, not in any manageable way.
The more complicated answer is sort of, since most labels will have a property for the knowledge graph entry (e.g., {desc: 'dog', mid: '/m/0bt9lr'}). This means that you can look-up more information about the label/entity using the Knowledge Graph API.
While you can't "store a copy" of Google's Knowledge Graph as a list of choices in a drop-down on a page, you can use the API to do a look-up after the Vision API responds with an ID.

Using webhooks with Google Analytics

I'm trying to integrate my CRM with Google Analytics to monitor lead changes (from lead to sell) and so on. As I understood, I need to use Google Measurement Protocol, to receive webhooks from CRM and translate it to Analytics Conversions.
But in fact, I don't really understand how to do it. I need to make some script, to translate webhook code to analytics, but where I need to place that script? Are there some templates? And so on.
So, If you know some tutorials/courses/freelancers to help me with intergrating webhooks with Analytics - I need your advice.
Example of webhook from CRM:
{
"leads": {
"status": {
"id": "25399013",
"name": "Lead title",
"old_status_id": "7039101",
"status_id": "142",
"price": "0",
"responsible_user_id": "102525",
"last_modified": "1413554372",
"modified_user_id": "102525",
"created_user_id": "102525",
"date_create": "1413554349",
"account_id": "7039099",
"custom_fields": [
{
"id": "427183",
"name": "Checkbox custom field",
"values": ["1"]
},
{
"id": "427271",
"name": "Date custom field",
"values": ["1412380800"]
},
{
"id": "1069602",
"name": "Checkbox custom field",
"values": ["0"]
},
{
"id": "427661",
"name": "Text custom field",
"values": ["Валера"]
},
{
"id": "1075272",
"name": "Date custom field",
"values": ["1413331200"]
}
]
}
}
}
"Webhook" is a fancy way of saying that your CRM can call a web based service whenever something interesting happens (i.e. the CRM can "hook" into a web based application). E.g. if a new lead is created you can call an url with the lead details as parameters.
Specifics depend on your CRM, but when you set up a webhook there should be a field to set a url; the script that evaluates the CRM data is located at the URL.
You have that big JSON thing as your example - No real way to tell without knowing your system, but I assume that is sent as request body. So in your script you evaluate the request body, extract the parameters you want to send to analytics (be mindful that you are not allowed to store personally identifiable information) and sent it via the measurement protocol as described in the documentation linked in the other answer.
Depending on the system you might even be able to call the measurement protocol without having a custom script in between (after all the measurement protocol is an url with a few parameters).
This is an awfully generic answer, but then the question is really broad.
I've done just this in my line of work.
You need to first decide your data model on how you would like the CRM data to look within Google Analytics. This could be just mapping Google Analytics' event category, event label, event action to your data, or perhpas using custom dimensions and metrics.
Then to make it most useful, you would like to be able to link the CRM activity of a customer to their online activity. You can do this if they login online. In that case, you can set the cid and/or uid of the user to your CRM id.
Then, if you send in a GA hit with the same cid/uid in your Measurement Protocol hit, you will link the online sessions with your offline CRM activity.
To make the actual record hit Google Analytics, you will need to program something that takes the CRM data and turns it into a Measurement Protocol hit, which is essentially just a URL with the correct parameters. Look here for reference: https://developers.google.com/analytics/devguides/collection/protocol/v1/reference
An example could be: http://www.google-analytics.com/collect?v=1&tid=UA-123456-1&cid=5555&t=pageview&dp=%2FpageA
We usually have this as a seperate process, that fires when the CRM data is written to its database (the webhook in your example). If its a lot of data, you should probably implement checks to see if the hit was sucessful, and caching in case the service is not online - you have an optional parameter that gives you 4 hours leeway in sending data.
Hope this gets you at least started.

Google Analytics Query Custom Channel Grouping

I am trying to pull a Custom Channel Grouping for Transaction IDs from Google Analytics. The marketing group has defined a couple of custom Channel Groupings in GA and they want me to pull these fields. I can not find any documentation anywhere which discusses this. It's not a custom dimension and it's not a custom variable. Has anyone else had to do this? Is it possible or do I have to re-implement the rules outside of GA?
Short answer: this is not currently possible (as of June 2015) in the Google Analytics API.
The best workaround I have found is to rebuild the channel grouping in the logic of the API query. For example, if you have a channel group that is defined in your custom grouping as "campaign contains shopping AND source == google," you can write that into the filters line of the optArgs call to the API.
This doesn't strike me as a sustainable, maintainable practice, however -- if the custom grouping is changed, you need to go back and change your code separately -- but it's the best solution available at the moment.
Example code is Javascript:
The filter doesn't seem to work for ga:channelGrouping, so 'filters':'ga:channelGrouping=Direct', fails with the error:
{
"error": {
"errors": [{
"domain": "global",
"reason": "invalidParameter",
"message": "Invalid value 'ga:channelGrouping=Direct' for filters parameter."
}],
"code": 400,
"message": "Invalid value 'ga:channelGrouping=Direct' for filters parameter."
}
}
But you can get the ga:channelGrouping back as a dimension:
gapi.client.analytics.data.ga.get({
'ids': 'ga:' + profileId,
'start-date': 'yesterday',
'end-date': 'today',
'dimensions':'ga:channelGrouping,ga:date, ga:landingPagePath, ga:pagePath',
'metrics': 'ga:entrances',
'sort': '-ga:date',
})
so you get it in the data:
[
/*Channel grouping*/
"(Other)",
"20150730",
"blah",
"vlah",
"7"
]
At the moment I'm planning on filtering the channel grouping in my own code once I get the result back rather than trying to get Google to do this for me. Basically because Google doesn't seem to support this right now...

Resources