ncoa / hapid_api_documentation

HAPID API Documentation
1 stars 0 forks source link

Participant creation docs don't seem correct. #4

Open craigmcnamara opened 8 months ago

craigmcnamara commented 8 months ago

I tried to follow the documentation to create a participant and got back an error.

URL: POST https://ncoa1--monami.sandbox.my.site.com/services/data/v54.0/sobjects/epd_Participant__c/Participant_External_ID__c/RXZlbnRzOjpBdHRlbmRlZS0xMQ==

Request Headers:
{"User-Agent"=>"Faraday v2.7.12", "Content-Type"=>"application/json"}

Request Body:
{"id":11,"Name":"Customer Name","Participant_Name_ID__c":"Customer Name"}

Response Status: 404

Response Body:
[{"errorCode"=>"NOT_FOUND", "message"=>"Provided external ID field does not exist or is not accessible: Participant_External_ID__c"}]

The docs seem like I need to already have the Participant_External_ID__c param matching an existing record. Since this seemed like a documentation error I tried to post do the Participant endpoint without the extra path params:

URL: POST https://ncoa1--monami.sandbox.my.site.com/services/data/v54.0/sobjects/epd_Participant__c

Request Headers:
{"User-Agent"=>"Faraday v2.7.12", "Content-Type"=>"application/json"}

Request Body:
{"id":11,"Name":"Customer Name","Participant_Name_ID__c":"Customer Name"}

Response Status: 400

Response Body:
[{"message"=>"The Id field should not be specified in the sobject data.", "errorCode"=>"INVALID_FIELD"}]

This error makes sense since the ID should be returned when I create a participant object in salesforce, so when I omit the ID field I get:

URL: POST https://ncoa1--monami.sandbox.my.site.com/services/data/v54.0/sobjects/epd_Participant__c

Request Headers:
{"User-Agent"=>"Faraday v2.7.12", "Content-Type"=>"application/json"}

Request Body:
{"Name":"Customer Name","Participant_Name_ID__c":"Customer Name"}

Response Status: 400

Response Body:
[{"message"=>"Unable to create/update fields: Name. Please check the security settings of this field and verify that it is read/write for your profile or permission set.", "errorCode"=>"INVALID_FIELD_FOR_INSERT_UPDATE", "fields"=>["Name"]}]
benkean commented 8 months ago

Name (Label: Participant Number) is an autonumber field on that object, so you can't set it via the API. @djschlicht this would be indicated in the describesobjectresult as autonumber = true. Perhaps we can find a way to explain this in our docs?

Not sure what the issue is around the external id field, we will have to research.

benkean commented 8 months ago

@craigmcnamara it looks like you may be using the wrong request method. When using the external id endpoint, you may need to use PATCH instead of POST. Please review https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_upsert.htm and let me know if you have a different understanding.

craigmcnamara commented 8 months ago

The main issue is here:

### STEP2: Adding a Participant.  

If the Participant does not exist in the Hapi database , you will be able to add the same.  

Endpoint:   

 POST https://ncoa1--uat.sandbox.my.site.com/services/data/v54.0/sobjects/epd_Participant__c/Participant_External_ID__c/{ExternalIdValue}

Replace the ExternalIdValue with the External Id of the participant. 

Sample requestbody:  

~~~
{  
  "id": "string",  
  "Name": "string",  
  "Participant_Name_ID__c": "string"  
}   

Making this request as documented only leads to failure.

I'm able to create a record with the following:

URL: POST https://ncoa1--monami.sandbox.my.site.com/services/data/v54.0/sobjects/epd_Participant__c

Request Headers:
{"User-Agent"=>"Faraday v2.7.12", "Content-Type"=>"application/json"}

Request Body:
{"Participant_Name_ID__c":"Customer Name"}

With every request I'm saving the returned IDs, so is there any reason for me to need Participant_External_ID__c since I have the actual IDs for all the records I create?