PractiTest Discussion Forum

How do I use the runs API to post updates to a custom field?

I’m creating test filters using a custom field I created:

After each run, I post the results to the runs. API:

      const data =
      {
        "data": {
          "type": "runs",
          "attributes": {
            "instance-id": testInstance,
            "custom-fields": { "---f-185629": "0.8" },
          },

          "steps": {

            "data": [
              {
                "name": `${test.title}`,
                "expected-results": `${test.expectedStatus}`,
                "status": `${result.status.toUpperCase()}`,
                "description": "Test step's description",
              }
            ]
          }
        }
      }

      //Post test run results to Practitest
      try {
        await this.instance.post(`${process.env.PRACTITEST_RUNS_URL}`, data, {
          headers: {
            'PTToken': `${process.env.PRACTITEST_KEY}`,
            'Content-type': 'application/json'
          }
        });
        console.log('Success', data);
      } catch (error) {
        console.log('Error', error)
      }

I’d expect the filter to display all of the tests that have the custom field I created, but the actual test instance isn’t getting updated. It updates the last run and run status but not the custom field.

Why is it not updating the test with the custom field value so that it gets picked up by the filter I’ve created?

It seems like you’re using PractiTest’s API to update test runs with custom field values. From the provided code snippet, it appears that you’re sending a POST request to update a test run, including a custom field value in the “custom-fields” attribute. However, there are a couple of things to consider and potential reasons why the custom field might not be getting updated as expected:
Correct Custom Field ID
API Endpoint and Parameters
Custom Field Permissions
Data Format
Error Handling

Here’s an example of how you can log the response from the API https://tech-stack.com/blog/what-is-an-api/

try {
const response = await this.instance.post(${process.env.PRACTITEST_RUNS_URL}, data, {
headers: {
‘PTToken’: ${process.env.PRACTITEST_KEY},
‘Content-type’: ‘application/json’
}
});
console.log(‘Success’, response.data);
} catch (error) {
console.log(‘Error’, error.response.data);
}