Support

Expand all | Collapse all

Cannot use 'put' with JAMA REST API

  • 1.  Cannot use 'put' with JAMA REST API

    Posted 05-09-2019 13:52
    Edited by Pablo Beltran 05-10-2019 00:57
    Im trying to use 'put' with following arguments:

    def __put_data(self, task, result):
          return requests.put(self._base_url + task,
                                          data = json.dumps(result),
                                          headers={'Content-Type': "application/json""Accept": "application/json"},
                                          auth=(self._username, self._password))

    but I always get this message:

    "status": "Bad request"...
    "message":"Cannot construct instance of `com.jamasoftware.contour.rest.versions.v1.domain.RequestTestRun` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ("the data Im trying to write")

    'get' function is working properly.
    I am using python 3.7

    Thanks in advance,

    ------------------------------
    Pablo Beltran
    Bose Corporation
    Tijuana BCN
    016649794000
    ------------------------------


  • 2.  RE: Cannot use 'put' with JAMA REST API

    Posted 05-10-2019 12:26
    Pablo:

    Could you confirm for me which field in the Test Run you are attempting to update and use PUT? I ask because the Test Run endpoint uses PUT for very specific functions.

    ------------------------------
    Chloe Elliott
    Jama Software
    Portland OR
    ------------------------------



  • 3.  RE: Cannot use 'put' with JAMA REST API

    Posted 05-10-2019 13:41
    Edited by Pablo Beltran 05-14-2019 18:14
    Hi Chloe,

    Thanks for your response.

    I am trying to modify "fields" in TestRun. For the specific purpose of ["TestRunSteps"]["status"]
    It looks something like this:

    {
    "createdBy": 1273,
    "createdDate": "2019-05-06T21:47:04.000+0000",
    "documentKey": "DocumentKey",
    "fields":   {
        "assignedTo": 1273,
        "description": "description here",
        "documentKey": "TestRunKey",
        "duration": 5908,
        "executionDate": "2019-05-07",
        "forcePassed": false,
        "globalId": "GID-xxx",
        "modifiedDate": "2019-05-07",
        "name": "TestRunName",
        "project": 132,
        "testCase": 707565,
        "testCycle": 1059913,
        "testPlan": 1059617,
        "testRunSetName": "Demo Test runs",
        "testRunStatus": "INPROGRESS",
        "testRunSteps":   [
              {
                     "action": "TestStepName",
                     "expectedResult": "",
                     "notes": "Approved",
                     "status": "Passed"
              },
         ]
    },
    "globalId": "GID-1015591",
    "id": 1059917,
    "itemType": 37,
    "lastActivityDate": "2019-05-07T23:58:22.000+0000",
    "modifiedBy": 1273,
    "modifiedDate": "2019-05-07T23:58:22.000+0000",
    "project": 132,
    "resources": {
             "self": {
                   "allowed": [
                          "GET",
                          "PUT",
                          "PATCH"
                    ]
              }
    },
    "sortOrderFromTestGroup": 1,
    "testCaseCurrentVersionNumber": 1,
    "testCaseVersionNumber": 1,
    "testGroup": [
    1059913,
    2773
    ],
    "type": "testruns"
    }

    I already did the same request on Swagger and it is working there. Hope you can help

    ------------------------------
    Pablo Beltran
    Bose Corporation
    Tijuana BCN
    016649794000
    ------------------------------



  • 4.  RE: Cannot use 'put' with JAMA REST API

    Posted 05-10-2019 14:37
    Hi Pablo,

    Have you tried using the PATCH endpoint instead. If you are just trying to update the 'Status' of a test run, it might be cleaner to simply update the status and not worry about all the other values. The formatting of PUT requests is very picky when working with test runs, so the fewer fields you have to deal with the better.

    ------------------------------
    Jason Ritz
    Jama Software
    OR
    ------------------------------



  • 5.  RE: Cannot use 'put' with JAMA REST API

    Posted 05-10-2019 15:00
    Hello Jason,

    Yes, I've tried with PATCH..same issue.
    The thing with the fields I am trying to modify, it's that I;ve already did it on Swagger with the same format.
    I also tried including "jama-csrf-token". Still same issue.

    Is there a way to see how Swagger is handling the strings provided in 'body'  value field boxes?


    ------------------------------
    Pablo Beltran
    Bose Corporation
    Tijuana BCN
    016649794000
    ------------------------------



  • 6.  RE: Cannot use 'put' with JAMA REST API

    Posted 05-10-2019 17:34
    Hi Pablo,

    Try this and see if it helps.

    import requests as r

    #set the base URL and add the endpoint you want to hit
    baseURL = "< add base URL>"
    restURL = "rest/latest/<add endpoint>"
    url = baseURL + restURL


    #using the generated client ID and secret from Jama's "set API creds" (to use OAuth)
    username = "<user ID token>" # User ID created in Jama
    password = "<user password token>" # User secret created in Jama


    #sets up auth token
    response=r.post(baseURL + "rest/oauth/token", auth=(username, password), data={'grant_type':'client_credentials'})
    jamaToken=response.json()["access_token"]
    jamaHeaders={'authorization' : 'Bearer ' + jamaToken}


    #set payload
    payload = {
    "createdBy": 1273,
    "createdDate": "2019-05-06T21:47:04.000+0000",
    "documentKey": "DocumentKey",
    "fields": {
    "assignedTo": 1273,
    "description": "description here",
    "documentKey": "TestRunKey",
    "duration": 5908,
    "executionDate": "2019-05-07",
    "forcePassed": false,
    "globalId": "GID-xxx",
    "modifiedDate": "2019-05-07",
    "name": "TestRunName",
    "project": 132,
    "testCase": 707565,
    "testCycle": 1059913,
    "testPlan": 1059617,
    "testRunSetName": "Demo Test runs",
    "testRunStatus": "INPROGRESS",
    "testRunSteps": [
    {
    "action": "Script Name: SVPr_AC_2445_Unified_Volume_VolumeCurve.py",
    "expectedResult": "",
    "notes": "Approved",
    "status": "Passed"
    },
    ]
    },
    "globalId": "GID-1015591",
    "id": 1059917,
    "itemType": 37,
    "lastActivityDate": "2019-05-07T23:58:22.000+0000",
    "modifiedBy": 1273,
    "modifiedDate": "2019-05-07T23:58:22.000+0000",
    "project": 132,
    "resources": {
    "self": {
    "allowed": [
    "GET",
    "PUT",
    "PATCH"
    ]
    }
    },
    "sortOrderFromTestGroup": 1,
    "testCaseCurrentVersionNumber": 1,
    "testCaseVersionNumber": 1,
    "testGroup": [
    1059913,
    2773
    ],
    "type": "testruns"
    }

    # Make call
    response = r.post(url, json=payload, headers=jamaHeaders)


    print response.text






    ------------------------------
    Jason Ritz
    Jama Software
    OR
    ------------------------------