Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to submit collection through API #47

Closed
amitdotagarwal opened this issue Apr 3, 2019 · 9 comments
Closed

Unable to submit collection through API #47

amitdotagarwal opened this issue Apr 3, 2019 · 9 comments
Assignees

Comments

@amitdotagarwal
Copy link

Hi Team,

We need your help, we are trying post collection through API, and facing some strange issues. For your reference please find below code error and API key.

below is the code error

{"error":{"name":"malformedRequestError","message":"Found 8 errors with the supplied collection.\nshould be null,string\nshould be null,string\nshould have required property 'item'\nshould match exactly one schema in oneOf\nshould be null,string\nshould be null,string\nshould have required property 'item'\nshould match exactly one schema in oneOf"}}%

This is API request, I have API key


curl -L -X PUT https://api.getpostman.com/collections/7124099-7aa2ce22-e8f6-46a1-b4f9-2304013e4543 -H 'Content-Type: application/json' -H 'X-Api-Key: <API_KEY>' --data '{"collection":{"item":[{"id":"253735e6-4fc7-45ef-a5b1-f6bc68c11836","name":"GET list of credentials","request":{"name":"GET list of credentials","description":{},"url":{"path":["credentials"],"host":["{baseUrl}"],"query":[{"key":"page[number]","value":"<integer>"},{"key":"page[size]","value":"<integer>"},{"key":"filter","value":"<string>"},{"key":"sort","value":"<string>"}],"variable":[]},"method":"GET","auth":{"type":"noauth"}},"response":[{"id":"4cd39b63-4c64-45cc-990d-a2e161107ac5","name":"success","originalRequest":{"url":{"path":["credentials"],"host":["{baseUrl}"],"query":[{"key":"page[number]","value":"<integer>"},{"key":"page[size]","value":"<integer>"},{"key":"filter","value":"<string>"},{"key":"sort","value":"<string>"}],"variable":[]},"method":"GET","body":{}},"status":"OK","code":200,"header":[{"key":"Content-Type","value":"application/vnd.api+json"}],"body":{"data":[{"id":"<1>"},{"id":"<1>"}]},"stream":{"data":[{"id":"<1>"},{"id":"<1>"}]},"cookie":[],"_postman_previewlanguage":"text"},{"id":"27f78524-8dbc-4ea3-be70-a817ce5e544e","name":"unauthorized","originalRequest":{"url":{"path":["credentials"],"host":["{baseUrl}"],"query":[{"key":"page[number]","value":"<integer>"},{"key":"page[size]","value":"<integer>"},{"key":"filter","value":"<string>"},{"key":"sort","value":"<string>"}],"variable":[]},"method":"GET","body":{}},"status":"Unauthorized","code":401,"header":[{"key":"Content-Type","value":"application/vnd.api+json"}],"body":{"data":[{"id":"<1>"},{"id":"<1>"}]},"stream":{"data":[{"id":"<1>"},{"id":"<1>"}]},"cookie":[],"_postman_previewlanguage":"text"}],"event":[]},{"id":"0ffe82a8-6bd9-4983-bc81-d2f07a2047e0","name":"GET list of tenants","request":{"name":"GET list of tenants","description":{},"url":{"path":["tenants"],"host":["{baseUrl}"],"query":[{"key":"schema_name","value":"<string>"}],"variable":[]},"method":"GET","auth":{"type":"noauth"}},"response":[{"id":"b460f471-3088-4630-8554-f4e4edb274e9","name":"success","originalRequest":{"url":{"path":["tenants"],"host":["{baseUrl}"],"query":[{"key":"schema_name","value":"<string>"}],"variable":[]},"method":"GET","body":{}},"status":"OK","code":200,"header":[{"key":"Content-Type","value":"application/json"}],"body":"{\n \"name\": \"<test>\"\n}","cookie":[],"_postman_previewlanguage":"json"}],"event":[]},{"id":"46001990-469b-49dd-806b-5eca0b884311","name":"GET list of users","request":{"name":"GET list of users","description":{},"url":{"path":["users"],"host":["{baseUrl}"],"query":[{"key":"page[number]","value":"<integer>"},{"key":"page[size]","value":"<integer>"},{"key":"filter","value":"<string>"},{"key":"sort","value":"<string>"}],"variable":[]},"method":"GET","auth":{"type":"noauth"}},"response":[{"id":"4f929d33-8861-4e18-ad5f-96aaed7b299c","name":"success","originalRequest":{"url":{"path":["users"],"host":["{baseUrl}"],"query":[{"key":"page[number]","value":"<integer>"},{"key":"page[size]","value":"<integer>"},{"key":"filter","value":"<string>"},{"key":"sort","value":"<string>"}],"variable":[]},"method":"GET","body":{}},"status":"OK","code":200,"header":[{"key":"Content-Type","value":"application/vnd.api+json"}],"body":{"data":[{"id":"<1>"},{"id":"<1>"}]},"stream":{"data":[{"id":"<1>"},{"id":"<1>"}]},"cookie":[],"_postman_previewlanguage":"text"},{"id":"e796746d-f46d-471c-bb51-dc23c65d69c9","name":"unauthorized","originalRequest":{"url":{"path":["users"],"host":["{baseUrl}"],"query":[{"key":"page[number]","value":"<integer>"},{"key":"page[size]","value":"<integer>"},{"key":"filter","value":"<string>"},{"key":"sort","value":"<string>"}],"variable":[]},"method":"GET","body":{}},"status":"Unauthorized","code":401,"header":[{"key":"Content-Type","value":"application/vnd.api+json"}],"body":{"data":[{"id":"<1>"},{"id":"<1>"}]},"stream":{"data":[{"id":"<1>"},{"id":"<1>"}]},"cookie":[],"_postman_previewlanguage":"text"}],"event":[]}],"event":[],"variable":[{"id":"baseUrl","type":"string","value":"http://localhost:3000"}],"info":{"_postman_id":"9da6abdf-6b12-4564-b7e7-045cf6cc5351","name":"iam","version":{"raw":"0.1.0","major":0,"minor":1,"patch":0,"prerelease":[],"build":[],"string":"0.1.0"},"schema":"https://schema.getpostman.com/json/collection/v2.1.0/collection.json","description":{"content":"API documentation","type":"text/plain"}}}}'

@amitdotagarwal
Copy link
Author

@Raja-Simha could you please help me troubleshoot this issue?

@amitdotagarwal
Copy link
Author

Additionally, I am able to import same collection, JSON file through Postman application, but not through API.

@preethammavin
Copy link
Member

@amitdotagarwal can you share the collection json file you are trying to import? or a sample one if it doesnt have any sensitive information?

@amitdotagarwal
Copy link
Author

really thanks for your response, please find attached, requested JSON file.
ros-api.json.zip

@abhijitkane
Copy link
Member

@preethammavin The OpenAPI converter is converting the OAS spec to a valid collection. The Postman Collection file is importing correctly in the app, but not in the API (even using the POST /collection endpoint, which has nothing to do with openAPI).

Probably linked to a transformer version mismatch across app/api/sync

@abhijitkane
Copy link
Member

Attaching the Postman Collection V2 file that imports in the app but not in the API.

collection-import-error.txt

@abhijitkane
Copy link
Member

@amitdotagarwal While we fix this in our converter, changing application/vnd.api+json to application/json in your OpenAPI file should work.

@abhijitkane abhijitkane transferred this issue from postmanlabs/postman-app-support Apr 12, 2019
@abhijitkane
Copy link
Member

abhijitkane commented Apr 27, 2019

@amitdotagarwal We've pushed out a fix. Can you confirm you're able to import the collection through the API now?

Closing the ticket - feel free to add a comment if you still face issues.

@thim81
Copy link
Contributor

thim81 commented Jun 6, 2020

@abhijitkane

I face similar issue.

Flow:

  • OpenApi.spec (validated by spectral) > convert useing openapi-to-postman = generated_postman.collection
  • Postman API using the generated_postman.collection

I'm using this simple function to communicate with the API

function updatePostman(newFileName, collection_uid) {

    // read the updated local file and update the Postman collection using Postman API
    newFileName = process.env["POSTMAN_FILE"]
    var data = fs.readFileSync( newFileName, 'utf8');

    // Postman users can get a Postman API key here: https://app.getpostman.com/dashboard/integrations
    var postmanAPIKey = process.env["API_KEY"];

    // compile PUT request to update the Postman collection
    var putOptions = {
        method: 'PUT',
        url: 'https://api.getpostman.com/collections/' + collection_uid,
        qs: {
            format: '2.1.0'
        },
        headers: {
            // 'Postman-Token': '4122abb3-6098-6906-e172-49334961f595',
            'Cache-Control': 'no-cache',
            'X-Api-Key': postmanAPIKey,
            'Content-Type': 'application/json'
        },
        body: {"collection": JSON.parse(data)},
        json: true
    };

    // submit PUT request to update the Postman collection
    request(putOptions, function (error, response, body) {
        if (error) throw new Error(error);
        console.log(body);
    });

}

Which results in the following errors:

{
  error: {
    name: 'malformedRequestError',
    message: 'Found 298 errors with the supplied collection.\n' +
      "should have required property 'request'\n" +
      'should be null\n' +
      "should have required property 'type'\n" +
      'should match exactly one schema in oneOf\n' +
      'should be string\n' +
      'should match exactly one schema in oneOf\n' +
      "should have required property 'item'\n" +
      'should match some schema in anyOf\n' +
      'should be null\n' +
      ...
  }
}

While I can import the collection using the Postman Import option, without any problem.

image

image

Should I send it to the API using different parameters or query string properties?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants