Pre-request Postman script for Swagger petstore - postman-pre-request-script

Learning Postman, and got some trouble making DELETE call with POST call in pre-request script. Aim is to make only DELETE call without having to make POST call each time. Endpoint is swagger petstore. So, DELETE is for deleting pet by ID and POST (in pre-request) is for creating a pet with required ID.
When I make a POST call separately - it works okay. When POST call is in pre-request - pet is not created. What may be wrong?
Body of separated POST call:
{
"name": "Volodya",
"photoUrls": [
"www.parrots.org/photo1"
],
"id": 202207,
"category": {
"id": 12675,
"name": "Buzza"
},
"tags": [
{
"id": 5566,
"name": "A Scary Mummy"
}
],
"status": "yes"
}
image of POST call
And my pre-request code:
const createPet = {
url: 'https://petstore.swagger.io/v2/pet/202207',
method: 'POST',
header: {
'Content-Type': 'application/json',
'Accept': '*/*'
},
body: {
mode: 'raw',
raw: JSON.stringify({
"name": "Volodya",
"photoUrls": [
"www.parrots.org/photo1"
],
"id": 202207,
"category": {
"id": 12675,
"name": "Buzza"
},
"tags": [
{
"id": 5566,
"name": "A Scary Mummy"
}
],
"status": "yes"
})
}
};
pm.sendRequest(createPet);
Image of pre-request
Thanks for your help.

Found the answer =)
The problem was simple - mistake in endpoint. In original POST request endpoint was https://petstore.swagger.io/v2/pet. But in pre-request code endpoint was https://petstore.swagger.io/v2/pet/202207. So that was the reason.

Related

Dynamics 365 API v2: Adding sales lines to an existing sales order

I am trying to add sales lines to an existing sales order using the standard API included with dynamics 365 business central. However I cannot find the correct syntax on the api request to accomplish this.
I have tried posting to the companies({id})/salesOrderLines endpoint, and the companies({id})/salesOrder({id})/salesOrderLines endpoint but no matter how I try to work my request I always get the "Invalid Request Body" error.
Here is an example of the request I sent to the companies({id})/salesOrderLines endpoint:
Here is my request body:
[
{
"id": "e92c39cb-f552-4d4f-b680-ad7ded2949d0",
"documentId": "e80573b0-9c8b-ed11-bfba-001dd8b71ee3",
"lineType": "Item",
"lineObjectNumber": "H10-110013",
"quantity": 1
},
{
"id": "e92c39cb-f552-4d4f-b680-ad7ded2949d0",
"documentId": "e80573b0-9c8b-ed11-bfba-001dd8b71ee3",
"lineType": "Item",
"lineObjectNumber": "H10-112117",
"quantity": 1
}
]
Here is the response I get back:
"{"error":{"code":"BadRequest","message":"Invalid Request
Body CorrelationId: 241e540a-5af5-4516-83f2-fbc035f80389."}}"
I am able to post a sales order and its lines simultaneously using deep requests but with larger orders they hit the request limit and I need a way of splitting up the lines.
salesOrderLines endpoint expects an object and does not accept collections, so best you can do here is post each line in a separate request.
Request body would look like this:
{
"lineType": "Item",
"lineObjectNumber": "H10-110013",
"quantity": 1
}
id and documentId can be added to the request, but not really required.
Another option is to send the request on the $batch endpoint as described in the docs here: https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/webservices/use-odata-batch
POST http://bc21-dev:7048/bc/api/v2.0/$batch
{
"requests": [
{
"method": "POST",
"url": "http://bc21-dev:7048/bc/api/v2.0/salesOrders(dd3585b3-dd6c-ed11-81b4-6045bd8e5172)/salesOrderLines",
"headers": {
"Company": "CRONUS International Ltd.",
"Content-Type": "application/json"
},
"body": {
"lineType": "Item",
"lineObjectNumber": "1920-S",
"quantity": 2,
"unitPrice": 420.4
}
},
{
"method": "POST",
"url": "http://bc21-dev:7048/bc/api/v2.0/salesOrders(dd3585b3-dd6c-ed11-81b4-6045bd8e5172)/salesOrderLines",
"headers": {
"Company": "CRONUS International Ltd.",
"Content-Type": "application/json"
},
"body": {
"lineType": "Item",
"lineObjectNumber": "1952-W",
"quantity": 1,
"unitPrice": 183.12
}
}
]
}

List users as non admin with custom fields

As per the documentation, I should be able to get a list of users with a custom schema as long as the field in the schema has a value of ALL_DOMAIN_USERS in the readAccessType property. That is the exact set up I have in the admin console; Moreover, when I perform a get request to the schema get endpoint for the schema in question, I get confirmation that the schema fields are set to ALL_DOMAIN_USERS in the readAccessType property.
The problem is when I perform a users list request, I don't get the custom schema in the response. The request is the following:
GET /admin/directory/v1/users?customer=my_customer&projection=full&query=franc&viewType=domain_public
HTTP/1.1
Host: www.googleapis.com
Content-length: 0
Authorization: Bearer fakeTokena0AfH6SMD6jF2DwJbgiDZ
The response I get back is the following:
{
"nextPageToken": "tokenData",
"kind": "admin#directory#users",
"etag": "etagData",
"users": [
{
"externalIds": [
{
"type": "organization",
"value": "value"
}
],
"organizations": [
{
"department": "department",
"customType": "",
"name": "Name",
"title": "Title"
}
],
"kind": "admin#directory#user",
"name": {
"fullName": "Full Name",
"givenName": "Full",
"familyName": "Name"
},
"phones": [
{
"type": "work",
"value": "(999)999-9999"
}
],
"thumbnailPhotoUrl": "https://photolinkurl",
"primaryEmail": "user#domain.com",
"relations": [
{
"type": "manager",
"value": "user#domain.com"
}
],
"emails": [
{
"primary": true,
"address": "user#domain.com"
}
],
"etag": "etagData",
"thumbnailPhotoEtag": "photoEtagData",
"id": "xxxxxxxxxxxxxxxxxx",
"addresses": [
{
"locality": "Locality",
"region": "XX",
"formatted": "999 Some St Some State 99999",
"primary": true,
"streetAddress": "999 Some St",
"postalCode": "99999",
"type": "work"
}
]
}
]
}
However, if I perform the same request with a super admin user, I get an extra property in the response:
"customSchemas": {
"Dir": {
"fieldOne": false,
"fieldTwo": "value",
"fieldThree": value
}
}
My understanding is that I should get the custom schema with a non admin user as long as the custom schema fields are set to be visible by all domain users. This is not happening. I opened a support ticket with G Suite but the guy that provided "support", send me in this direction. I believe this is a bug or maybe I overlooked something.
I contacted G Suite support and in fact, this issue is a domain specific problem.
It took several weeks for the issue to be addressed by the support engineers at Google but it was finally resolved. The behaviour is the intended one now.

Autodesk BIM360: Folder Creation returns 400 Bad request

I called the POST-Folder Method via Postman with a JSON body according to this example. But I only receive the message "400 Bad Request" without any explanations. This is what my request looks like:
The service adress:
https://developer.api.autodesk.com/data/v1/projects/b.5823d0b2-0000-0000-00/commands
The HTTP-header
Authorization: Bearer 2_legged_token
Content-Type: application/vnd.api+json
The JSON-Body
{
"jsonapi": {
"version": "1.0"
},
"data": {
"type": "commands",
"attributes": {
"extension": {
"type": "commands:autodesk.core:CreateFolder",
"version": "1.0.0",
"data": {
"requiredAction": "create"
}
}
},
"relationships": {
"resources": {
"data": [
{
"type": "folders",
"id": "1"
}
]
}
}
},
"included": [
{
"type": "folders",
"id": "1",
"attributes": {
"name": "test",
"extension": {
"type": "folders:autodesk.bim360:Folder",
"version": "1.0.0"
}
},
"relationships": {
"parent": {
"data": {
"type": "folders",
"id": "urn:adsk.wipprod:fs.folder:co.Ai*****"
}
}
}
}
]
}
The response
{
"jsonapi": {
"version": "1.0"
},
"errors": [
{
"id": "f1266e76-a37e-400b-bff6-de84b11cdb00",
"status": "400",
"detail": "BadRequest"
}
]
}
What I have found out so far:
The project id is right. When I take a wrong project id I receive a different error.
The Json is also valid.
When I take a (surely) wrong parent-folder-urn I'll receive the same error message. So maybe this is a wrong urn format or something?
As of now, you can create a BIM 360 Docs Folder with commands endpoints, as you pointed out. For that you can use:
3-legged token
2-legged token with x-user-id header, this should contain the Autodesk User ID obtained, for instance, from GET users#me endpoint
"pure" 2-legged token will return bad request (as of August/2017)
Sorry about the documentation, the endpoint to create BIM 360 Docs folder via Commands was released a couple weeks back and we're just finishing to write the documentation.

How to get included values of jsonapi on a router with ember-data?

I'm using jsonapi directives to make a connection between ember.js app and an API. I have a track that could have like 50 or more comments and I need to load them on a route to perform some logic.
This is and example response of the API:
{
"data": {
"id": 1,
"type": "track",
"attributes": {
"name": "XPTO"
},
"relationships": {
"comment": {
"data": [
{"id": 1, "type": "comment"}
]
}
}
},
"include": [
{
"id": 1,
"type": "comment",
"attributes": {
"text": "Lorem ipsum..."
}
}
]
}
Now imagine it with 50 comments, this would be very consuming to make a request for each call. If I do it in a view with an each loop, it doesn't make all the requests, but it I try to access it in a Route, it will make all the requests. How do I achieve that with the following code?
this.store.findRecord('track', 1).then((t) => {
// logic here
// I tried this but it would make all the requests too
t.get('comments');
})
U can use property "coalesceFindRequests" in your adapter
coalesceFindRequests: true
If you set coalesceFindRequests to true it will instead trigger the following request:
GET /comments?ids[]=1&ids[]=2
so this makes only one call for all the comments.
Note: Requests coalescing rely on URL building strategy. So if you
override buildURL in your app groupRecordsForFindMany more likely
should be overridden as well in order for coalescing to work.

Delete record Libcloud (GoDaddy api)

I try to implement delete method for Record delate-record, but its my first time to use python and this api.
The GoDaddy API doesn't have a delete record method, so this functionality is not exposed in the driver.
https://developer.godaddy.com/doc#!/_v1_domains/recordReplace
The driver could offer the 'replace records in zone' method, which would allow you to fetch the current list of records, and then set the new list minus the record you want to remove. But that feature is not implemented and quite risky.
First,
Send a GET request to https://api.godaddy.com/v1/domains/{DOMAIN}/records
Then, Enumerate over all records of API Response (JSON Array) and prepare new data by removing the one that needs to be deleted.
API Response (SAMPLE)
[
{
"data": "192.168.1.1",
"name": "#",
"ttl": 600,
"type": "A"
},
{
"data": "ns1.example.com",
"name": "#",
"ttl": 3600,
"type": "NS"
},
{
"data": "#",
"name": "www",
"ttl": 3600,
"type": "CNAME"
},
{
"data": "mail.example.com",
"name": "#",
"ttl": 3600,
"priority": 1,
"type": "MX"
}
]
New Data (After deleting record) (SAMPLE)
[
{
"data": "192.168.1.1",
"name": "#",
"ttl": 600,
"type": "A"
},
{
"data": "ns1.example.com",
"name": "#",
"ttl": 3600,
"type": "NS"
},
{
"data": "#",
"name": "www",
"ttl": 3600,
"type": "CNAME"
}
]
Now,
Send a PUT request to https://api.godaddy.com/v1/domains/{DOMAIN}/records with new data.
The most important thing is how you identify the records in above array which needs to be deleted. This would not be a difficult task, assuming you have good programming skills.
I managed to worked around it in kind of a hacky - we had bunch of records we wanted to delete, doing it manually seemed weird so I added a Javascript into the Chrome Developer Console, running on an authenticated session from the DNS manage page:
function deleteGoDaddyRecords(recordId) {
$.ajax({
url: 'https://dcc.godaddy.com/api/v3/domains/<YOUR-DOMAIN.com>/records?recordId='+recordId,
type: 'DELETE',
success: function(result) {
console.log(result)
}
});
}
which let me use the same call the UI is calling when you ask to delete a record.
the only thing you need to provide is the AttributeUid which is not available with the public API, but it is in the front-end API:
https://dcc.godaddy.com/api/v2/domains/runahr.com/records
So I managed to create a script that will generate bunch of
deleteGoDaddyRecords('<RECORD-UUID>');
deleteGoDaddyRecords('<RECORD-UUID>');
copy & paste the generated script into the Developers Console and that solved it for now.
I hope GoDaddy will add a public DELETE endpoint to their API in the future :)