Mixpanel delete user data using api - mixpanel

I want to delete all the data created for a user on mix panel . I have tried to use mixpanel engage api to delete the profile but i can still see the profile . Only profile properties is getting cleared .
curl --request POST
--url 'https://api.mixpanel.com/engage#profile-delete'
--header 'Accept: text/plain'
--header 'Content-Type: application/x-www-form-urlencoded'
--data 'data={
"$token": "YOUR_PROJECT_TOKEN",
"$distinct_id": "13793",
"$delete": "",
"$ignore_alias": false
}
'
What is $delete field used for (didn't find anything in the mixpanel documentation)
How can i delete everything created for a user via api (profile , event and properties)

You can't delete the data from mixpanel using the api. Instead refer to https://help.mixpanel.com/hc/en-us/articles/360000881023-Export-or-Delete-End-User-Data
If you only need to hide the data (not applicable if you for example need to delete it for GDPR reasons), you can overwrite it using the the import api, and add a field to it that you then filter out (i.e. deleted=true).
Events with identical values for (event, time, distinct_id, $insert_id) are considered duplicates and only one of them will be surfaced in queries.
Have a look at https://developer.mixpanel.com/reference/import-events to use this solution.

Related

drf_yasg and amazon api gateway returns json instead of html ui

I have setup my python api service using djangorestframework and I am using drf_yasg for showing swagger docs for my api.
Here is glance of setup:
schema_view = get_schema_view(
openapi.Info(
title='My API',
default_version='v1',
description='rest service',
terms_of_service='',
contact=openapi.Contact(email='my#email'),
license=openapi.License(name='BSD License'),
),
public=False,
)
urlpatterns = [
path('pyapi/weather/', include('apps.weather.urls')),
re_path(r'^pyapi/swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
re_path(r'^pyapi/swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
re_path(r'^pyapi/redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
Next I setup this api with amazon ec2 and stuff, and I am using Amazon API Gateway to access the api from containers.
Now the problem is when I try to access that using api gateway domain, it returns swagger JSON instead of HTML.
I tried several things like setting Content-Type mappings in method response and integration response but nothing works.
In my local machine it shows html as expected, so I am suspecting problem is in my gateway settings.
I highly appreciate if someone can help!
Ok I solved mystery!
After tons of tries and looking here and there, I found there was problem in API Gateway Request header setting.
Actually drf-yasg also kind of weird let me tell you why.
After setting up urls as I shown in first image, if you try to access http://localhost:8000/pyapi/swagger/ it shows UI perfectly.
At that time value of request header is Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Now same URL if you pass request header "Accept: application/json" then istead of showing html UI, it shows swagger JSON! wutt!!
That I found in Amazon API Gateways's test method's output. It was by default sending "Accept: application/json" and thats why I was always getting swagger.json in output. That was showstopper thing!
I changed it to Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9 and now I could see UI perfectly!
I hope this will save time of many other people like me who are new to this kind of stuff!

How to get dropdown list key value using sugacrm restful api?

I am a new CodeIgniter framework developer. I have created a sample program for CodeIgniter using SugarCRM library rest API concepts. I havintegratedte and connect SugarCRM rest api working. I ha to get dropdown list item value using rest api. Please help me how to get dropdown list value
Thanks
To get a list of enum values you have to make an HTTP request to the sugarcrm. Use a GET verb to request data from:
https://<name>.sugarondemand.com//rest/<api_version>/<module_name>/enum/<enum_name>
Let's assume that name = flex, api_version = 11_6, module_name = Leads, enum_name = lead_soruce then the full url value should be
https://flex.sugarondemand.com/rest/v11_6/Leads/enum/lead_source
And the full get request (with curl):
curl -X GET -H Cache-Control:no-cache -H "Oauth-token":"<access_token>" https://flex.sugarondemand.com/rest/v11_6/Leads/enum/lead_source
If you don't have the access token then use the following request to get the access and the refresh tokens
curl -X POST -H Cache-Control:no-cache -H "Content-Type: application/json" -d '{
"grant_type":"password",
"client_id":"sugar",
"client_secret":"",
"username":"<username>",
"password":"<user_password>",
"platform":"custom_api"
}' https://<client_name>.sugarondemand.com/rest/v11_6/oauth2/token

Not able to create Grafana User using HTTP API

I am trying to create the grafana users using API's and this is what I tried.
curl -XPOST -H “Content-Type: application/json” -d ‘{“name”:“User”,“email”:“user#graf.com”,“login”:“user”,“password”:“password”}’ http://admin:admin#localhost:3000/api/admin/users
got this: [{“classification”:“DeserializationError”,“message”:“invalid character ‘\’’ looking for beginning of value”},{“fieldNames”:[“Password”],“classification”:“RequiredError”,“message”:“Required”}]
Can any one help me?
I followed the http://docs.grafana.org/http_api/user/ documentation and now I am able to create the users and able to use all grafana api's
Here is the answer for my question
import requests
url='http://admin:admin#localhost:3000/api/admin/users'
data='''{
"name":"tester",
"email":"test#graadff.com",
"login":"tester",
"password":"test#123"
}'''
headers={"Content-Type": 'application/json'}
response = requests.post(url, data=data,headers=headers)
print (response.text)

How do I find the API endpoint of a lambda function?

I have a Lambda function that has an exposed API Gateway endpoint, and I can get the URL for that via the AWS console. However, I would like to get that URL via API call. Neither the Lambda API documentation nor the API Gateway documentation seem to have that information (or perhaps I've missed it), so is this even possible in the first place?
I don't really understand the above answer (maybe it's outdated?).
The absolute easiest way:
Choose "API Gateway" under "Services" in AWS.
Click on your API.
Click on "Stages".
Choose the stage you want to use
Now you can see the entire URL very visible inside a blue box on the top with the heading "Invoke URL"
Your API Gateway endpoint URL doesn't get exposed via an API call. However, since the URL of the API follows a certain structure, you could get all the necessary pieces and create the URI within your code.
https://API-ID.execute-api.REGION.amazonaws.com/STAGE
You could use apigateway:rest-apis to get your API-ID and restapi:stages to get the stage corresponding identifier.
I'm not seeing a direct answer to the OP's question (get endpoint URL using API). Here's a snippet of Python code that I hope will guide the way, even if you're using other language bindings or the CLI. Note the difference in approach for getting the internal endpoint vs getting any associated custom domain endpoints.
import boto3
apigw = boto3.client('apigateway')
def get_rest_api_internal_endpoint(api_id, stage_name, region=None):
if region is None:
region = apigw.meta.region_name
return f"https://{api_id}.execute-api.{region}.amazonaws.com/{stage_name}"
def get_rest_api_public_endpoints(api_id, stage_name):
endpoints = []
for item in apigw.get_domain_names().get('items',[]):
domain_name = item['domainName']
for mapping in apigw.get_base_path_mappings(domainName=domain_name).get('items', []):
if mapping['restApiId'] == api_id and mapping['stage'] == stage_name:
path = mapping['basePath']
endpoint = f"https://{domain_name}"
if path != "(none)":
endpoint += path
endpoints.append(endpoint)
return endpoints
Go to you lambda main page -> Click on "Application" [Function Overview section] -> Resource section -> LambdaAPIDefinition -> Stages tab -> [Select required stage] -> [Invoke URL] You can see the api endpoint visible.
Following up on #larschanders comment, if you create the gateway using CloudFormation, the endpoint URL is surfaced as one of the stack outputs.
If you use CloudFormation you can get this with Python and Boto3:
import boto3
cloudformation = boto3.resource('cloudformation')
stack = cloudformation.Stack(name=stack_name)
api_url = next(
output['OutputValue'] for output in stack.outputs
if output['OutputKey'] == 'EndpointURL')
This is from a working example of a REST service using Chalice that I put on GitHub. Here's a link to the pertinent code, in context: aws-doc-sdk-examples.
If you know the function name, you can get the apigw endpoint by fetching the policy:
aws lambda get-policy --function-name <name> \
| jq -r '.Policy | fromjson | .Statement[0].Condition.ArnLike."AWS:SourceArn"'
THen it's just a matter of extracting the api_id and construct the endpoint like Jurgen suggested
A Script is the only answer as of now
But if someone wants to do purely on CLI using commands here is the long way (though I am a very beginner in AWS and I tried this during learning Lambda basics), maybe there is a much better way...
The format of Invoke-URL of the endpoint is something like this
https://YOUR-REST-API-ID.execute-api.REGION.amazonaws.com/STAGE/RESOURCE
// get YOUR-REST-API-ID e.g., 0w12zl28di
aws apigateway get-rest-apis | jq -r '.items[] | [.id, .name] | #tsv'
// get REGION using Lambda_function_name e.g., ap-east-1
aws lambda get-function-configuration --function-name YOUR_LAMBDA_FUNCTION_NAME | jq '.FunctionArn | split(":")[3]'
// get STAGE e.g., dev
aws apigateway get-stages --rest-api-id YOUR-REST-API-ID | jq -r '.item[] | [.stageName] | #tsv'
// get RESOURCE e.g., users
aws apigateway get-resources --rest-api-id YOUR-REST-API-ID | jq '.items[] | [.id, .path]'
// finally put your pieces in this way
https://0w12zl28di.execute-api.ap-east-1.amazonaws.com/dev/users
Note you have to install jq parser (if you don't have it already)
https://stedolan.github.io/jq/download/
I was using Linux on top of Windows, so I need to do it in this way
curl -L -o /usr/bin/jq.exe https://github.com/stedolan/jq/releases/latest/download/jq-win64.exe
To very precise Go to AWS Console search :
Lambda under services
Search the Function name which are looking for.
In Function overview, you will find API GATEWAY (Click on this)
Under API GATEWAY, click on Details (down arrow)
Under Details, you will find all the details like
API endpoint :
API type :
Authorization :
Method :
Resource path :
Stage :

How to manually send HTTP POST requests from Firefox or Chrome browser

I want to test some URLs in a web application I'm working on. For that I would like to manually create HTTP POST requests (meaning I can add whatever parameters I like).
Is there any functionality in Chrome and/or Firefox that I'm missing?
I have been making a Chrome app called Postman for this type of stuff. All the other extensions seemed a bit dated so made my own. It also has a bunch of other features which have been helpful for documenting our own API here.
Postman now also has native apps (i.e. standalone) for Windows, Mac and Linux! It is more preferable now to use native apps, read more here.
CURL is awesome to do what you want! It's a simple, but effective, command line tool.
REST implementation test commands:
curl -i -X GET http://rest-api.io/items
curl -i -X GET http://rest-api.io/items/5069b47aa892630aae059584
curl -i -X DELETE http://rest-api.io/items/5069b47aa892630aae059584
curl -i -X POST -H 'Content-Type: application/json' -d '{"name": "New item", "year": "2009"}' http://rest-api.io/items
curl -i -X PUT -H 'Content-Type: application/json' -d '{"name": "Updated item", "year": "2010"}' http://rest-api.io/items/5069b47aa892630aae059584
Firefox
Open Network panel in Developer Tools by pressing Ctrl+Shift+E or by going Menubar -> Tools -> Web Developer -> Network. Select a row corresponding to a request.
Newer versions
Look for a resend button in the far right. Then a new editing form would open in the left. Edit it.
Older versions
Then Click on small door icon on top-right (in expanded form in the screenshot, you'll find it just left of the highlighted Headers), second row (if you don't see it then reload the page) -> Edit and resend whatever request you want
Forget the browser and try CLI. HTTPie is a great tool!
CLI HTTP clients:
HTTPie
Curlie
HTTP Prompt
Curl
wget
If you insist on a browser extension then:
Chrome:
Postman - REST Client (deprecated, now has a desktop program)
Advanced REST client
Talend API Tester - Free Edition
Firefox:
RESTClient
Having been greatly inspired by Postman for Chrome, I decided to write something similar for Firefox.
REST Easy* is a restartless Firefox add-on that aims to provide as much control as possible over requests. The add-on is still in an experimental state (it hasn't even been reviewed by Mozilla yet) but development is progressing nicely.
The project is open source, so if anyone feels compelled to help with development, that would be awesome: https://github.com/nathan-osman/Rest-Easy
* the add-on available from http://addons.mozilla.org will always be slightly behind the code available on GitHub
You specifically asked for "extension or functionality in Chrome and/or Firefox", which the answers you have already received provide, but I do like the simplicity of oezi's answer to the closed question "How can I send a POST request with a web browser?" for simple parameters. oezi says:
With a form, just set method to "post"
<form action="blah.php" method="post">
<input type="text" name="data" value="mydata" />
<input type="submit" />
</form>
I.e., build yourself a very simple page to test the POST actions.
I think that Benny Neugebauer's comment on the OP question about the Fetch API should be presented here as an answer since the OP was looking for a functionality in Chrome to manually create HTTP POST requests and that is exactly what the fetch command does.
There is a nice simple example of the Fetch API here:
// Make sure you run it from the domain 'https://jsonplaceholder.typicode.com/'. (cross-origin-policy)
fetch('https://jsonplaceholder.typicode.com/posts',{method: 'POST', headers: {'test': 'TestPost'} })
.then(response => response.json())
.then(json => console.log(json))
Some of the advantages of the fetch command are really precious:
It's simple, short, fast, available and even as a console command it stored on your chrome console and can be used later.
The simplicity of pressing F12, write the command in the console tab (or press the up key if you used it before) then press Enter, see it pending and returning the response is what making it really useful for simple POST requests tests.
Of course, the main disadvantage here is that, unlike Postman, this won't pass the cross-origin-policy, but still I find it very useful for testing in local environment or other environments where I can enable CORS manually.
Here's the Advanced REST Client extension for Chrome.
It works great for me -- do remember that you can still use the debugger with it. The Network pane is particularly useful; it'll give you rendered JSON objects and error pages.
For Firefox there is also an extension called RESTClient which is quite nice:
RESTClient, a debugger for RESTful web services
It may not be directly related to browsers, but Fiddler is another good software.
You could also use Watir or WatiN to automate browsers. Watir is written for Ruby and Watin is for .NET languages. I am not sure if it's what you are looking for, though.
http://watin.sourceforge.net/
http://watir.com/
There have been some other clients born since the rise of Postman that is worth mentioning here:
Insomnia: with both desktop application and Chrome plugin
Hoppscotch: previously known as Postwoman, and with a Chrome plugin available as well. You can also make it work locally with docker if you want to get funny
Paw: if you are on Mac
Advanced Rest Client: already mentioned as a Chrome plugin, but it is worth pointing out that it also has a desktop application
soapUI: written in Java and with lots of testing functionality
Boomerang: yet another way to test APIs. It comes with SOAP integration and it also has a Chrome plugin available
Thunder Client: if you use VS Code as your text editor then you should go and check out this awesome extension
Try Runscope. A free tool sampling their service is provided at https://www.hurl.it/.
You can set the method, authentication, headers, parameters, and body. The response shows status code, headers, and body. The response body can be formatted from JSON with a collapsable hierarchy.
Paid accounts can automate test API calls and use return data to build new test calls.
COI disclosure: I have no relationship to Runscope.
Check out http-tool for Firefox...
Aimed at web developers who need to debug HTTP requests and responses.
Can be extremely useful while developing REST based API.
Features:
GET
HEAD
POST
PUT
DELETE
Add header(s) to request.
Add body content to request.
View header(s) in response.
View body content in response.
View status code of response.
View status text of response.
So it occurs to me that you can use the console, create a function, and just easily send requests from the console, which will have the correct cookies, etc.
so I just grabbed this from here: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#supplying_request_options
// Example POST method implementation:
async function postData(url = '', data = {}, options = {}) {
// Default options are marked with *
let defaultOptions = {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(data) // body data type must match "Content-Type" header
}
// update the default options with specific options (e.g. { "method": "GET" } )
const requestParams = Object.assign(defaultOptions, options);
const response = await fetch(url, requestParams);
return response.text(); // displays the simplest form of the output in the console. Maybe changed to response.json() if you wish
}
IF YOU WANT TO MAKE GET REQUESTS, you can just put them in your browser address bar!
if you paste that into your console, then you can make POST requests by repeatedly calling your function like this:
postData('https://example.com/answer', { answer: 42 })
.then(data => {
console.log(data); // you might want to use JSON.parse on this
});
and the server output will be printed in the console (as well as all the data available in the network tab)
This function assumes you are sending JSON data. If you are not, you will need to change it to suite your needs
You can post requests directly from the browser with ReqBin.
No plugin or desktop application is required.
I tried to use postman app, had some auth issues.
If you have to do it exclusively using browser, go to network tab, right click on the call, say edit and send response. There is a similar ans on here about Firefox, this right click worked for me on edge and pretty sure it would work for chrome too
Windows CLI solution
In PowerShell you can use Invoke-WebRequest. Example syntax:
Invoke-WebRequest -Uri http://localhost:3000 -Method POST -Body #{ username='clever_name', password='hunter2' } -UseBasicParsing
On systems without Internet Explorer, you need the -UseBasicParsing flag.
The question being 12 years old now, it is easy to understand why the author asked a solution for Firefox or Chrome back then. After 12 years though, there are also other browsers and the best one which does not involve any add-ons or additional tools is Microsoft Edge.
Just open devtools (F12) and then Network Console tab (not the Network or Console tab. Click on + sign and open it, if it is not visible.).
And here is the official guide:
https://learn.microsoft.com/en-us/microsoft-edge/devtools-guide-chromium/network-console/network-console-tool
Have fun!

Resources