I'm new in rest api and i'm trying to use the api rest to associate file to object:
curl -X POST \
-H "X-Parse-Application-Id: qS0KL*9lFLE**S3VMk" \
-H "X-Parse-REST-API-Key: nh3***MhcKJIfIt1Gm" \
-H "Content-Type: application/json" \
-d '{
"name": "Andrew",
"picture": {
"name": "...profile.png",
"__type": "File"
}
}' \
https://api.parse.com/1/classes/PlayerProfile
Can anyone explain me how to set the ajax call?And what is "name":"andrew"?Is this a column named andrew in my player profile?
This is my implementation of api,but the server responded me bad request 400:
$.ajax({
type: 'POST',
headers: {'X-Parse-Application-Id':'qS0KLMx5h9lFLG**yhM9EEPiTS3VMk','X-Parse-REST-API-
Key':'nh3G8D**hcKJIfIt1Gm','Content-Type': 'application/json'},
url: "https://api.parse.com/1/users",
data: {
"username": "francesco",
"picture": {
"name": "b3b47ce2-62dc-4861-a0ad-79cfffe9b07a-foto ste.jpg",
"__type": "File"
}
},
contentType: "application/json",
success: function(data) {
console.log(data );
},
error: function(data) {
console.log("ko" );
}
});
May the api -d is wrong in my implementation.What's means -d in curl?
The example in the guide shows how you can create a new PlayerProfile object and associate it with a File in a single request. Since you want to update an existing User (and not create a new one), you'll need to use the Update REST API request format. Use PUT instead of POST, then specify which user you're referring to by appending the object id to the endpoint URL: https://api.parse.com/1/users/{objectId}.
Related
I've been trying to run a pipeline for a particular branch of the repository I'm using.
In the UI, there is a convenient option, but I don't understand what to try in the request.
No matter what I do I always run from master.
How do I change that? I tried filling out the repository parameters but to no avail: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run%20pipeline?view=azure-devops-rest-6.0#repositoryresourceparameters
Here is an example request:
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"previewRun": true,
"resources": {
"repositories": {
"refName": "refs/heads/<redacted>"
}
},
"runParameters":
{
"namespace" : "<redacted>",
"image" : "<redacted>",
"tag" : "<redacted>",
"package" : "<redacted>",
"version" : "8.4.4"
}
}'
From your screenshot, it seems that you are using the YAML pipeline.
I have tested your example , and the root cause of this issue is that the request body(data-raw) has some issues.
You could try my sample
curl --location --request POST 'https://dev.azure.com/<redacted>/<redacted>/_apis/pipelines/<redacted>/runs?api-version=6.0-preview.1' \
--header 'Authorization: Basic <redacted>' \
--header 'Content-Type: application/json' \
--header 'Cookie: VstsSession=<redacted>' \
--data-raw '{
"stagesToSkip":[],
"resources":
{
"repositories":
{
"self":{"refName":"refs/heads/{Branchname}"}
}
},
"templateParameters":
{
"namespace":"{value}",
"image":"{value}",
"tag":"{value}",
"package":"{value}",
"version":"{value}"
},
"variables":{}
}'
Result:
For Http Request (you can test it with Postman)
1. Get pipeline api url like this
https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=7.1-preview.1
Source: https://learn.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/run-pipeline?view=azure-devops-rest-7.1
Fill in your organization, project and pipelineId.
(all of this can be found in the link when you open your pipeline definition in Azure DevOps)
2. Add Basic Auth headers
key: Authorization, value:"Basic [your azure Person Access Token from Azure Dev Ops with Access to Pipeline goes here]"
Should look like this
"Basic OndzNWdz43FKfjdi98hjKDJFH8kkg9854HJKHF9D8RFEHui4387lkNXE="
And set content type to application/json
like this
key: Content-Type, value: application/json
3. Put this JSON Into Raw Body
{
"templateParameters":{
"inputName":"johnsmith"
},
"resources":{
"repositories":{
"self":{
"refName":"refs/heads/feature/#JIRATask01_Blabla"
}
}
},
"variables":{
}
}
Replace refName value with branch you want to run the pipeline for.
If you have multiple repo pipeline look into this topic (but i haven't tested that solution):
Azure DevOps API to Trigger Multi Repo changing branches
In Sandbox, the logged-in user needs to be a member of a group to register data products or apps.
How can I add my user to a group?
You, as user, are an identity of type Person. A Group is also a type of identity in Platform of Trust.
A Person must be linked to a Group with MemberOf type of link.
Using Identity API, you can create a Group type identity and connect your own user identity to the group with a MemberOf type link.
To create a group, run the following cURL command:
curl -i -X POST \
-H "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9eyJzY29w...DVs5aaf" \
-H "Content-Type: application/json" \
-d \
"{
"context": "https://standards.oftrust.net/v2/Context/Identity/Group/",
"type": "Group",
"data": {
"name": "Company Oy"
}
}" "https://api-sandbox.oftrust.net/identities/v1"
On Success, you'll get the following response including the ID of the created group.
Next, you need to link your user identity to the created group identity with a MemberOf type link.
option1: This post in StackOverflow discusses how to obtain the current logged-in user's ID.
OR,
option2:
Start with getting your user ID (you need to be logged-in into the Sandbox) using /me end
point of Login API
Request:
curl -i -X GET \
-H "Authorization: Bearer eyJ0eXAi...hdEsJLNGV2YA" \
"https://api-sandbox.oftrust.net/me"
Response:
HTTP/1.0 200
{
"#context": "https://standards.oftrust.net/v2/Context/Identity/LegalParty/Person/",
"#type": "Person",
"#id": "33237067-14c3-4801-9e50-bf08406406e2",
"email": "user#example.com",
"role": "developer",
"firstName": "Anna",
"lastName": "Bar"
}
Then make a POST request to Identity API with Identity IDs of your user and the created group as parameters:
curl -i --request POST \
--url https://api-sandbox.oftrust.net/identities/v1/{fromIdentityId}/link/{toIdentityId} \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9eyJzY29w...DVs5aaf' \
--header 'content-type: application/json' \
--data '{
"context": "https://standards.oftrust.net/v2/Context/Link/Role/MemberOf/",
"type": "MemberOf"
}'
Remember to set the parameters as the following:
fromIdentityId = ID of your own user
toIdentityID = ID of the created group above.
On success, you should receive the following response:
HTTP/1.0 201
{
"#context": "https://standards.oftrust.net/v2/Context/Link/Role/MemberOf/",
"#type": "MemberOf",
"#id": "be7a2c57-03d8-46f4-aaf0-2b1ca118ef5c",
"from": "8ac7494b-b7bc-4a63-a253-4b9b1887b262",
"to": "a6b5a74e-bd98-4c9b-9561-932877258833",
"data": {},
"metadata": {
"createdAt": "2019-09-12T09:49:24+00:00",
"createdBy": "33237067-e72c-4f26-b78b-9f9e234b2e7d",
"updatedAt": "2019-09-12T09:49:24+00:00",
"updatedBy": "33237067-e72c-4f26-b78b-9f9e234b2e7d"
}
}
Now you will bee able to use the created group to register data products and apps in Platform of Trust.
Alternatively, you can use world-sandbox.oftrust.net to create your group identity using the UI. Simply save the group ID that appears in the S-alert.
Checkout Identity API documentation here.
You can also use our Insomnia Workspace and Guide to execute chain request to create a Group.
The documentation and help for this particular Segment.io is limited and sparse, so I hope it's OK to ask in here.
I have just set up a Segment.io workspace and a HTTP API source
Per the docs, I sent some POST requests (with Postman) to the https://api.segment.io/v1/track and https://api.segment.io/v1/page endpoints. The requests were structured like this:
curl -X POST \
https://api.segment.io/v1/track \
-H 'Accept: */*' \
-H 'Authorization: My4w3s0m3k3y' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Host: api.segment.io' \
-H 'Postman-Token: 474d7fbe-15af-43d2-b629-61e15945e662,2c3d5fbe-2c09-4fe6-b7ea-a04e3221201b' \
-H 'User-Agent: PostmanRuntime/7.11.0' \
-H 'accept-encoding: gzip, deflate' \
-H 'cache-control: no-cache' \
-H 'content-length: 117' \
-d '{
"userId": "abc123",
"event": "My tests",
"properties": {
"name": "test 1"
}
}'
which all returned a 200 response and the following message:
{
"success": true
}
However, when I got to my dashboard, no events have been recorded.
The debugger is also empty
What am I missing here?
It looks like your write key isn't base64 encoded. When you encode your write key, remember to add the : at the end of it, before it's encoded.
Also, for the Authorization key:value, be sure to add Basic before the encoded write key. So your Authorization key:value would look like:
Authorization: Basic {encoded write key}
An example from the segment documentation:
In practice that means taking a Segment source Write Key,'abc123', as the username, adding a colon, and then the password field is left empty. After base64 encoding 'abc123:' becomes 'YWJjMTIzOg=='; and this is passed in the authorization header like so: 'Authorization: Basic YWJjMTIzOg=='.
I have been dealing with the same issue.
I found the solution as Todd said.
You should add a header Authorization: Basic + base64 encoding write key.
So, you look for the Segment source setting and get the write key.
After that, i have used an online base64 encoding tool to encode my write key.
Finally, you should add this header (Authorization) with 'Basic' and the encoded write key.
You should be able to see the tracked event in the Debugging panel in Segment web page.
I hope this helps!
You can try this code
const { promisify } = require("util");
var Analytics = require("analytics-node");
var analytics = new Analytics("xxxxxxxxxxxxxxxxxxxxxxx", {
flushAt: 1,
});
const [identify, track] = [
analytics.identify.bind(analytics),
analytics.track.bind(analytics),
].map(promisify);
console.log("user id: ", req.body.event.app_user_id);
let app_user_id = req.body.event.app_user_id;
let period_type = req.body.event.period_type;
let expiration_at_ms = req.body.event.expiration_at_ms;
let ret = "Initial";
try {
await identify({
userId: app_user_id,
traits: {
period_type: period_type,
expiration_at_ms: expiration_at_ms,
},
});
ret = "Done : Sengment done";
} catch (err) {
console.log("err: ", err);
ret = "Error : " + err;
}
return {
rafsan: ret,
};
Try to clear your browser's cache or use a different browser. I had the same problem and worked for me.
Hope this helps.
Good morning, guys. I'm still new to Loopback, and have a feeling that I'm missing something, but not sure where and what to find, so advice would be helpful.
I have an app. I'm using local authentication with standard ACL.
I have few methods that open only for $owner, and few that open for $authenticated. I'm using few POST requests within the app to retrieve data, and every time I get 401 error. If use GET request, all I have to do is to include an access token id into the url like that url?access_token=jjkdfsjjkj334.
I have a feeling that there is a some sort similar of trick for POST requests.
Any help would be appreciated.
For the post request pass the access_token as the "Authorization" header in the respective post call.
request({url: url, json: true, headers: {'Authorization': 'access-token-value'}}, function (err, res, responseJson) {
console.log(responseJson);
});
You also specify other headers also, like Accept-type etc.
If you had a model called Test with the following ACL:
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "DENY"
},
{
"principalType": "ROLE",
"principalId": "$authenticated",
"permission": "ALLOW",
"property": "create"
}
You should be able to make the following POST request:
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{}" "http://localhost:3000/api/Tests?access_token=cor7DDfUKoFSI6DzgCezQzoKFOuSmpLYzSF85xA8QXePkbFAGDKjjp7QwaVlP11B"
I always like to use the component explorer to test out what works and what doesn't. My guess is that something isn't set up properly in your ACL.
How do I use POST with Ansbile
curl -k -X POST -H "Accept:application/json" -H "Content-Type:application/json"-u user:A231212123432 "https://www.example.com"
Request Body
{
"a":"1"
"b":"2"
"c":"3"
}
According to the docs it would work like this:
- url: https://www.example.com
method: POST
user: user
password: A231212123432
HEADER_Content-Type: "application/json"
body: '{ "a":"1" "b":"2" "c":"3" }'